Repository Public
1import AxeBuilder from "@axe-core/playwright";2import { expect, test, type Page } from "@playwright/test";3import { PREVIEW, PROD, S01, setTheme } from "./helpers";45/** axe-core (WCAG 2.0/2.1/2.2 A and AA + best practices) on every route, in both themes. */6const DIAGRAMS = ["tokenisation", "attention", "budget-contexte", "memoire-contexte-recherche", "pipeline-rag", "boucle-agent", "outils-permissions", "terminal-shell", "delegation-multi-agents", "carte-mcp", "flux-git", "evaluation-agents", "hebergement-modeles", "injection-requetes", "cycle-agent-de-code"];7const PROD_ROUTES = ["/", "/programme", S01, `${S01}/regarder`, "/seances/24-projet-integrateur", "/parcours", "/laboratoires", "/ressources", "/glossaire", "/recherche", "/recherche?q=agent", "/a-propos", "/accessibilite", "/confidentialite", "/conditions", "/page-introuvable"];8const PREVIEW_ROUTES = ["/", "/programme", S01, `${S01}/regarder`, "/laboratoires", "/ressources", "/glossaire", "/recherche?q=tonalite", "/schemas", "/apercu", ...DIAGRAMS.map((d) => `/schemas/${d}`)];910async function audit(page: Page, label: string) {11 const results = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa", "best-practice"]).analyze();12 const summary = results.violations.map((v) => `${v.id} (${v.impact}) — ${v.help}\n ${v.nodes.slice(0, 3).map((n) => `${n.target.join(" ")} :: ${n.failureSummary?.split("\n")[1]?.trim() ?? ""}`).join("\n ")}`);13 expect(summary, `${label}\n${summary.join("\n")}`).toEqual([]);14}1516for (const theme of ["light", "dark"] as const) {17 for (const [mode, base, routes] of [["production", PROD, PROD_ROUTES], ["aperçu", PREVIEW, PREVIEW_ROUTES]] as const) {18 for (const path of routes) {19 test(`axe · ${mode} · ${theme} · ${path}`, async ({ page }) => {20 await setTheme(page, theme);21 await page.goto(base + path, { waitUntil: "networkidle" });22 await expect(page.locator("html")).toHaveAttribute("data-theme", theme);23 await audit(page, `${mode} ${theme} ${path}`);24 });25 }26 }2728 test(`axe · états interactifs · ${theme}`, async ({ page }) => {29 await setTheme(page, theme);30 // Quiz with every kind of feedback displayed31 await page.goto(PREVIEW + "/apercu", { waitUntil: "networkidle" });32 await page.getByTestId("quiz-finish").click();33 await expect(page.getByTestId("quiz-result")).toBeVisible();34 await audit(page, "quiz corrigé");35 // Player: each study panel, then the help dialog36 await page.goto(`${PREVIEW}${S01}/regarder`, { waitUntil: "networkidle" });37 for (const tab of [/Chapitres/, /Signets/, /Notes/]) { await page.getByRole("tab", { name: tab }).click(); await audit(page, `lecteur, onglet ${tab}`); }38 await page.getByTestId("help-toggle").click();39 await audit(page, "lecteur, aide");40 await page.keyboard.press("Escape");41 // Mobile menu open42 await page.setViewportSize({ width: 375, height: 812 });43 await page.goto(PROD + "/", { waitUntil: "networkidle" });44 await page.getByRole("button", { name: "Ouvrir le menu" }).click();45 await audit(page, "menu mobile ouvert");46 // Data panel with the confirmation dialog open47 await page.goto(PROD + "/confidentialite", { waitUntil: "networkidle" });48 await page.getByTestId("clear-data").click();49 await audit(page, "confirmation d'effacement");50 });51}52