SPB Git

Repository Public

09-a11y.spec.ts 5.9 KB 143 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Command Center (MCC)8 * File             : apps/web/e2e/specs/09-a11y.spec.ts9 * Module           : web10 * Repository       : https://git.spboucher.ai/maclustr-command-center11 * Project Website  : https://clustr.spboucher.ai12 * Created          : 2026-11-1813 * Last Modified    : 2026-11-1814 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import AxeBuilder from "@axe-core/playwright";43import { expect, test, type BrowserContext, type Page } from "@playwright/test";44import { settled, signedIn, type Problems, newClient } from "../lib/harness";45import { SCREENS } from "../lib/screens";4647const TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"];4849async function audit(page: Page, name: string): Promise<void> {50  const results = await new AxeBuilder({ page }).withTags(TAGS).analyze();51  const summary = results.violations.map((v) => `${v.id} (${v.impact}): ${v.help} — ${v.nodes.map((n) => n.target.join(" ")).slice(0, 6).join(" | ")}`);52  // soft: every screen is audited even when an earlier one has violations; the test still fails53  expect.soft(summary, `axe violations on ${name}`).toEqual([]);54}5556test.describe("accessibility (axe, WCAG 2.2 AA)", () => {57  let context: BrowserContext;58  let page: Page;59  let problems: Problems;60  test.beforeAll(async ({ browser }) => {61    ({ context, page, problems } = await signedIn(browser, "e2e-owner"));62  });63  test.afterAll(async () => {64    await context.close();65  });6667  test("sign-in (dark and light)", async ({ browser }) => {68    const ctx = await newClient(browser, { conditional: true });69    const p = await ctx.newPage();70    await p.goto("/signin");71    await expect(p.getByTestId("signin-button")).toBeVisible();72    await audit(p, "signin dark");73    await p.getByRole("button", { name: "Thème clair" }).click();74    await p.waitForTimeout(400); // colour transitions of the theme switch75    await audit(p, "signin light");76    await ctx.close();77  });7879  for (const s of SCREENS) {80    test(`${s.name}`, async () => {81      await page.goto(s.path);82      await expect(page.getByTestId(s.testid)).toBeVisible();83      await settled(page);84      await audit(page, s.name);85    });86  }8788  test("settings → security, dialogs and the command palette", async () => {89    await page.goto("/settings/security");90    await expect(page.getByTestId("screen-settings-security")).toBeVisible();91    await settled(page);92    await audit(page, "settings/security");93    await page.goto("/settings/invitations");94    await page.getByTestId("invite-create").click();95    await page.waitForTimeout(350); // opening animation: colours are blended until it ends96    await audit(page, "invitation dialog");97    await page.keyboard.press("Escape");98    await page.keyboard.press("ControlOrMeta+k");99    await expect(page.getByTestId("palette-input")).toBeFocused();100    await page.waitForTimeout(350);101    await audit(page, "command palette");102    await page.keyboard.press("Escape");103  });104105  test("light theme: overview, nodes, maintenance, settings", async () => {106    await page.goto("/");107    await page.getByTestId("account-menu").click();108    await page.getByRole("menuitem", { name: "Thème clair" }).click();109    for (const s of SCREENS.filter((x) => ["overview", "nodes", "maintenance", "settings"].includes(x.name))) {110      await page.goto(s.path);111      await expect(page.getByTestId(s.testid)).toBeVisible();112      await settled(page);113      await audit(page, `${s.name} (light)`);114    }115    await page.getByTestId("account-menu").click();116    await page.getByRole("menuitem", { name: "Thème sombre" }).click();117  });118119  test("keyboard: skip link, focus is visible, dialogs trap and restore focus", async () => {120    await page.goto("/nodes");121    await expect(page.getByTestId("screen-nodes")).toBeVisible();122    await page.keyboard.press("Tab");123    await expect(page.getByRole("link", { name: "Aller au contenu" })).toBeFocused();124    await page.keyboard.press("Enter");125    await expect(page).toHaveURL(/#main$/);126    // focus ring: a focused control has a visible outline from the focus token127    const trigger = page.getByTestId("search-trigger");128    await trigger.focus();129    await page.keyboard.press("Shift+Tab");130    await page.keyboard.press("Tab");131    expect(await trigger.evaluate((el) => getComputedStyle(el).outlineStyle)).toBe("solid");132    // dialog: opens with focus inside, Esc closes and returns focus to the trigger133    await page.keyboard.press("Enter");134    await expect(page.getByTestId("palette-input")).toBeFocused();135    await page.keyboard.press("Escape");136    await expect(trigger).toBeFocused();137  });138139  test("no CSP violation and no console error", async () => {140    problems.assertClean();141  });142});143
Files main
Menu

Theme