Files
clean-architecture-frontend…/tests/e2e/reference-form.spec.ts
T
DongHyeonkaandClaude Opus 5.5 f17572a4be test(a11y): scan the rendered route, signed in and per state (08-05, 11-02)
axe ran as soon as `main` showed, which is the app shell's loading surface,
and protected routes were scanned on the sign-in prompt. The specs now wait
for the route's h1, sign in first, and scan the reference list, detail, form
and status states. The state-surfaces baseline was the loading surface.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 00:25:46 +09:00

151 lines
5.7 KiB
TypeScript

import AxeBuilder from "@axe-core/playwright";
import type { Page } from "@playwright/test";
import { expect, test } from "../support/browser/strict-browser-test.ts";
async function openReferenceForm(page: Page) {
await page.goto("/examples/reference-resources/new");
await page.getByRole("button", { name: "로그인 시작" }).click();
await expect(
page.getByRole("heading", { name: "Reference resource 만들기" }),
).toBeVisible();
}
test("validates a reference form and focuses the first invalid field", async ({
page,
}) => {
await openReferenceForm(page);
await page.getByRole("button", { name: "저장" }).click();
const firstField = page.getByRole("textbox", { name: /새 항목 이름/ });
await expect(firstField).toBeFocused();
await expect(firstField).toHaveAttribute("aria-invalid", "true");
await expect(page.getByRole("alert")).toContainText("입력 내용을 확인해 주세요.");
});
test("guards dirty cancellation and restores focus when writing continues", async ({
page,
}) => {
await openReferenceForm(page);
await page
.getByRole("textbox", { name: /새 항목 이름/ })
.fill("Unsaved reference");
const cancel = page.getByRole("button", { name: "취소" });
await cancel.click();
await expect(
page.getByRole("dialog", { name: "저장하지 않은 변경이 있습니다." }),
).toBeVisible();
await page.getByRole("button", { name: "계속 작성" }).click();
await expect(cancel).toBeFocused();
await expect(page).toHaveURL(/\/examples\/reference-resources\/new$/);
});
test("keeps the form template within a 320px viewport", async ({ page }) => {
await page.setViewportSize({ width: 320, height: 720 });
await openReferenceForm(page);
const viewport = await page.evaluate(() => ({
clientWidth: document.documentElement.clientWidth,
scrollWidth: document.documentElement.scrollWidth,
}));
expect(viewport.scrollWidth).toBeLessThanOrEqual(viewport.clientWidth);
});
// 08-04. Feature screens take their words from the catalog. This lives with
// the sample's specs so removing the sample removes it too.
test("renders the reference screens without Korean copy in en-US", async ({
page,
}) => {
await page.route("http://localhost:8080/api/reference-resources?*", (route) =>
route.fulfill({
json: [
{
id: "browser-reference",
name: "Browser reference",
createdAt: "2026-07-26T00:00:00.000Z",
},
],
}),
);
await page.goto("/examples/reference-resources");
await page.getByRole("button", { name: "로그인 시작" }).click();
await expect(page.getByRole("link", { name: "Browser reference" })).toBeVisible();
await page.getByRole("combobox", { name: "언어" }).selectOption("en-US");
const main = page.getByRole("main");
await expect(main.getByRole("status")).toHaveText("Total items: 1");
await expect(main).not.toContainText(/[가-힣]/);
await main.getByRole("button", { name: "Create item" }).click();
await expect(main.getByRole("button", { name: "Save" })).toBeVisible();
await expect(main).not.toContainText(/[가-힣]/);
});
const LIST_PATH = "/examples/reference-resources";
const LIST_API = "http://localhost:8080/api/reference-resources?*";
const BROWSER_REFERENCE = {
id: "browser-reference",
name: "Browser reference",
createdAt: "2026-07-26T00:00:00.000Z",
};
async function signInAt(page: Page, path: string, heading: string) {
await page.goto(path);
await page.getByRole("button", { name: "로그인 시작" }).click();
await expect(page.getByRole("heading", { level: 1 })).toHaveText(heading);
}
async function expectNoBlockingViolations(page: Page) {
const results = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(
results.violations.filter((violation) =>
["critical", "serious"].includes(violation.impact ?? ""),
),
).toEqual([]);
}
// 08-05. The protected reference screens are scanned signed in and in each
// state they can show. The state must be on screen before axe runs.
for (const [state, payload, visible] of [
["success", [BROWSER_REFERENCE], "Browser reference"],
["empty", [], "표시할 항목이 없습니다."],
// A 200 that breaks the response schema: a 5xx would also log a console
// error, which the strict fixture rejects on its own.
["error", [{ wrong: true }], "서버 응답 데이터가 현재 화면과 맞지 않습니다."],
] as const) {
test(`@a11y reference list ${state} state has no blocking violations`, async ({
page,
}) => {
await page.route(LIST_API, (route) => route.fulfill({ json: payload }));
await signInAt(page, LIST_PATH, "Reference feature");
await expect(page.getByRole("main")).toContainText(visible);
await expectNoBlockingViolations(page);
});
}
test("@a11y reference detail has no blocking violations", async ({ page }) => {
await page.route(
"http://localhost:8080/api/reference-resources/browser-reference",
(route) => route.fulfill({ json: BROWSER_REFERENCE }),
);
await signInAt(page, `${LIST_PATH}/browser-reference`, "Browser reference");
await expectNoBlockingViolations(page);
});
test("@a11y reference form with submit errors has no blocking violations", async ({
page,
}) => {
await signInAt(page, `${LIST_PATH}/new`, "Reference resource 만들기");
await page.getByRole("button", { name: "저장" }).click();
await expect(page.getByRole("alert")).toContainText("입력 내용을 확인해 주세요.");
await expectNoBlockingViolations(page);
});
test("@a11y reference status page has no blocking violations", async ({
page,
}) => {
await signInAt(page, `${LIST_PATH}/status`, "잠시 사용할 수 없습니다.");
await expectNoBlockingViolations(page);
});