From 4afe2f88babd5df51664b69b31f2a1f1f76e3766 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Fri, 27 Mar 2026 12:18:40 +0800 Subject: [PATCH] Expand editor regression coverage --- docs/plan/Editor重构3.26.md | 4 ++ tests/editor/test_action_routing.cpp | 76 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/docs/plan/Editor重构3.26.md b/docs/plan/Editor重构3.26.md index d2a8c024..d9c6b1ca 100644 --- a/docs/plan/Editor重构3.26.md +++ b/docs/plan/Editor重构3.26.md @@ -304,10 +304,14 @@ - 已新增 `tests/editor/test_action_routing.cpp` - 已新增 `tests/editor/CMakeLists.txt` 与 `editor_tests` target +- 当前 `editor_tests` 已覆盖 7 条 editor 回归用例 - 已覆盖 `Hierarchy Edit route` 的 copy / paste / duplicate / delete / rename request - 已覆盖 `Project Edit route` 的 open / back / delete - 已覆盖 `scene dirty save + load` 后的 selection / undo reset - 已覆盖 `reparent` 的 parent 切换、cycle 拦截与 world position / scale 保持 +- 已覆盖 `MainMenu` 的 exit / reset-layout 事件请求与 about popup 请求 +- 已覆盖 `Hierarchy` rename helper 的 request / commit 语义 +- 已覆盖 `Project` 的 create-folder / move-asset / open-folder helper ## 下一阶段建议执行顺序 diff --git a/tests/editor/test_action_routing.cpp b/tests/editor/test_action_routing.cpp index 3d93fe68..b440a5f8 100644 --- a/tests/editor/test_action_routing.cpp +++ b/tests/editor/test_action_routing.cpp @@ -1,6 +1,9 @@ #include #include "Actions/EditActionRouter.h" +#include "Actions/HierarchyActionRouter.h" +#include "Actions/MainMenuActionRouter.h" +#include "Actions/ProjectActionRouter.h" #include "Commands/EntityCommands.h" #include "Commands/SceneCommands.h" #include "Core/EditorContext.h" @@ -220,5 +223,78 @@ TEST_F(EditorActionRoutingTest, ReparentPreserveWorldTransformKeepsWorldPose) { ExpectNear(child->GetTransform()->GetScale(), worldScaleBefore); } +TEST_F(EditorActionRoutingTest, MainMenuRouterRequestsExitResetAndAboutPopup) { + int exitRequestCount = 0; + int resetLayoutCount = 0; + + const uint64_t exitSubscription = m_context.GetEventBus().Subscribe( + [&](const EditorExitRequestedEvent&) { + ++exitRequestCount; + }); + const uint64_t resetSubscription = m_context.GetEventBus().Subscribe( + [&](const DockLayoutResetRequestedEvent&) { + ++resetLayoutCount; + }); + + UI::DeferredPopupState aboutPopup; + EXPECT_FALSE(aboutPopup.HasPendingOpenRequest()); + + Actions::RequestAboutPopup(aboutPopup); + Actions::RequestDockLayoutReset(m_context); + Actions::RequestEditorExit(m_context); + + EXPECT_TRUE(aboutPopup.HasPendingOpenRequest()); + EXPECT_EQ(resetLayoutCount, 1); + EXPECT_EQ(exitRequestCount, 1); + + m_context.GetEventBus().Unsubscribe(exitSubscription); + m_context.GetEventBus().Unsubscribe(resetSubscription); +} + +TEST_F(EditorActionRoutingTest, HierarchyRouterRenameHelpersPublishAndCommit) { + auto* entity = Commands::CreateEmptyEntity(m_context, nullptr, "Create Entity", "BeforeRename"); + ASSERT_NE(entity, nullptr); + + uint64_t renameRequestedId = 0; + const uint64_t renameSubscription = m_context.GetEventBus().Subscribe( + [&](const EntityRenameRequestedEvent& event) { + renameRequestedId = event.entityId; + }); + + Actions::RequestEntityRename(m_context, entity); + EXPECT_EQ(renameRequestedId, entity->GetID()); + + EXPECT_TRUE(Actions::CommitEntityRename(m_context, entity->GetID(), "AfterRename")); + ASSERT_NE(m_context.GetSceneManager().GetEntity(entity->GetID()), nullptr); + EXPECT_EQ(m_context.GetSceneManager().GetEntity(entity->GetID())->GetName(), "AfterRename"); + EXPECT_TRUE(m_context.GetUndoManager().CanUndo()); + + EXPECT_FALSE(Actions::CommitEntityRename(m_context, entity->GetID(), "")); + EXPECT_FALSE(Actions::CommitEntityRename(m_context, 0, "Invalid")); + + m_context.GetEventBus().Unsubscribe(renameSubscription); +} + +TEST_F(EditorActionRoutingTest, ProjectCommandsCreateFolderMoveAssetAndOpenFolderHelper) { + const fs::path assetsDir = m_projectRoot / "Assets"; + const fs::path sourceFilePath = assetsDir / "MoveMe.txt"; + + std::ofstream(sourceFilePath.string()) << "move source"; + + EXPECT_TRUE(Commands::CreateFolder(m_context.GetProjectManager(), "MovedFolder")); + m_context.GetProjectManager().RefreshCurrentFolder(); + + const AssetItemPtr folderItem = FindCurrentItemByName("MovedFolder"); + ASSERT_NE(folderItem, nullptr); + ASSERT_TRUE(folderItem->isFolder); + + EXPECT_TRUE(Commands::MoveAssetToFolder(m_context.GetProjectManager(), sourceFilePath.string(), folderItem)); + EXPECT_FALSE(fs::exists(sourceFilePath)); + EXPECT_TRUE(fs::exists(assetsDir / "MovedFolder" / "MoveMe.txt")); + + EXPECT_TRUE(Actions::OpenProjectAsset(m_context, folderItem)); + EXPECT_EQ(m_context.GetProjectManager().GetCurrentPath(), "Assets/MovedFolder"); +} + } // namespace } // namespace XCEngine::Editor