2026-06-20 03:44:26 +08:00
|
|
|
/**
|
|
|
|
|
* Axe accessibility pass -- desktop (chromium project).
|
|
|
|
|
*
|
|
|
|
|
* Scoped set: home, one tool per modality, editor, settings, login.
|
|
|
|
|
* Runs in the default locale (en) and one RTL locale (ar).
|
|
|
|
|
*
|
2026-07-27 15:37:30 +08:00
|
|
|
* The release gate requires zero axe violations in the scoped pages.
|
2026-06-20 03:44:26 +08:00
|
|
|
*/
|
|
|
|
|
import AxeBuilder from "@axe-core/playwright";
|
2026-07-27 15:37:30 +08:00
|
|
|
import { DESKTOP_A11Y_PAGES } from "./a11y-routes.js";
|
|
|
|
|
import { expect, openSettings, test } from "./helpers";
|
2026-06-20 03:44:26 +08:00
|
|
|
|
|
|
|
|
interface ViolationEntry {
|
|
|
|
|
id: string;
|
|
|
|
|
impact: string | undefined;
|
|
|
|
|
description: string;
|
2026-07-18 12:56:48 +08:00
|
|
|
nodes: { target?: unknown[]; failureSummary?: string }[];
|
2026-06-20 03:44:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buildKey(pageKey: string, ruleId: string): string {
|
|
|
|
|
return `${pageKey}:${ruleId}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-07-27 15:37:30 +08:00
|
|
|
* Run axe on the current page and collect every violation. The caller gates
|
|
|
|
|
* on the complete result so moderate debt cannot silently become permanent.
|
2026-06-20 03:44:26 +08:00
|
|
|
*/
|
|
|
|
|
async function auditPage(
|
|
|
|
|
page: import("@playwright/test").Page,
|
|
|
|
|
pageKey: string,
|
2026-07-18 12:56:48 +08:00
|
|
|
allViolations: {
|
|
|
|
|
key: string;
|
|
|
|
|
impact: string;
|
|
|
|
|
description: string;
|
|
|
|
|
count: number;
|
|
|
|
|
targets: string[];
|
|
|
|
|
}[],
|
2026-06-20 03:44:26 +08:00
|
|
|
) {
|
|
|
|
|
const results = await new AxeBuilder({ page })
|
|
|
|
|
.withTags(["wcag2a", "wcag2aa", "best-practice"])
|
|
|
|
|
.analyze();
|
|
|
|
|
|
|
|
|
|
for (const v of results.violations as ViolationEntry[]) {
|
|
|
|
|
const key = buildKey(pageKey, v.id);
|
|
|
|
|
const entry = {
|
|
|
|
|
key,
|
|
|
|
|
impact: v.impact ?? "unknown",
|
|
|
|
|
description: v.description,
|
|
|
|
|
count: v.nodes.length,
|
2026-07-18 12:56:48 +08:00
|
|
|
targets: v.nodes.map((n) => (n.target ?? []).join(" ")),
|
2026-06-20 03:44:26 +08:00
|
|
|
};
|
|
|
|
|
allViolations.push(entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Tests ----
|
|
|
|
|
|
|
|
|
|
// Each test scans 9+ pages with axe; the default 30s timeout is tight.
|
|
|
|
|
test.describe("Axe a11y audit -- desktop EN", () => {
|
|
|
|
|
test.setTimeout(90_000);
|
2026-07-27 15:37:30 +08:00
|
|
|
test("has no accessibility violations on scoped pages", async ({
|
2026-06-20 03:44:26 +08:00
|
|
|
loggedInPage: page,
|
|
|
|
|
browser,
|
|
|
|
|
}) => {
|
|
|
|
|
const allViolations: { key: string; impact: string; description: string; count: number }[] = [];
|
|
|
|
|
|
2026-07-27 15:37:30 +08:00
|
|
|
for (const p of DESKTOP_A11Y_PAGES.en) {
|
2026-06-20 03:44:26 +08:00
|
|
|
if (p.needsAuth) {
|
|
|
|
|
await page.goto(p.path);
|
|
|
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
|
await page.waitForTimeout(500);
|
2026-07-27 15:37:30 +08:00
|
|
|
if (p.openSettings) await openSettings(page);
|
|
|
|
|
await auditPage(page, p.key, allViolations);
|
|
|
|
|
if (p.openSettings) await page.keyboard.press("Escape");
|
2026-06-20 03:44:26 +08:00
|
|
|
} else {
|
|
|
|
|
// Login page: use a fresh context without auth
|
|
|
|
|
const ctx = await browser.newContext({ storageState: { cookies: [], origins: [] } });
|
|
|
|
|
const anonPage = await ctx.newPage();
|
|
|
|
|
await anonPage.goto(p.path);
|
|
|
|
|
await anonPage.waitForLoadState("networkidle");
|
|
|
|
|
await anonPage.waitForTimeout(500);
|
2026-07-27 15:37:30 +08:00
|
|
|
await auditPage(anonPage, p.key, allViolations);
|
2026-06-20 03:44:26 +08:00
|
|
|
await ctx.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Report all violations by severity
|
|
|
|
|
const bySeverity: Record<string, number> = {};
|
|
|
|
|
for (const v of allViolations) {
|
|
|
|
|
bySeverity[v.impact] = (bySeverity[v.impact] || 0) + v.count;
|
|
|
|
|
}
|
|
|
|
|
console.log("a11y violation counts by severity (desktop EN):", JSON.stringify(bySeverity));
|
|
|
|
|
console.log(`total unique rules violated: ${allViolations.length}`);
|
|
|
|
|
|
|
|
|
|
expect(
|
2026-07-27 15:37:30 +08:00
|
|
|
allViolations,
|
|
|
|
|
`${allViolations.length} accessibility violation(s) found.\n` +
|
|
|
|
|
allViolations
|
2026-07-18 12:56:48 +08:00
|
|
|
.map(
|
|
|
|
|
(v) =>
|
|
|
|
|
` ${v.key} [${v.impact}]: ${v.description}\n${v.targets.map((t) => ` - ${t}`).join("\n")}`,
|
|
|
|
|
)
|
|
|
|
|
.join("\n"),
|
2026-06-20 03:44:26 +08:00
|
|
|
).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.describe("Axe a11y audit -- desktop AR (RTL)", () => {
|
|
|
|
|
test.setTimeout(60_000);
|
2026-07-27 15:37:30 +08:00
|
|
|
test("has no accessibility violations on RTL pages", async ({ loggedInPage: page, browser }) => {
|
2026-06-20 03:44:26 +08:00
|
|
|
const allViolations: { key: string; impact: string; description: string; count: number }[] = [];
|
|
|
|
|
|
2026-07-27 15:37:30 +08:00
|
|
|
for (const p of DESKTOP_A11Y_PAGES.ar) {
|
2026-06-20 03:44:26 +08:00
|
|
|
if (p.needsAuth) {
|
|
|
|
|
// Switch to Arabic locale
|
|
|
|
|
await page.evaluate(() => {
|
|
|
|
|
localStorage.setItem("snapotter-locale", "ar");
|
|
|
|
|
});
|
|
|
|
|
await page.goto(p.path);
|
|
|
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
|
await page.waitForTimeout(500);
|
2026-07-27 15:37:30 +08:00
|
|
|
if (p.openSettings) await openSettings(page);
|
|
|
|
|
await auditPage(page, p.key, allViolations);
|
|
|
|
|
if (p.openSettings) await page.keyboard.press("Escape");
|
2026-06-20 03:44:26 +08:00
|
|
|
} else {
|
|
|
|
|
const ctx = await browser.newContext({ storageState: { cookies: [], origins: [] } });
|
|
|
|
|
const anonPage = await ctx.newPage();
|
|
|
|
|
// Set Arabic locale before navigating
|
|
|
|
|
await anonPage.goto("/");
|
|
|
|
|
await anonPage.evaluate(() => {
|
|
|
|
|
localStorage.setItem("snapotter-locale", "ar");
|
|
|
|
|
});
|
|
|
|
|
await anonPage.goto(p.path);
|
|
|
|
|
await anonPage.waitForLoadState("networkidle");
|
|
|
|
|
await anonPage.waitForTimeout(500);
|
2026-07-27 15:37:30 +08:00
|
|
|
await auditPage(anonPage, p.key, allViolations);
|
2026-06-20 03:44:26 +08:00
|
|
|
await ctx.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset locale
|
|
|
|
|
await page.evaluate(() => {
|
|
|
|
|
localStorage.setItem("snapotter-locale", "en");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Report
|
|
|
|
|
const bySeverity: Record<string, number> = {};
|
|
|
|
|
for (const v of allViolations) {
|
|
|
|
|
bySeverity[v.impact] = (bySeverity[v.impact] || 0) + v.count;
|
|
|
|
|
}
|
|
|
|
|
console.log("a11y violation counts by severity (desktop AR):", JSON.stringify(bySeverity));
|
|
|
|
|
console.log(`total unique rules violated: ${allViolations.length}`);
|
|
|
|
|
expect(
|
2026-07-27 15:37:30 +08:00
|
|
|
allViolations,
|
|
|
|
|
`${allViolations.length} accessibility violation(s) in AR locale.\n` +
|
|
|
|
|
allViolations
|
2026-07-18 12:56:48 +08:00
|
|
|
.map(
|
|
|
|
|
(v) =>
|
|
|
|
|
` ${v.key} [${v.impact}]: ${v.description}\n${v.targets.map((t) => ` - ${t}`).join("\n")}`,
|
|
|
|
|
)
|
|
|
|
|
.join("\n"),
|
2026-06-20 03:44:26 +08:00
|
|
|
).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
});
|