107 lines
3.7 KiB
TypeScript
107 lines
3.7 KiB
TypeScript
import AxeBuilder from "@axe-core/playwright";
|
|
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
|
import {
|
|
ROUTE_FEATURE_OWNER,
|
|
ROUTE_REGISTRY,
|
|
} from "../../src/features/installed-feature-contracts.ts";
|
|
import { MEMENTO_FEATURE_ID } from "../../src/features/memento-web/contracts/memento-feature-contract.ts";
|
|
|
|
function representativePath(path: string): string {
|
|
if (path === "*") return "/not-found";
|
|
return path
|
|
.replace(":resourceId", "reference-1")
|
|
.replace(":memoryId", "memory-jeju")
|
|
.replace(":albumId", "album-family")
|
|
.replace(":personId", "person-family")
|
|
.replace(":placeId", "place-jeju");
|
|
}
|
|
|
|
for (const definition of Object.values(ROUTE_REGISTRY)) {
|
|
const route = representativePath(definition.path);
|
|
const owner = ROUTE_FEATURE_OWNER[definition.routeId];
|
|
test(`@a11y ${route} has no critical or serious axe violations`, async ({
|
|
page,
|
|
}) => {
|
|
if (owner === MEMENTO_FEATURE_ID) {
|
|
// Accessibility analysis owns the Memento document, not the third-party
|
|
// OpenStreetMap embed. Fulfil that iframe locally so headless GPU/WebGL
|
|
// support cannot turn an external map implementation warning into an app
|
|
// console/page error.
|
|
await page.route("https://www.openstreetmap.org/**", async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: "text/html; charset=utf-8",
|
|
body: "<!doctype html><html><body></body></html>",
|
|
});
|
|
});
|
|
}
|
|
|
|
await page.goto(route);
|
|
await expect(page.getByRole("main")).toBeVisible();
|
|
|
|
let analyzer = new AxeBuilder({ page }).withTags([
|
|
"wcag2a",
|
|
"wcag2aa",
|
|
"wcag21a",
|
|
"wcag21aa",
|
|
]);
|
|
if (owner === MEMENTO_FEATURE_ID) {
|
|
// The approved legacy Memento visual contract contains known AA color
|
|
// contrast debt. P2 requires pixel-equivalent migration, so changing
|
|
// those colors here would invalidate the approved visual authority.
|
|
// Only color-contrast is waived for Memento; every other serious/critical
|
|
// accessibility rule remains blocking.
|
|
analyzer = analyzer.disableRules(["color-contrast"]);
|
|
}
|
|
|
|
const results = await analyzer.analyze();
|
|
const blocking = results.violations.filter((violation) =>
|
|
["critical", "serious"].includes(violation.impact ?? ""),
|
|
);
|
|
expect(blocking).toEqual([]);
|
|
});
|
|
}
|
|
|
|
test("@a11y keyboard reaches the primary route action with visible focus", async ({
|
|
page,
|
|
}) => {
|
|
await page.goto("/examples/states");
|
|
const action = page.getByRole("button", { name: "첫 작업 시작" });
|
|
await expect(action).toBeVisible();
|
|
|
|
for (let index = 0; index < 30; index += 1) {
|
|
if (await action.evaluate((element) => document.activeElement === element)) {
|
|
break;
|
|
}
|
|
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("/examples/states");
|
|
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(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
|
|
.analyze();
|
|
expect(
|
|
results.violations.filter((violation) =>
|
|
["critical", "serious"].includes(violation.impact ?? ""),
|
|
),
|
|
).toEqual([]);
|
|
});
|