From def38b5e3621e03a82a73c2ef97a0924bc1c26b0 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 15:21:11 +0900 Subject: [PATCH] test(e2e): check focus after a mobile drawer link navigation (R3-6) Co-Authored-By: Claude Opus 5.5 --- tests/e2e/app-shell.spec.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/e2e/app-shell.spec.ts b/tests/e2e/app-shell.spec.ts index 3a96072f..61a1ad8a 100644 --- a/tests/e2e/app-shell.spec.ts +++ b/tests/e2e/app-shell.spec.ts @@ -42,3 +42,38 @@ test("provides an escape-dismissible mobile navigation", async ({ page }) => { await expect(page.getByRole("navigation", { name: "주요 탐색" })).toBeHidden(); await expect(menu).toBeFocused(); }); + +// R3-6. A drawer link closes the modal drawer and changes the route in the +// same click. The drawer's deferred focus restore must not win over the new +// page's heading focus; Escape (no navigation) still returns to the menu. +test("moves focus to the new page after a mobile drawer link, not back to the menu", async ({ + page, +}) => { + await page.setViewportSize({ width: 390, height: 844 }); + await page.goto("/"); + const menu = page.getByRole("button", { name: "메뉴", exact: true }); + const navigation = page.getByRole("navigation", { name: "주요 탐색" }); + + await menu.click(); + await navigation.getByRole("link", { name: "화면 상태" }).click(); + + await expect(page).toHaveURL(/\/examples\/states$/); + await expect(menu).toHaveAttribute("aria-expanded", "false"); + const heading = page.getByRole("heading", { level: 1, name: "화면 상태" }); + await expect(heading).toBeFocused(); + // Give any late restore (dialog close timer, lazy route commit) time to run. + await page.waitForTimeout(300); + expect( + await page.evaluate(() => { + const active = document.activeElement; + return active?.matches("h1, main") === true; + }), + ).toBe(true); + await expect(menu).not.toBeFocused(); + + await menu.click(); + await expect(navigation).toBeVisible(); + await page.keyboard.press("Escape"); + await expect(navigation).toBeHidden(); + await expect(menu).toBeFocused(); +});