Skip to content

Commit

Permalink
TestEngine: ComboClickAll() supports when item doesn't close combo + …
Browse files Browse the repository at this point in the history
…remove initial extraneous click.
  • Loading branch information
ocornut committed Dec 20, 2024
1 parent 42d0539 commit 2e2d83a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ CHANGELOG
2024/12/20:
- TestEngine: fixed error recovery mis-asserting after a GuiFunc triggered
a failed error (when a test fail, error recover runs but shouldn't assert).
- TestEngine: ComboClickAll() supports when item doesn't close combo
+ remove initial extraneous click.

2024/12/19:
- TestEngine: ctx->SetVarsDataType() created blocks are zero-cleared before
Expand Down
7 changes: 5 additions & 2 deletions imgui_test_engine/imgui_te_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,7 @@ void ImGuiTestContext::KeyCharsReplaceEnter(const char* chars)
}

// depth = 1 -> immediate child of 'parent' in ID Stack
// FIXME: Configurable filter for InLayerMask. Perhaps we can expose a GatherItemEx() that takes a ImGuiTestGatherTask struct as input.
void ImGuiTestContext::GatherItems(ImGuiTestItemList* out_list, ImGuiTestRef parent, int depth)
{
IM_ASSERT(out_list != NULL);
Expand All @@ -2703,7 +2704,7 @@ void ImGuiTestContext::GatherItems(ImGuiTestItemList* out_list, ImGuiTestRef
parent.ID = GetID(parent);
task->InParentID = parent.ID;
task->InMaxDepth = depth;
task->InLayerMask = (1 << ImGuiNavLayer_Main); // FIXME: Configurable filter
task->InLayerMask = (1 << ImGuiNavLayer_Main);
task->OutList = out_list;

// Keep running while gathering
Expand Down Expand Up @@ -3511,7 +3512,9 @@ void ImGuiTestContext::ComboClickAll(ImGuiTestRef ref_parent)
GatherItems(&items, "//$FOCUSED");
for (auto item : items)
{
ItemClick(ref_parent); // We assume that every interaction will close the combo again
// Reopen popup when closed
if (GetWindowByRef("//$FOCUSED") != popup)
ItemClick(ref_parent);
ItemClick(item.ID);
}
}
Expand Down
29 changes: 29 additions & 0 deletions imgui_test_suite/imgui_tests_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6760,6 +6760,35 @@ void RegisterTests_TestEngine(ImGuiTestEngine* e)
}
};

// ## Test for combo functions
t = IM_REGISTER_TEST(e, "testengine", "testengine_combo");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGui::Begin("Test Window", NULL, ImGuiWindowFlags_NoSavedSettings);
if (ImGui::BeginCombo("Combo", "", ImGuiComboFlags_HeightSmall))
{
// Large enough to have a scrollbar
for (int n = 0; n < 10; n++)
ImGui::Selectable(Str30f("Item %d", n).c_str());
ImGui::EndCombo();
}
if (ImGui::BeginCombo("Combo2", "", ImGuiComboFlags_HeightSmall))
{
// Large enough to have a scrollbar
ImGui::PushItemFlag(ImGuiItemFlags_AutoClosePopups, false);
for (int n = 0; n < 10; n++)
ImGui::Selectable(Str30f("Item %d", n).c_str());
ImGui::PopItemFlag();
ImGui::EndCombo();
}
ImGui::End();
};
t->TestFunc = [](ImGuiTestContext* ctx)
{
ctx->SetRef("Test Window");
ctx->ComboClickAll("Combo");
ctx->ComboClickAll("Combo2"); // without auto-close
};

// ## Test not focusing window if unnecessary(issue #24)
t = IM_REGISTER_TEST(e, "testengine", "testengine_avoid_focus");
Expand Down

0 comments on commit 2e2d83a

Please sign in to comment.