From b597627a396c5301773b2930ca923e11c1d2ed05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 25 Oct 2026 09:15:06 +0100 Subject: [PATCH] test(mental-health): press an answer once the step's question holds the focus The keys followed each other without waiting for the step to move the focus, so on a slow run Tab started from the previous answer and the number chose nothing. --- .../__tests__/check-in-wizard.browser.test.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/mental-health/__tests__/check-in-wizard.browser.test.tsx b/src/components/mental-health/__tests__/check-in-wizard.browser.test.tsx index 69469cf9f..42940e82e 100644 --- a/src/components/mental-health/__tests__/check-in-wizard.browser.test.tsx +++ b/src/components/mental-health/__tests__/check-in-wizard.browser.test.tsx @@ -57,9 +57,15 @@ async function wizard( /** * Answer the current step by its position, as a keyboard user does: each new * step focuses its question, so Tab first reaches the answers, then the - * number key chooses. + * number key chooses. The step moves the focus in an effect after it renders, + * so the keys wait for the question to hold it, as a person reading it would; + * pressed earlier, Tab started from the previous step's answer and the number + * chose nothing. */ async function pressAnswer(position: number) { + await expect + .poll(() => document.activeElement?.getAttribute("data-slot")) + .toBe("check-in-question"); await userEvent.tab(); await userEvent.keyboard(String(position)); }