문제 tests/e2e/accessibility.spec.ts는 보호 라우트의 모든 API에 맨 배열 `[]`를 답했다. create:feature가 만드는 기능은 responseEnvelope: "ENVELOPE_V1"이라 `[]`는 ENVELOPE_MISMATCH가 되고, 페이지는 경고 상자를 그린다. spec은 h1과 axe만 봐서 오류 화면을 검사하고도 통과했고, 증거는 그 라우트를 "passed"로 적었다. 경로 파라미터는 `:resourceId`만 바꿔서 다른 이름을 쓰는 기능은 이 템플릿 파일을 고쳐야 했다. 고른 방법 (결정 D4 (b)) - tests/e2e/support/installed-api-answers.ts가 요청을 설치된 GET descriptor에서 method와 pathTemplate으로 찾는다. 출력 스키마가 빈 목록을 받으면 그 operation의 모양으로 답한다(Envelope면 MSW 시나리오와 같은 successEnvelope, 아니면 맨 배열). - 목록만 읽은 라우트는 로딩이 끝난 뒤 경고 상자(role="alert")가 없다고 단언한다. 모양이 다시 어긋나면 axe 통과 대신 여기서 실패한다. - 경로 파라미터는 이름과 상관없이 모두 a11y-1로 바꾼다. 기능을 더해도 spec을 고치지 않는다(16-03 앞 절반). - 설치된 GET이 아닌 요청, 빈 목록을 받지 않는 파라미터 없는 GET은 501로 답하고 그 목록이 비어 있다고 단언한다. - 매뉴얼 01·03, starter-experience, create-feature 참조, 수동 점검 문서의 "모든 API에 []", ".replace를 잇는다" 문장을 동작에 맞췄다. - 버린 대안: 전역 Envelope 응답(참조 기능 DTO가 거꾸로 깨짐), 기능마다 접근성 spec 생성(파일·실행 시간 증가). 위험·한계 - 한 자원을 읽는 GET(상세 페이지)에는 빈 목록 말고 줄 본문이 없다. 그 라우트는 지금처럼 실패 상태로 검사하고 a11y-data-state annotation만 남긴다. 경고 상자 단언은 그 라우트에서 건너뛴다. - write-a11y-report.ts의 증거는 annotation을 읽지 않는다. 상세 라우트도 "passed"로 적힌다. 검증 - 새 unit 테스트 6건: helper가 없을 때 실패, 추가 뒤 통과. - 템플릿 상태 chromium test:a11y 대상 spec 14건 통과. - create:feature sample-feature 상태에서 `@a11y /sample` 세 엔진 통과. 변이 1(Envelope 대신 맨 배열): 세 엔진 모두 경고 상자 단언으로 실패. 변이 2(빈·성공 상태에서만 보이는 이름 없는 버튼): 세 엔진 모두 axe button-name으로 실패. 생성 파일은 지웠다. - check:types:test, eslint, verify:documentation, check:ci 통과. Refs: docs/reviews/2026-11-03-maturity-review/11-tests-browser-release-scale.md 11-01 Refs: docs/reviews/2026-11-03-maturity-review/16-structure-patterns.md 16-03
147 lines
6.0 KiB
TypeScript
147 lines
6.0 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 { 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,
|
|
}) => {
|
|
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);
|
|
} else {
|
|
// No generic body answers a read of one resource: a detail page is
|
|
// scanned in its failure state, and the report says which.
|
|
test.info().annotations.push({
|
|
type: "a11y-data-state",
|
|
description: `failure state: ${singleResourceReads.join(", ")} reads one resource`,
|
|
});
|
|
}
|
|
} 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");
|
|
});
|
|
|
|
// 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);
|
|
});
|
|
|
|
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([]);
|
|
});
|