test(editor): cover multi-reparent selection undo state

This commit is contained in:
ayuan9957 2026-06-23 22:25:15 +08:00
parent ef261c3c8e
commit a265f32ed6

View File

@ -425,6 +425,43 @@ void MetaCoreTestHierarchyEditingCommandsDirtyAndUndo() {
MetaCoreExpect(editorContext.GetActiveObjectId() == *createdId, "Redo ReparentSelection should restore moved object selection"); MetaCoreExpect(editorContext.GetActiveObjectId() == *createdId, "Redo ReparentSelection should restore moved object selection");
MetaCoreExpect(scenePersistenceService->SaveCurrentScene(editorContext), "Hierarchy command scene should save after reparent"); MetaCoreExpect(scenePersistenceService->SaveCurrentScene(editorContext), "Hierarchy command scene should save after reparent");
const auto multiReparentFirstId = sceneEditingService->CreateGameObject(
editorContext,
"MultiReparentFirst",
false,
std::optional<MetaCore::MetaCoreId>{0}
);
const auto multiReparentSecondId = sceneEditingService->CreateGameObject(
editorContext,
"MultiReparentSecond",
false,
std::optional<MetaCore::MetaCoreId>{0}
);
MetaCoreExpect(multiReparentFirstId.has_value(), "CreateGameObject command should create first multi-reparent object");
MetaCoreExpect(multiReparentSecondId.has_value(), "CreateGameObject command should create second multi-reparent object");
MetaCoreExpect(scenePersistenceService->SaveCurrentScene(editorContext), "Hierarchy command scene should save before multi-reparent");
const std::vector<MetaCore::MetaCoreId> multiReparentSelection{*multiReparentFirstId, *multiReparentSecondId};
editorContext.SetSelection(multiReparentSelection, *multiReparentSecondId);
MetaCoreExpect(sceneEditingService->ReparentSelection(editorContext, *parentId), "ReparentSelection command should reparent multiple selected objects");
MetaCoreExpect(scene.FindGameObject(*multiReparentFirstId).GetParentId() == *parentId, "ReparentSelection should set first selected object parent id");
MetaCoreExpect(scene.FindGameObject(*multiReparentSecondId).GetParentId() == *parentId, "ReparentSelection should set second selected object parent id");
MetaCoreExpect(editorContext.GetActiveObjectId() == *multiReparentSecondId, "ReparentSelection should keep multi-selection active object");
MetaCoreExpect(editorContext.GetSelectedObjectIds() == multiReparentSelection, "ReparentSelection should keep multi-selection list");
MetaCoreExpect(scenePersistenceService->IsSceneDirty(), "Multi ReparentSelection command should mark scene dirty");
MetaCoreExpect(editorContext.UndoCommand(), "Undo multi ReparentSelection should succeed");
MetaCoreExpect(scene.FindGameObject(*multiReparentFirstId).GetParentId() == 0, "Undo multi ReparentSelection should restore first selected object root parent");
MetaCoreExpect(scene.FindGameObject(*multiReparentSecondId).GetParentId() == 0, "Undo multi ReparentSelection should restore second selected object root parent");
MetaCoreExpect(editorContext.GetActiveObjectId() == *multiReparentSecondId, "Undo multi ReparentSelection should restore active object");
MetaCoreExpect(editorContext.GetSelectedObjectIds() == multiReparentSelection, "Undo multi ReparentSelection should restore selection list");
MetaCoreExpect(!scenePersistenceService->IsSceneDirty(), "Undo multi ReparentSelection should restore clean baseline");
MetaCoreExpect(editorContext.RedoCommand(), "Redo multi ReparentSelection should succeed");
MetaCoreExpect(scene.FindGameObject(*multiReparentFirstId).GetParentId() == *parentId, "Redo multi ReparentSelection should restore first selected object parent id");
MetaCoreExpect(scene.FindGameObject(*multiReparentSecondId).GetParentId() == *parentId, "Redo multi ReparentSelection should restore second selected object parent id");
MetaCoreExpect(editorContext.GetActiveObjectId() == *multiReparentSecondId, "Redo multi ReparentSelection should restore active object");
MetaCoreExpect(editorContext.GetSelectedObjectIds() == multiReparentSelection, "Redo multi ReparentSelection should restore selection list");
MetaCoreExpect(scenePersistenceService->SaveCurrentScene(editorContext), "Hierarchy command scene should save after multi-reparent");
editorContext.SelectOnly(*createdId); editorContext.SelectOnly(*createdId);
const std::size_t countBeforeDuplicate = scene.GetGameObjects().size(); const std::size_t countBeforeDuplicate = scene.GetGameObjects().size();
MetaCoreExpect(clipboardService->DuplicateSelection(editorContext), "DuplicateSelection command should duplicate selected object"); MetaCoreExpect(clipboardService->DuplicateSelection(editorContext), "DuplicateSelection command should duplicate selected object");