2026-06-20 03:44:26 +08:00
|
|
|
/**
|
|
|
|
|
* Axe accessibility pass -- mobile device (mobile-chromium project).
|
|
|
|
|
*
|
|
|
|
|
* Mirrors the desktop a11y spec's scoped set on a real device emulation
|
|
|
|
|
* (Pixel 7 via mobile-chromium). All tests tagged @mobile for project routing.
|
|
|
|
|
*
|
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 { MOBILE_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}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 ----
|
|
|
|
|
|
|
|
|
|
test.describe("@mobile Axe a11y audit -- mobile 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,
|
|
|
|
|
}) => {
|
2026-07-18 12:56:48 +08:00
|
|
|
const allViolations: {
|
|
|
|
|
key: string;
|
|
|
|
|
impact: string;
|
|
|
|
|
description: string;
|
|
|
|
|
count: number;
|
|
|
|
|
targets: string[];
|
|
|
|
|
}[] = [];
|
2026-06-20 03:44:26 +08:00
|
|
|
|
2026-07-27 15:37:30 +08:00
|
|
|
for (const p of MOBILE_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 {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 (mobile 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) on mobile.\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("@mobile Axe a11y audit -- mobile AR (RTL)", () => {
|
|
|
|
|
test.setTimeout(60_000);
|
2026-07-27 15:37:30 +08:00
|
|
|
test("has no accessibility violations on RTL mobile pages", async ({
|
2026-06-20 03:44:26 +08:00
|
|
|
loggedInPage: page,
|
|
|
|
|
browser,
|
|
|
|
|
}) => {
|
2026-07-18 12:56:48 +08:00
|
|
|
const allViolations: {
|
|
|
|
|
key: string;
|
|
|
|
|
impact: string;
|
|
|
|
|
description: string;
|
|
|
|
|
count: number;
|
|
|
|
|
targets: string[];
|
|
|
|
|
}[] = [];
|
2026-06-20 03:44:26 +08:00
|
|
|
|
2026-07-27 15:37:30 +08:00
|
|
|
for (const p of MOBILE_A11Y_PAGES.ar) {
|
2026-06-20 03:44:26 +08:00
|
|
|
if (p.needsAuth) {
|
|
|
|
|
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();
|
|
|
|
|
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");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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 (mobile AR):", JSON.stringify(bySeverity));
|
|
|
|
|
expect(
|
2026-07-27 15:37:30 +08:00
|
|
|
allViolations,
|
|
|
|
|
`${allViolations.length} accessibility violation(s) on mobile AR.\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);
|
|
|
|
|
});
|
|
|
|
|
});
|