예제 화면 /examples/ui·/examples/states가 visual 골든 2장과 갤러리
브라우저 시험의 대상이다. 2026-11-07 소유자 결정으로 예제 화면을
지우므로 그 역할을 먼저 옮긴다(design-docs repo-structure/
04-frontend-layout.md 9.2절 2단계 (1)).
두 갤러리 화면을 그대로 src/presentation/design-system/
galleries.stories.tsx로 옮겼다. 화면 단위 story(parameters.page)는
preview가 여백을 더하지 않아 앱 안과 같은 폭으로 그려진다. visual
설정은 Storybook 정적 빌드를 두 번째 web server로 띄우고
(TEST_VISUAL_WORKSHOP_PORT, 빌드 명령은 workshop 설정과 같은
scripts/lib/storybook-static.ts), 골든 2장은 그 story를 찍는다. 어두운
골든은 테마 선택기가 없어 시스템 dark(colorScheme)로 그린다. e2e의
갤러리 상호작용(텍스트 필드, 모달 포커스, 메뉴·탭·토스트, 열린 대화
상자 axe, 320px 리플로)은 tests/storybook/galleries.spec.ts로 옮겼다.
위험: 골든의 픽셀 색 허용치(threshold 0.2)는 그대로다. 미세한 토큰
변화는 옛 골든처럼 새 골든도 잡지 못한다.
검증(desktop): test:storybook 6 passed, test:visual 7 passed,
playwright-run-isolation 단위 시험 통과. 변이 확인: --color-action을
파랑→빨강으로 바꾸면 새 골든이 어두운 쪽 42,313px, 밝은 쪽 22,359px
차이로 실패했다. 옛 골든(main f33e4778)도 40,238px, 22,511px로 실패했다.
미세 변이(어두운 --color-danger red-500→600, 밝은 --color-danger-surface
색상각 25→145)는 옛·새 골든 모두 통과했다. 변이는 되돌렸다.
138 lines
6.2 KiB
TypeScript
138 lines
6.2 KiB
TypeScript
import AxeBuilder from "@axe-core/playwright";
|
|
import { recordA11yDataState } from "../../scripts/lib/a11y-data-state.ts";
|
|
import { expect, test, type Page } from "../support/browser/strict-browser-test.ts";
|
|
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
|
|
import { COMPOSED_CONTRACT_CONTRIBUTIONS } from "../../src/features/loaded-feature-runtimes.ts";
|
|
import type { RouteDefinition } from "../../src/contracts/routes.ts";
|
|
import { KO_MESSAGES } from "../../src/presentation/i18n/catalog.ts";
|
|
import {
|
|
answerInstalledApiRequest,
|
|
type InstalledApiAnswer,
|
|
} from "./support/installed-api-answers.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);
|
|
// 1103/16-03. Every path parameter gets one value: a feature with its own
|
|
// parameter names needs no edit here.
|
|
const PATH_PARAMETER_VALUE = "a11y-1";
|
|
const API_ORIGIN = "http://localhost:8080";
|
|
for (const definition of ROUTES) {
|
|
const route =
|
|
definition.path === "*"
|
|
? "/not-found"
|
|
: definition.path.replace(/:[A-Za-z][A-Za-z0-9_]*/gu, PATH_PARAMETER_VALUE);
|
|
test(`@a11y ${route} has no critical or serious axe violations`, async ({
|
|
page,
|
|
}) => {
|
|
// 1106/11-01. An earlier run's record never outlives this run, even when
|
|
// no record call below is reached. scripts/write-a11y-report.ts then
|
|
// fails on a route the descriptors say reads one resource.
|
|
await recordA11yDataState(definition.routeId, null);
|
|
const heading = page.getByRole("heading", { level: 1 });
|
|
if (definition.access === "session-required") {
|
|
// 1103/11-01. Feature data is not this spec's subject: a list read gets
|
|
// an empty list in the frame its descriptor declares, so the page is
|
|
// scanned in its empty state, not on a response-shape error.
|
|
const answers: InstalledApiAnswer[] = [];
|
|
await page.route(`${API_ORIGIN}/**`, (request) => {
|
|
const answer = answerInstalledApiRequest(
|
|
COMPOSED_CONTRACT_CONTRIBUTIONS,
|
|
request.request().method(),
|
|
new URL(request.request().url()).pathname,
|
|
);
|
|
answers.push(answer);
|
|
return answer.kind === "unanswerable"
|
|
? request.fulfill({ status: 501, body: answer.reason ?? answer.request })
|
|
: request.fulfill({ json: answer.body });
|
|
});
|
|
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);
|
|
await expect(page.locator("[aria-busy='true']")).toHaveCount(0);
|
|
expect(
|
|
answers.filter((answer) => answer.kind === "unanswerable"),
|
|
"requests no installed list or single-resource read answers",
|
|
).toEqual([]);
|
|
const singleResourceReads = answers.flatMap((answer) =>
|
|
answer.kind === "single-resource" ? [answer.operationId] : [],
|
|
);
|
|
if (singleResourceReads.length === 0) {
|
|
// A shape the page does not read fails here, before axe passes it.
|
|
await expect(page.getByRole("alert")).toHaveCount(0);
|
|
await recordA11yDataState(definition.routeId, null);
|
|
} else {
|
|
// No generic body answers a read of one resource: a detail page is
|
|
// scanned in its failure state. 1103/11-01. a11y.json then lists it
|
|
// under `notChecked`, not as passed.
|
|
const reason = `scanned on its failure state only: ${singleResourceReads.join(", ")} reads one resource`;
|
|
test.info().annotations.push({ type: "a11y-data-state", description: reason });
|
|
await recordA11yDataState(definition.routeId, reason);
|
|
}
|
|
} else {
|
|
await page.goto(route);
|
|
const title = CATALOG[`route.${definition.routeId}.title`];
|
|
await expect(heading).toHaveText(title ?? definition.title);
|
|
await recordA11yDataState(definition.routeId, null);
|
|
}
|
|
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");
|
|
});
|
|
|
|
// 08-09. axe's skip-link rule is best-practice, outside WCAG_TAGS, so the only
|
|
// way past the header and sidebar (WCAG 2.4.1) needs its own check.
|
|
test("@a11y skip link moves keyboard focus into main", async ({ page }) => {
|
|
await page.goto("/examples/ui");
|
|
await expect(page.getByRole("heading", { level: 1 })).toBeFocused();
|
|
const skipLink = page.getByRole("link", { name: "본문으로 건너뛰기" });
|
|
await skipLink.focus();
|
|
await expect(skipLink).toBeFocused();
|
|
|
|
await page.keyboard.press("Enter");
|
|
|
|
await expect
|
|
.poll(() =>
|
|
page.evaluate(
|
|
() => document.querySelector("main")?.contains(document.activeElement) ?? false,
|
|
),
|
|
)
|
|
.toBe(true);
|
|
});
|
|
|
|
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);
|
|
});
|