From f185663259bdffc0e0e90fd6281a61ce5e461458 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sun, 5 Apr 2026 06:03:15 +0800 Subject: [PATCH] Stabilize XCUI demo runtime editing tests --- tests/NewEditor/test_xcui_demo_runtime.cpp | 64 ++++++++++++++++------ 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/tests/NewEditor/test_xcui_demo_runtime.cpp b/tests/NewEditor/test_xcui_demo_runtime.cpp index 1253dbfa..067a1e11 100644 --- a/tests/NewEditor/test_xcui_demo_runtime.cpp +++ b/tests/NewEditor/test_xcui_demo_runtime.cpp @@ -185,6 +185,13 @@ TEST(NewEditorXCUIDemoRuntimeTest, RuntimeFrameEmitsTextCommandsWithResolvedFont const UIDrawCommand* buttonLabelCommand = FindTextCommand(frame.drawData, "Toggle Accent"); ASSERT_NE(buttonLabelCommand, nullptr); EXPECT_FLOAT_EQ(buttonLabelCommand->fontSize, 14.0f); + + EXPECT_NE( + FindTextCommand(frame.drawData, "Single-line input, Enter submits, 0 chars"), + nullptr); + EXPECT_NE( + FindTextCommand(frame.drawData, "Multiline input, click caret, Tab indent, 1 lines"), + nullptr); } TEST(NewEditorXCUIDemoRuntimeTest, InputStateTransitionsAreAcceptedAndFrameStillBuilds) { @@ -386,39 +393,64 @@ TEST(NewEditorXCUIDemoRuntimeTest, TextAreaAcceptsMultilineInputAndCaretMovement EXPECT_NE(FindTextCommand(typedFrame.drawData, "2"), nullptr); EXPECT_NE(FindTextCommand(typedFrame.drawData, "OK"), nullptr); EXPECT_NE(FindTextCommand(typedFrame.drawData, "X"), nullptr); + EXPECT_NE( + FindTextCommand(typedFrame.drawData, "Multiline input, click caret, Tab indent, 2 lines"), + nullptr); + + const UIDrawCommand* secondLineText = FindTextCommand(typedFrame.drawData, "X"); + ASSERT_NE(secondLineText, nullptr); + + XCEngine::Editor::XCUIBackend::XCUIDemoInputState secondLinePressed = BuildInputState(); + secondLinePressed.pointerPosition = XCEngine::UI::UIPoint( + secondLineText->position.x + 1.0f, + secondLineText->position.y + secondLineText->fontSize * 0.5f); + secondLinePressed.pointerPressed = true; + secondLinePressed.pointerDown = true; + runtime.Update(secondLinePressed); + + XCEngine::Editor::XCUIBackend::XCUIDemoInputState secondLineReleased = BuildInputState(); + secondLineReleased.pointerPosition = secondLinePressed.pointerPosition; + secondLineReleased.pointerReleased = true; + const auto& secondLineCaretFrame = runtime.Update(secondLineReleased); + + ASSERT_TRUE(secondLineCaretFrame.stats.documentsReady); + EXPECT_EQ(secondLineCaretFrame.stats.focusedElementId, "sessionNotes"); XCEngine::Editor::XCUIBackend::XCUIDemoInputState tabInput = BuildInputState(); - tabInput.events.push_back(MakeKeyDownEvent(XCEngine::Input::KeyCode::Home)); tabInput.events.push_back(MakeKeyDownEvent(XCEngine::Input::KeyCode::Tab)); const auto& indentedFrame = runtime.Update(tabInput); ASSERT_TRUE(indentedFrame.stats.documentsReady); EXPECT_EQ(indentedFrame.stats.focusedElementId, "sessionNotes"); EXPECT_EQ(indentedFrame.stats.lastCommandId, "demo.text.edit.sessionNotes"); + EXPECT_NE(FindTextCommand(indentedFrame.drawData, "OK"), nullptr); + EXPECT_NE(FindTextCommand(indentedFrame.drawData, " X"), nullptr); - const XCEngine::UI::UIPoint firstLineStart( - notesRect.x + 8.0f, - notesRect.y + 10.0f); + const UIDrawCommand* firstLineText = FindTextCommand(indentedFrame.drawData, "OK"); + ASSERT_NE(firstLineText, nullptr); - XCEngine::Editor::XCUIBackend::XCUIDemoInputState caretPressed = BuildInputState(); - caretPressed.pointerPosition = firstLineStart; - caretPressed.pointerPressed = true; - caretPressed.pointerDown = true; - runtime.Update(caretPressed); + XCEngine::Editor::XCUIBackend::XCUIDemoInputState firstLinePressed = BuildInputState(); + firstLinePressed.pointerPosition = XCEngine::UI::UIPoint( + firstLineText->position.x + 1.0f, + firstLineText->position.y + firstLineText->fontSize * 0.5f); + firstLinePressed.pointerPressed = true; + firstLinePressed.pointerDown = true; + runtime.Update(firstLinePressed); - XCEngine::Editor::XCUIBackend::XCUIDemoInputState caretReleased = BuildInputState(); - caretReleased.pointerPosition = firstLineStart; - caretReleased.pointerReleased = true; - const auto& caretFrame = runtime.Update(caretReleased); + XCEngine::Editor::XCUIBackend::XCUIDemoInputState firstLineReleased = BuildInputState(); + firstLineReleased.pointerPosition = firstLinePressed.pointerPosition; + firstLineReleased.pointerReleased = true; + const auto& caretFrame = runtime.Update(firstLineReleased); ASSERT_TRUE(caretFrame.stats.documentsReady); EXPECT_EQ(caretFrame.stats.focusedElementId, "sessionNotes"); - XCEngine::Editor::XCUIBackend::XCUIDemoInputState caretInput = BuildInputState(); - caretInput.events.push_back(MakeCharacterEvent('!')); - const auto& editedFrame = runtime.Update(caretInput); + XCEngine::Editor::XCUIBackend::XCUIDemoInputState editInput = BuildInputState(); + editInput.events.push_back(MakeCharacterEvent('!')); + const auto& editedFrame = runtime.Update(editInput); ASSERT_TRUE(editedFrame.stats.documentsReady); EXPECT_NE(FindTextCommand(editedFrame.drawData, "!OK"), nullptr); + EXPECT_NE(FindTextCommand(editedFrame.drawData, " X"), nullptr); EXPECT_EQ(editedFrame.stats.focusedElementId, "sessionNotes"); }