yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_ui_tests.cc
Go to the documentation of this file.
2
3#if defined(YAZE_ENABLE_IMGUI_TEST_ENGINE) && YAZE_ENABLE_IMGUI_TEST_ENGINE
4
5#include "imgui.h"
6#if __has_include("imgui_test_engine/imgui_te_context.h")
7#include "imgui_test_engine/imgui_te_context.h"
8#elif __has_include("imgui_te_context.h")
9#include "imgui_te_context.h"
10#else
11#error "ImGui Test Engine context header not found"
12#endif
13
14#if __has_include("imgui_test_engine/imgui_te_engine.h")
15#include "imgui_test_engine/imgui_te_engine.h"
16#elif __has_include("imgui_te_engine.h")
17#include "imgui_te_engine.h"
18#else
19#error "ImGui Test Engine engine header not found"
20#endif
21
22namespace yaze::test {
23
24// ============================================================================
25// Test: Panel visibility toggles
26//
27// Verifies that dungeon editor panels can be opened and closed via the
28// PanelManager without crashing or leaving orphaned state.
29// ============================================================================
30
31static void RegisterPanelVisibilityTests(ImGuiTestEngine* engine) {
32 // Test: Object Editor panel opens when requested
33 {
34 ImGuiTest* test =
35 IM_REGISTER_TEST(engine, "dungeon_panels", "object_editor_opens");
36 test->TestFunc = [](ImGuiTestContext* ctx) {
37 ctx->SetRef("Dungeon Workbench");
38 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
39 ctx->WindowFocus("");
40 ctx->ItemClick("**/BG1");
41 ctx->ItemClick("**/BG1");
42 };
43 }
44
45 // Test: Room selector panel can be focused
46 {
47 ImGuiTest* test =
48 IM_REGISTER_TEST(engine, "dungeon_panels", "room_selector_exists");
49 test->TestFunc = [](ImGuiTestContext* ctx) {
50 ctx->SetRef("Room Selector");
51 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
52 ctx->WindowFocus("");
53 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
54 };
55 }
56}
57
58// ============================================================================
59// Test: Layer visibility toggles (BG1/BG2/Sprites/Grid/Bounds)
60//
61// The compact layer toggle bar renders SmallButton("BG1"), SmallButton("BG2"),
62// etc. inside the canvas viewer. These are standard ImGui buttons addressable
63// by the test engine.
64// ============================================================================
65
66static void RegisterLayerToggleTests(ImGuiTestEngine* engine) {
67 // Test: BG1 toggle button exists and is clickable
68 {
69 ImGuiTest* test =
70 IM_REGISTER_TEST(engine, "dungeon_layers", "bg1_toggle_clickable");
71 test->TestFunc = [](ImGuiTestContext* ctx) {
72 // Navigate to the workbench first
73 ctx->SetRef("Dungeon Workbench");
74 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
75 ctx->WindowFocus("");
76 ctx->ItemClick("**/BG1");
77
78 // Click again to restore original state
79 ctx->ItemClick("**/BG1");
80 };
81 }
82
83 // Test: BG2 toggle
84 {
85 ImGuiTest* test =
86 IM_REGISTER_TEST(engine, "dungeon_layers", "bg2_toggle_clickable");
87 test->TestFunc = [](ImGuiTestContext* ctx) {
88 ctx->SetRef("Dungeon Workbench");
89 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
90 ctx->WindowFocus("");
91 ctx->ItemClick("**/BG2");
92 ctx->ItemClick("**/BG2");
93 };
94 }
95}
96
97// ============================================================================
98// Test: Workbench toolbar interactions
99//
100// Tests that toolbar buttons in the workbench panel respond to clicks.
101// ============================================================================
102
103static void RegisterToolbarTests(ImGuiTestEngine* engine) {
104 // Test: Workbench window can be focused
105 {
106 ImGuiTest* test =
107 IM_REGISTER_TEST(engine, "dungeon_toolbar", "workbench_focus");
108 test->TestFunc = [](ImGuiTestContext* ctx) {
109 ctx->SetRef("Dungeon Workbench");
110 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
111 ctx->WindowFocus("");
112 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
113 };
114 }
115}
116
117// ============================================================================
118// Test: Keyboard shortcut smoke tests
119//
120// Verifies that common keyboard shortcuts don't crash the application.
121// These are smoke tests - they verify no crash, not specific behavior
122// (behavior depends on editor state which may vary).
123// ============================================================================
124
125static void RegisterKeyboardShortcutTests(ImGuiTestEngine* engine) {
126 // Test: Escape key doesn't crash (should cancel placement if active)
127 {
128 ImGuiTest* test =
129 IM_REGISTER_TEST(engine, "dungeon_keys", "escape_no_crash");
130 test->TestFunc = [](ImGuiTestContext* ctx) {
131 ctx->SetRef("Dungeon Workbench");
132 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
133 ctx->WindowFocus("");
134 ctx->KeyPress(ImGuiKey_Escape);
135 ctx->Yield(3); // Let a few frames process
136 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
137 };
138 }
139
140 // Test: Delete key doesn't crash (should delete selection if any)
141 {
142 ImGuiTest* test =
143 IM_REGISTER_TEST(engine, "dungeon_keys", "delete_no_crash");
144 test->TestFunc = [](ImGuiTestContext* ctx) {
145 ctx->SetRef("Dungeon Workbench");
146 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
147 ctx->WindowFocus("");
148 ctx->KeyPress(ImGuiKey_Delete);
149 ctx->Yield(3);
150 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
151 };
152 }
153
154 // Test: Ctrl+Z (undo) doesn't crash
155 {
156 ImGuiTest* test = IM_REGISTER_TEST(engine, "dungeon_keys", "undo_no_crash");
157 test->TestFunc = [](ImGuiTestContext* ctx) {
158 ctx->SetRef("Dungeon Workbench");
159 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
160 ctx->WindowFocus("");
161 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Z);
162 ctx->Yield(3);
163 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
164 };
165 }
166}
167
168// ============================================================================
169// Test: Toast dedup verification
170//
171// Triggers the same error condition twice rapidly and verifies the UI
172// doesn't stack duplicate toasts. Since we can't easily inspect toast
173// state from the test engine, we verify the action doesn't crash and
174// the UI remains responsive.
175// ============================================================================
176
177static void RegisterToastTests(ImGuiTestEngine* engine) {
178 // Test: Rapid repeated actions don't flood the UI
179 {
180 ImGuiTest* test =
181 IM_REGISTER_TEST(engine, "dungeon_toast", "rapid_actions_stable");
182 test->TestFunc = [](ImGuiTestContext* ctx) {
183 ctx->SetRef("Dungeon Workbench");
184 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
185 ctx->WindowFocus("");
186
187 // Rapidly press escape multiple times - if placement mode is active
188 // this would generate repeated "placement cancelled" toasts.
189 // With dedup, only one should appear.
190 for (int i = 0; i < 5; ++i) {
191 ctx->KeyPress(ImGuiKey_Escape);
192 ctx->Yield(1);
193 }
194 ctx->Yield(5); // Let toasts settle
195 IM_CHECK(ctx->GetWindowByRef("") != nullptr);
196 };
197 }
198}
199
200// ============================================================================
201// Public registration entry point
202// ============================================================================
203
204void RegisterDungeonUITests(ImGuiTestEngine* engine) {
205 RegisterPanelVisibilityTests(engine);
206 RegisterLayerToggleTests(engine);
207 RegisterToolbarTests(engine);
208 RegisterKeyboardShortcutTests(engine);
209 RegisterToastTests(engine);
210}
211
212} // namespace yaze::test
213
214#else // !YAZE_ENABLE_IMGUI_TEST_ENGINE
215
216namespace yaze::test {
217void RegisterDungeonUITests(ImGuiTestEngine*) {}
218} // namespace yaze::test
219
220#endif // YAZE_ENABLE_IMGUI_TEST_ENGINE
void RegisterDungeonUITests(ImGuiTestEngine *)