Skip to content

Commit 5bccd4e

Browse files
committed
test(gamestudio): select the Use button by label, not by DOM shape
Fold Kilo review nit: find the card's action button by its text instead of grabbing the first button (drops the exactly-one-button assumption) and narrow the card element with an explicit guard instead of a bare non-null assertion.
1 parent 01444db commit 5bccd4e

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

desktop/src/apps/GameStudioApp.test.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,22 @@ describe("GameStudioApp", () => {
120120
it("selecting a template from the gallery routes to Play and loads its scene", () => {
121121
renderApp("gamestudio-template-select-test");
122122
const template = TEMPLATES[2]!; // pick a non-default template so the routing is provable
123-
// Scope to this template's card (so we cannot click another card's button)
124-
// and grab its single action button directly. Using querySelector rather
125-
// than getByRole avoids the accessible-name role computation, which was
126-
// non-deterministic in the full CI suite; the card has exactly one button
127-
// (Use), so this is unambiguous.
123+
// Scope to this template's card (so we cannot click another card's button),
124+
// then find its action button by label. Selecting by text rather than
125+
// grabbing the first button drops the assumption that the card has exactly
126+
// one button; using querySelectorAll rather than getByRole avoids the
127+
// accessible-name role computation, which was non-deterministic in the full
128+
// CI suite.
128129
const titleEl = screen.getByText(template.title);
129-
const card = titleEl.closest("[class*='rounded-2xl']") as HTMLElement | null;
130-
expect(card).toBeTruthy();
131-
const useButton = card!.querySelector("button") as HTMLButtonElement;
132-
expect(useButton.textContent).toContain("Use");
133-
fireEvent.click(useButton);
130+
const card = titleEl.closest("[class*='rounded-2xl']");
131+
if (!(card instanceof HTMLElement)) {
132+
throw new Error("template card not found");
133+
}
134+
const useButton = Array.from(card.querySelectorAll("button")).find((b) =>
135+
b.textContent?.includes("Use"),
136+
);
137+
expect(useButton).toBeTruthy();
138+
fireEvent.click(useButton!);
134139

135140
const nav = screen.getByRole("navigation", { name: "Game Studio views" });
136141
const playBtn = nav.querySelector('[aria-label="Play"]') as HTMLElement;

0 commit comments

Comments
 (0)