From 3cee1f12dab45594e85cbd9fbe9a3af5af182789 Mon Sep 17 00:00:00 2001 From: dotta Date: Thu, 9 Apr 2026 10:38:21 -0500 Subject: [PATCH] test(ui): wait for workspace selector in new issue dialog test --- ui/src/components/NewIssueDialog.test.tsx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ui/src/components/NewIssueDialog.test.tsx b/ui/src/components/NewIssueDialog.test.tsx index d492e907..3e652a02 100644 --- a/ui/src/components/NewIssueDialog.test.tsx +++ b/ui/src/components/NewIssueDialog.test.tsx @@ -222,6 +222,18 @@ async function flush() { }); } +async function waitForValue(getValue: () => T | null | undefined, attempts = 10): Promise { + for (let attempt = 0; attempt < attempts; attempt += 1) { + const value = getValue(); + if (value != null) { + return value; + } + await flush(); + } + + throw new Error("Timed out waiting for value"); +} + function renderDialog(container: HTMLDivElement) { const queryClient = new QueryClient({ defaultOptions: { @@ -421,13 +433,13 @@ describe("NewIssueDialog", () => { expect(container.textContent).not.toContain("will no longer use the parent issue workspace"); - const selects = Array.from(container.querySelectorAll("select")); - const modeSelect = selects[0] as HTMLSelectElement | undefined; - expect(modeSelect).not.toBeUndefined(); + const modeSelect = await waitForValue( + () => container.querySelector("select") as HTMLSelectElement | null, + ); await act(async () => { - modeSelect!.value = "shared_workspace"; - modeSelect!.dispatchEvent(new Event("change", { bubbles: true })); + modeSelect.value = "shared_workspace"; + modeSelect.dispatchEvent(new Event("change", { bubbles: true })); }); await flush();