test(app): scope known axe exceptions to their markup and route

Each pre-existing exception (RR-7) now matches the axe rule, the selector,
the element's opening markup and its route; a new screen or element never
inherits one. Failure lines name the route.
This commit is contained in:
bchanot committed 2026-10-26 01:02:54 +01:00
1 parent 533a1c497d
commit ba3a51e1b8
1 file changed
+34 -9
+34 -9
View File
@@ -95,29 +95,49 @@ export { expect }
/**
* Serious violations found before V1-1.3, outside its code, listed in TODO RR-7
* until their own fix: the scan lets these exact nodes through and fails on any
* other (WCAG 2.5.3 label in name, 1.3.1 info and relationships).
* until their own fix: the scan lets through only the node that matches the
* rule, the selector, the opening markup and the route of each entry, and fails
* on any other, so a new screen or a new element never inherits an exception
* (WCAG 2.5.3 label in name, 1.3.1 info and relationships).
*/
const KNOWN_VIOLATIONS: { id: string; target: RegExp; note: string }[] = [
const KNOWN_VIOLATIONS: {
id: string
target: RegExp
html: RegExp
path: RegExp
note: string
}[] = [
{
id: 'label-content-name-mismatch',
target: /^button\[aria-label="(Passer en français|Switch to English)"\]$/,
note: 'LanguageSwitcher: shows « FR » / « EN », named « Passer en français » / « Switch to English »',
html: /^<button [^>]*aria-label="(Passer en français|Switch to English)"/,
path: /^\//,
note: 'LanguageSwitcher (every page): shows « FR » / « EN », named « Passer en français » / « Switch to English »',
},
{
id: 'label-content-name-mismatch',
target: /^\.pr-1$/,
html: /^<a [^>]*href="\/app\/account"/,
path: /^\/app(\/|$)/,
note: 'AppLayout top bar account link: shows the display name, named « Mon compte » / « My account »',
},
{
id: 'definition-list',
target: /^dl$/,
html: /^<dl class="grid gap-2 text-sm">/,
path: /^\/app\/?$/,
note: 'DashboardRoute account card: the verified-status row is a div without dt/dd inside the dl',
},
]
const isKnown = (id: string, target: string) =>
KNOWN_VIOLATIONS.some((known) => known.id === id && known.target.test(target))
const isKnown = (id: string, target: string, html: string, path: string) =>
KNOWN_VIOLATIONS.some(
(known) =>
known.id === id &&
known.target.test(target) &&
known.html.test(html) &&
known.path.test(path),
)
/**
* Zero serious or critical axe violation on the page as it stands (WCAG 2.0 to
@@ -144,13 +164,18 @@ export async function expectAccessible(
'best-practice',
])
.analyze()
const path = new URL(page.url()).pathname
const blocking = violations
.filter((v) => v.impact === 'serious' || v.impact === 'critical')
.flatMap((v) =>
v.nodes
.map((node) => node.target.join(' '))
.filter((target) => !isKnown(v.id, target))
.map((target) => `${v.impact} ${v.id}: ${v.help} → ${target}`),
.filter(
(node) => !isKnown(v.id, node.target.join(' '), node.html, path),
)
.map(
(node) =>
`${v.impact} ${v.id}: ${v.help} → ${node.target.join(' ')} on ${path}`,
),
)
expect(blocking, `axe on ${state}`).toEqual([])
}