Files
clean-architecture-frontend…/tests/e2e/accessibility.spec.ts
T
donghyeon-kaandClaude Opus 5.5 02b90b2244 test(a11y): keep the route scan typechecking after sample removal (08-05)
With the sample removed every route is public, so comparing access with
session-required no longer typechecked and test:sample-removal failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:18:54 +09:00

88 lines
3.5 KiB
TypeScript

import AxeBuilder from "@axe-core/playwright";
import { expect, test, type Page } from "../support/browser/strict-browser-test.ts";
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
import type { RouteDefinition } from "../../src/contracts/routes.ts";
import { KO_MESSAGES } from "../../src/presentation/i18n/catalog.ts";
const WCAG_TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"];
const SIGN_IN_TITLE = KO_MESSAGES["route.auth.required.title"];
const CATALOG = KO_MESSAGES as Readonly<Record<string, string>>;
async function blockingViolations(page: Page) {
const results = await new AxeBuilder({ page }).withTags(WCAG_TAGS).analyze();
return results.violations.filter((violation) =>
["critical", "serious"].includes(violation.impact ?? ""),
);
}
// 08-05/11-02. The app shell draws `main` before the route chunk arrives, so
// axe waits for the route's own h1. A public route's h1 is its catalog title.
// A protected route is scanned after the demo sign-in, never on the sign-in
// prompt; the feature's own spec pins its exact headings and states.
// Widened: without an installed feature every route is public, and the
// `session-required` branch must still typecheck (sample removal).
const ROUTES: readonly RouteDefinition[] = Object.values(ROUTE_REGISTRY);
for (const definition of ROUTES) {
const route =
definition.path === "*"
? "/not-found"
: definition.path.replace(":resourceId", "reference-1");
test(`@a11y ${route} has no critical or serious axe violations`, async ({
page,
}) => {
const heading = page.getByRole("heading", { level: 1 });
if (definition.access === "session-required") {
// Feature data is not this spec's subject: any API answers an empty list.
await page.route("http://localhost:8080/api/**", (request) =>
request.fulfill({ json: [] }),
);
await page.goto(route);
await expect(heading).toHaveText(SIGN_IN_TITLE);
await page.getByRole("button", { name: "로그인 시작" }).click();
await expect(heading).toBeVisible();
await expect(heading).not.toHaveText(SIGN_IN_TITLE);
} else {
await page.goto(route);
const title = CATALOG[`route.${definition.routeId}.title`];
await expect(heading).toHaveText(title ?? definition.title);
}
expect(await blockingViolations(page)).toEqual([]);
});
}
test("@a11y keyboard reaches the primary route action with visible focus", async ({
page,
}) => {
await page.goto("/");
const action = page.getByRole("link", { name: "플랫폼 구성 보기" });
await expect(action).toBeVisible();
await page.keyboard.press("Tab");
await expect(action).toBeFocused();
await expect(action).toHaveCSS("outline-style", "solid");
});
test("@a11y reduced-motion policy disables long animation", async ({ page }) => {
await page.emulateMedia({ reducedMotion: "reduce" });
await page.goto("/");
const duration = await page
.locator("body")
.evaluate((body) => getComputedStyle(body).animationDuration);
expect(["0s", "0.00001s", "1e-05s"]).toContain(duration);
});
test("@a11y opened design-system dialog has no blocking violations", async ({
page,
}) => {
await page.goto("/examples/ui");
await page.getByRole("button", { name: "모달 열기" }).click();
const results = await new AxeBuilder({ page })
.include(".ui-dialog")
.withTags(WCAG_TAGS)
.analyze();
expect(
results.violations.filter((violation) =>
["critical", "serious"].includes(violation.impact ?? ""),
),
).toEqual([]);
});