import AxeBuilder from "@axe-core/playwright"; import { expect, test, type APIRequestContext } from "@playwright/test"; async function ensureServices(request: APIRequestContext) { await request.post("/api/v1/demo/exit"); const existing = (await (await request.get("/api/v1/services")).json()) as { service: { name: string } }[]; const names = new Set(existing.map((item) => item.service.name)); for (const name of ["A11y Database", "A11y API"]) { if (names.has(name)) continue; const response = await request.post("/api/v1/services", { data: { name, kind: "tcp", host: "127.0.0.1", port: 9, environment: "test" }, }); expect(response.ok(), await response.text()).toBeTruthy(); } } test.beforeEach(async ({ request }) => { await ensureServices(request); }); const PANELS = ["topology", "overview", "incidents", "services", "discovery", "changes", "activity", "config", "settings"]; for (const panel of PANELS) { test(`${panel} has no serious or critical axe violations`, async ({ page }) => { await page.goto(`/#/${panel}`); await expect(page.getByRole("navigation", { name: "ServiceMap-werkruimtes" })).toBeVisible(); await expect(page.locator("main#main-content")).toBeVisible(); await page.waitForLoadState("networkidle"); const results = await new AxeBuilder({ page }) .withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]) .analyze(); const blocking = results.violations .filter((violation) => violation.impact === "serious" || violation.impact === "critical") .map((violation) => `${violation.id}: ${violation.nodes.map((node) => node.target.join(" ")).slice(0, 5).join(" | ")}`); expect(blocking, blocking.join("\n")).toEqual([]); }); } test("navigation marks the current workspace and the skip link reaches content", async ({ page }) => { await page.goto("/#/services"); await expect(page.getByRole("button", { name: "Services", exact: true })).toHaveAttribute("aria-current", "page"); await page.keyboard.press("Tab"); const skip = page.getByRole("link", { name: "Naar inhoud springen" }); await expect(skip).toBeFocused(); await page.keyboard.press("Enter"); await expect(page.locator("main#main-content")).toBeFocused(); }); test("the topology can be explored with the keyboard alone", async ({ page }) => { await page.goto("/#/topology"); // Canvas nodes are focusable, labelled, and open the inspector on Enter. const node = page.locator(".react-flow__node").first(); // The first layout can take a while on a busy machine; wait for it, not for a fixed delay. await expect(node).toHaveAttribute("aria-label", /, (Gezond|Verminderd|Uitgevallen|Onbekend|Niet bewaakt|Herstellend|Onderhoud)/, { timeout: 30_000, }); await node.focus(); await page.keyboard.press("Enter"); await expect(page).toHaveURL(/(service|in_domain|in_app)=/); // The list alternative offers the same with plain buttons. await page.getByRole("button", { name: "Als lijst tonen" }).click(); const list = page.getByRole("region", { name: "Topologie als lijst" }); await expect(list).toBeVisible(); await list.getByRole("button").first().focus(); await page.keyboard.press("Enter"); await expect(page.getByRole("button", { name: "Grafiek tonen" })).toHaveAttribute("aria-pressed", "true"); });