Add XCUI expansion state and coverage tests

This commit is contained in:
2026-04-05 07:29:27 +08:00
parent 646e5855ce
commit 511e94fd30
18 changed files with 1213 additions and 53 deletions

View File

@@ -250,3 +250,116 @@ TEST(NewEditorXCUILayoutLabRuntimeTest, ClickSelectionPersistsOnSharedCollection
ASSERT_TRUE(persistedFrame.stats.documentsReady);
EXPECT_EQ(persistedFrame.stats.selectedElementId, selectedElementId);
}
TEST(NewEditorXCUILayoutLabRuntimeTest, ClickingTreeRootTogglesIndentedChildrenVisibility) {
XCEngine::Editor::XCUIBackend::XCUILayoutLabRuntime runtime;
ASSERT_TRUE(runtime.ReloadDocuments());
const auto& baseline = runtime.Update(BuildInputState());
ASSERT_TRUE(baseline.stats.documentsReady);
EXPECT_EQ(baseline.stats.expandedTreeItemCount, 1u);
XCEngine::UI::UIRect treeRootRect = {};
XCEngine::UI::UIRect treeChildRect = {};
ASSERT_TRUE(runtime.TryGetElementRect("treeAssetsRoot", treeRootRect));
ASSERT_TRUE(runtime.TryGetElementRect("treeScenes", treeChildRect));
ASSERT_GT(treeRootRect.width, 0.0f);
ASSERT_GT(treeRootRect.height, 0.0f);
const XCEngine::UI::UIPoint rootClickPoint(
treeRootRect.x + 18.0f,
treeRootRect.y + treeRootRect.height * 0.5f);
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState hoverInput = BuildInputState();
hoverInput.pointerPosition = rootClickPoint;
const auto& hoveredFrame = runtime.Update(hoverInput);
ASSERT_TRUE(hoveredFrame.stats.documentsReady);
ASSERT_EQ(hoveredFrame.stats.hoveredElementId, "treeAssetsRoot")
<< "treeRootRect=("
<< treeRootRect.x << ", "
<< treeRootRect.y << ", "
<< treeRootRect.width << ", "
<< treeRootRect.height << ")";
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState collapseInput = BuildInputState();
collapseInput.pointerPosition = rootClickPoint;
collapseInput.pointerPressed = true;
const auto& collapsedFrame = runtime.Update(collapseInput);
ASSERT_TRUE(collapsedFrame.stats.documentsReady);
EXPECT_EQ(collapsedFrame.stats.selectedElementId, "treeAssetsRoot");
const auto& collapsedPersistedFrame = runtime.Update(BuildInputState());
ASSERT_TRUE(collapsedPersistedFrame.stats.documentsReady);
EXPECT_EQ(collapsedPersistedFrame.stats.selectedElementId, "treeAssetsRoot");
EXPECT_EQ(collapsedPersistedFrame.stats.expandedTreeItemCount, 0u);
EXPECT_FALSE(runtime.TryGetElementRect("treeScenes", treeChildRect));
ASSERT_TRUE(runtime.TryGetElementRect("treeAssetsRoot", treeRootRect));
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState expandInput = BuildInputState();
expandInput.pointerPosition = XCEngine::UI::UIPoint(
treeRootRect.x + 18.0f,
treeRootRect.y + treeRootRect.height * 0.5f);
expandInput.pointerPressed = true;
const auto& expandedClickFrame = runtime.Update(expandInput);
ASSERT_TRUE(expandedClickFrame.stats.documentsReady);
const auto& expandedFrame = runtime.Update(BuildInputState());
ASSERT_TRUE(expandedFrame.stats.documentsReady);
EXPECT_EQ(expandedFrame.stats.expandedTreeItemCount, 1u);
EXPECT_TRUE(runtime.TryGetElementRect("treeScenes", treeChildRect));
EXPECT_GT(treeChildRect.height, 0.0f);
}
TEST(NewEditorXCUILayoutLabRuntimeTest, ClickingPropertySectionHeaderTogglesFieldVisibility) {
XCEngine::Editor::XCUIBackend::XCUILayoutLabRuntime runtime;
ASSERT_TRUE(runtime.ReloadDocuments());
const auto& baseline = runtime.Update(BuildInputState());
ASSERT_TRUE(baseline.stats.documentsReady);
XCEngine::UI::UIRect sectionRect = {};
XCEngine::UI::UIRect fieldRect = {};
ASSERT_TRUE(runtime.TryGetElementRect("inspectorTransform", sectionRect));
ASSERT_TRUE(runtime.TryGetElementRect("fieldPosition", fieldRect));
const float expandedHeight = sectionRect.height;
const XCEngine::UI::UIPoint sectionHeaderPoint(
sectionRect.x + 18.0f,
sectionRect.y + 10.0f);
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState hoverInput = BuildInputState();
hoverInput.pointerPosition = sectionHeaderPoint;
const auto& hoveredFrame = runtime.Update(hoverInput);
ASSERT_TRUE(hoveredFrame.stats.documentsReady);
ASSERT_EQ(hoveredFrame.stats.hoveredElementId, "inspectorTransform")
<< "sectionRect=("
<< sectionRect.x << ", "
<< sectionRect.y << ", "
<< sectionRect.width << ", "
<< sectionRect.height << "), expandedPropertySectionCount="
<< baseline.stats.expandedPropertySectionCount;
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState collapseInput = BuildInputState();
collapseInput.pointerPosition = sectionHeaderPoint;
collapseInput.pointerPressed = true;
const auto& collapsedFrame = runtime.Update(collapseInput);
ASSERT_TRUE(collapsedFrame.stats.documentsReady);
const auto& collapsedPersistedFrame = runtime.Update(BuildInputState());
ASSERT_TRUE(collapsedPersistedFrame.stats.documentsReady);
EXPECT_EQ(collapsedPersistedFrame.stats.selectedElementId, "inspectorTransform");
ASSERT_TRUE(runtime.TryGetElementRect("inspectorTransform", sectionRect));
EXPECT_LT(sectionRect.height, expandedHeight);
EXPECT_FALSE(runtime.TryGetElementRect("fieldPosition", fieldRect));
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState expandInput = BuildInputState();
expandInput.pointerPosition = XCEngine::UI::UIPoint(
sectionRect.x + 18.0f,
sectionRect.y + 10.0f);
expandInput.pointerPressed = true;
const auto& expandedClickFrame = runtime.Update(expandInput);
ASSERT_TRUE(expandedClickFrame.stats.documentsReady);
const auto& expandedFrame = runtime.Update(BuildInputState());
ASSERT_TRUE(expandedFrame.stats.documentsReady);
EXPECT_TRUE(runtime.TryGetElementRect("fieldPosition", fieldRect));
EXPECT_GT(fieldRect.height, 0.0f);
}