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:
1 parent
533a1c497d
commit
ba3a51e1b8
1 file changed
+34
-9
@@ -95,29 +95,49 @@ export { expect }
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Serious violations found before V1-1.3, outside its code, listed in TODO RR-7
|
* 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
|
* until their own fix: the scan lets through only the node that matches the
|
||||||
* other (WCAG 2.5.3 label in name, 1.3.1 info and relationships).
|
* 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',
|
id: 'label-content-name-mismatch',
|
||||||
target: /^button\[aria-label="(Passer en français|Switch to English)"\]$/,
|
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',
|
id: 'label-content-name-mismatch',
|
||||||
target: /^\.pr-1$/,
|
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 »',
|
note: 'AppLayout top bar account link: shows the display name, named « Mon compte » / « My account »',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'definition-list',
|
id: 'definition-list',
|
||||||
target: /^dl$/,
|
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',
|
note: 'DashboardRoute account card: the verified-status row is a div without dt/dd inside the dl',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const isKnown = (id: string, target: string) =>
|
const isKnown = (id: string, target: string, html: string, path: string) =>
|
||||||
KNOWN_VIOLATIONS.some((known) => known.id === id && known.target.test(target))
|
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
|
* 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',
|
'best-practice',
|
||||||
])
|
])
|
||||||
.analyze()
|
.analyze()
|
||||||
|
const path = new URL(page.url()).pathname
|
||||||
const blocking = violations
|
const blocking = violations
|
||||||
.filter((v) => v.impact === 'serious' || v.impact === 'critical')
|
.filter((v) => v.impact === 'serious' || v.impact === 'critical')
|
||||||
.flatMap((v) =>
|
.flatMap((v) =>
|
||||||
v.nodes
|
v.nodes
|
||||||
.map((node) => node.target.join(' '))
|
.filter(
|
||||||
.filter((target) => !isKnown(v.id, target))
|
(node) => !isKnown(v.id, node.target.join(' '), node.html, path),
|
||||||
.map((target) => `${v.impact} ${v.id}: ${v.help} → ${target}`),
|
)
|
||||||
|
.map(
|
||||||
|
(node) =>
|
||||||
|
`${v.impact} ${v.id}: ${v.help} → ${node.target.join(' ')} on ${path}`,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
expect(blocking, `axe on ${state}`).toEqual([])
|
expect(blocking, `axe on ${state}`).toEqual([])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user