Public pages, auth, registration, payment, My Events and the kiosk: skip link, focus ring, labels tied to fields, named quantity buttons, announced errors, ModalOverlay popups (focus trap, Escape, focus return), contrast and underlined in-text links, reduced motion. Branding warns about a primary colour too light for white text and offers a darker shade. axe-core and keyboard checks in e2e/accessibility.spec.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
6.5 KiB
TypeScript
137 lines
6.5 KiB
TypeScript
import AxeBuilder from "@axe-core/playwright";
|
|
import type { Page } from "@playwright/test";
|
|
import { test, expect, seed, loginAs } from "./fixtures";
|
|
|
|
// WCAG 2.2 AA checks (axe-core) on the pages visitors and members use, so the
|
|
// accessibility pass (1.50.0) doesn't regress.
|
|
const TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"];
|
|
|
|
async function check(page: Page, label: string) {
|
|
// Let animations and late-loading data settle so colours are measured as shown.
|
|
await page.waitForLoadState("networkidle");
|
|
await page.waitForTimeout(300);
|
|
const results = await new AxeBuilder({ page }).withTags(TAGS).analyze();
|
|
const summary = results.violations.map((v) => ({
|
|
id: v.id,
|
|
help: v.help,
|
|
nodes: v.nodes.map((n) => `${n.target.join(" ")} — ${n.failureSummary?.split("\n").slice(0, 2).join(" ")}`),
|
|
}));
|
|
expect.soft(summary, `${label}: accessibility violations`).toEqual([]);
|
|
}
|
|
|
|
async function visit(page: Page, url: string, label: string, ready?: () => Promise<void>) {
|
|
await page.goto(url);
|
|
if (ready) await ready();
|
|
await check(page, label);
|
|
}
|
|
|
|
test.describe("accessibility (WCAG 2.2 AA)", () => {
|
|
test("public pages", async ({ page }) => {
|
|
await visit(page, "/", "home");
|
|
await visit(page, "/events", "events", () => expect(page.getByText("E2E Free Evening")).toBeVisible());
|
|
await visit(page, `/events/${seed().events.course}`, "event page", () =>
|
|
expect(page.getByRole("heading", { name: "E2E Alpha Course" })).toBeVisible(),
|
|
);
|
|
await visit(page, `/events/${seed().events.dropIn}`, "drop-in event page");
|
|
await visit(page, "/contact", "contact");
|
|
await visit(page, "/legal/privacy", "privacy notice");
|
|
await visit(page, "/legal/terms", "terms");
|
|
});
|
|
|
|
test("sign in, sign up and forgot password, with errors", async ({ page }) => {
|
|
await visit(page, "/login", "login");
|
|
await page.getByLabel("Email or phone").fill(seed().users.user.email);
|
|
await page.getByLabel("Password", { exact: true }).fill("not-the-password");
|
|
await page.getByRole("button", { name: "Login" }).click();
|
|
await expect(page.getByRole("alert")).toBeVisible();
|
|
await check(page, "login with an error");
|
|
await visit(page, "/register", "sign up");
|
|
await visit(page, "/forgot-password", "forgot password");
|
|
});
|
|
|
|
test("registration form", async ({ page }) => {
|
|
await loginAs(page, "user");
|
|
await visit(page, `/register/${seed().events.paid}`, "registration", async () => {
|
|
await page.getByRole("button", { name: /^Add one / }).first().click();
|
|
await expect(page.getByText("Total: R150.00")).toBeVisible();
|
|
});
|
|
await visit(page, `/register/${seed().events.dropIn}`, "registration (pick sessions)");
|
|
});
|
|
|
|
test("My Events and account pages", async ({ page }) => {
|
|
await loginAs(page, "user");
|
|
await visit(page, "/dashboard/user", "My Events");
|
|
await visit(page, "/dashboard/user/profile", "profile");
|
|
await visit(page, "/dashboard/user/privacy", "privacy centre");
|
|
await visit(page, "/dashboard/user/payments", "payments");
|
|
await visit(page, "/dashboard/user/kids", "kids");
|
|
await visit(page, "/dashboard/user/serving", "serving");
|
|
});
|
|
|
|
test("self-service kiosk", async ({ page }) => {
|
|
await visit(page, "/self-service", "kiosk sign-in");
|
|
await page.getByPlaceholder("supervisor@example.com").fill(seed().users.supervisor.email);
|
|
await page.getByPlaceholder("••••••••").fill("E2e-password-123");
|
|
await page.getByRole("button", { name: "Sign In" }).click();
|
|
await expect(page.getByText("Signed in as supervisor")).toBeVisible();
|
|
await check(page, "kiosk event picker");
|
|
const value = await page.locator("option", { hasText: "E2E Free Evening" }).getAttribute("value");
|
|
await page.locator("select").selectOption(value!);
|
|
await page.getByRole("button", { name: "Start Kiosk" }).click();
|
|
await expect(page.getByRole("heading", { name: "E2E Free Evening" })).toBeVisible();
|
|
await check(page, "kiosk form");
|
|
|
|
// "Create an account" is a switch you can reach and flip with the keyboard.
|
|
const create = page.getByRole("switch", { name: /Create an account/ });
|
|
await create.focus();
|
|
await page.keyboard.press("Space");
|
|
await expect(create).toHaveAttribute("aria-checked", "true");
|
|
await expect(page.getByLabel("Choose a password")).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test.describe("keyboard", () => {
|
|
test("the first Tab reaches “Skip to main content”, which moves focus to the page content", async ({ page }) => {
|
|
await page.goto("/events");
|
|
await expect(page.getByText("E2E Free Evening")).toBeVisible();
|
|
await page.keyboard.press("Tab");
|
|
const skip = page.getByRole("link", { name: "Skip to main content" });
|
|
await expect(skip).toBeFocused();
|
|
await page.keyboard.press("Enter");
|
|
await expect(page.locator("main").first()).toBeFocused();
|
|
});
|
|
|
|
test("a popup keeps focus inside, closes with Escape and hands focus back", async ({ page }) => {
|
|
await page.goto("/self-service");
|
|
await page.getByLabel("Email").fill(seed().users.supervisor.email);
|
|
await page.getByLabel("Password", { exact: true }).fill("E2e-password-123");
|
|
await page.getByRole("button", { name: "Sign In" }).click();
|
|
const value = await page.locator("option", { hasText: "E2E Free Evening" }).getAttribute("value");
|
|
await page.getByLabel("Event").selectOption(value!);
|
|
await page.getByRole("button", { name: "Start Kiosk" }).click();
|
|
|
|
const opener = page.getByRole("button", { name: "Change Event" });
|
|
await opener.focus();
|
|
await page.keyboard.press("Enter");
|
|
const dialog = page.getByRole("dialog", { name: "Change Event" });
|
|
await expect(dialog).toBeVisible();
|
|
await expect(dialog.getByLabel("Password", { exact: true })).toBeFocused();
|
|
// Tab doesn't leave the popup.
|
|
for (let i = 0; i < 4; i++) await page.keyboard.press("Tab");
|
|
expect(await dialog.evaluate((el) => el.contains(document.activeElement))).toBe(true);
|
|
await page.keyboard.press("Escape");
|
|
await expect(dialog).toBeHidden();
|
|
await expect(opener).toBeFocused();
|
|
});
|
|
|
|
test("ticket quantities can be changed with the keyboard and are announced by name", async ({ page }) => {
|
|
await loginAs(page, "user");
|
|
await page.goto(`/register/${seed().events.paid}`);
|
|
const add = page.getByRole("button", { name: /^Add one / }).first();
|
|
await add.focus();
|
|
await page.keyboard.press("Enter");
|
|
await expect(page.getByText("Total: R150.00")).toBeVisible();
|
|
await expect(page.getByRole("button", { name: /^Remove one / }).first()).toBeEnabled();
|
|
});
|
|
});
|