test: the side panel's focus step is held in its commit; the MenuCheck contract counts chosen roles

This commit is contained in:
2026-09-27 21:56:24 +02:00
parent 25f2d9d0e4
commit 3a9ea9e330
2 changed files with 19 additions and 4 deletions
@@ -6,7 +6,7 @@
// hover-to-peek and click-to-pin. jsdom has no matchMedia: the stub answers the two queries SidePanel
// asks from three switches, and can flip them live (a tablet turning).
import { describe, it, expect, afterEach, vi } from "vitest";
import { act, render, screen, fireEvent, cleanup, waitFor } from "@testing-library/react";
import { act, render, screen, fireEvent, cleanup } from "@testing-library/react";
vi.mock("react-i18next", async (importOriginal) => {
const actual = await importOriginal<typeof import("react-i18next")>();
@@ -106,7 +106,7 @@ describe("SidePanel · the tab under an open card", () => {
expect(screen.getByRole("button", { name: "sidebar.pinNamed:Filters" }).tabIndex).toBe(0);
});
it("hands a key's focus on the tab to the card it peeks open, not to the hidden tab", async () => {
it("hands a key's focus on the tab to the card it peeks open, not to the hidden tab", () => {
stubMedia({ coarse: false, narrow: false, wide: true });
globalThis.ResizeObserver ??= class {
observe() {}
@@ -115,10 +115,14 @@ describe("SidePanel · the tab under an open card", () => {
} as unknown as typeof ResizeObserver;
mount(true);
const tab = screen.getByRole("button", { name: "sidebar.pinNamed:Filters" });
// A page the browser is not painting runs no animation frame: the step must not wait for one.
const raf = vi.spyOn(window, "requestAnimationFrame").mockImplementation(() => 0);
act(() => tab.focus()); // jsdom calls every focus :focus-visible — a key's focus, here
await waitFor(() => expect(document.activeElement?.closest("aside")).not.toBeNull());
// in the commit that opens the card, not a frame later
expect(document.activeElement?.closest("aside")).not.toBeNull();
expect(document.activeElement?.getAttribute("aria-label")).toBe("sidebar.pinNamed:Filters");
expect(document.activeElement).not.toBe(tab);
raf.mockRestore();
});
});