Skip to content

Commit c348f59

Browse files
shethjalexvuong
andauthored
A11y tests - Handle dynamic aria labels generated by chakra UI (#2864)
* Handle dynamic aria labels generated by chakra UI * improve sanitization --------- Co-authored-by: Alex Vuong <alex.vuong@salesforce.com>
1 parent 373decf commit c348f59

21 files changed

+49
-38
lines changed

e2e/scripts/utils.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ const getCreditCardExpiry = (yearsFromNow = 5) => {
4242
*/
4343
function simplifyViolations(violations) {
4444
return violations.map((violation) => ({
45-
id: violation.id, // Rule ID
46-
impact: violation.impact, // Impact (critical, serious, moderate, minor)
47-
description: violation.description, // Description of the rule
48-
help: violation.help, // Short description
45+
id: violation.id,
46+
// Severity of violation (critical, serious, moderate, minor)
47+
impact: violation.impact,
48+
description: violation.description,
49+
help: violation.help,
4950
helpUrl: violation.helpUrl,
5051
nodes: violation.nodes.map((node) => ({
5152
// Simplify the HTML to make it more stable for snapshots
@@ -54,7 +55,13 @@ function simplifyViolations(violations) {
5455
failureSummary: node.failureSummary,
5556
// Simplify target selectors for stability
5657
// #app-header[data-v-12345] > .navigation[data-testid="main-nav"] => #app-header > .navigation
57-
target: node.target.map((t) => t.split(/\[.*?\]/).join(''))
58+
// Also handle Chakra UI dynamic selectors like #popover-trigger-:r5l4v:
59+
target: node.target.map((t) =>
60+
t
61+
.split(/\[.*?\]/).join('') // Remove data attributes
62+
.replace(/#([^-\s]+(?:-[^:]*)?):([^"\s]*)/g, '#$1-...') // Remove Chakra UI dynamic IDs
63+
.replace(/\.css-[a-zA-Z0-9]+/g, '.css-...') // Simplify Chakra UI CSS classes
64+
)
5865
}))
5966
}))
6067
}
@@ -77,6 +84,10 @@ function sanitizeHtml(html) {
7784
.replace(/style="[^"]*"/g, '')
7885
// Remove content of script tags
7986
.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi, '<script>...</script>')
87+
// Dynamic values - keep stable part:
88+
// Before: aria-controls="popover-content-:rn:"
89+
// After: aria-controls="popover-content-..."
90+
.replace(/(aria-(?:controls|describedby|labelledby|owns))="([^:]*?)(?::[^"]*)?"/g, '$1="$2..."')
8091
// Trim whitespace
8192
.trim()
8293
)

e2e/tests/a11y/desktop/__snapshots__/guest/cart-a11y-violations.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"helpUrl": "https://dequeuniversity.com/rules/axe/4.10/aria-allowed-attr?application=playwright",
88
"nodes": [
99
{
10-
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-:rh:\">",
10+
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-...\">",
1111
"failureSummary": "Fix all of the following:\n ARIA attribute is not allowed: aria-expanded=\"false\"",
1212
"target": [
13-
"#popover-trigger-\\:rh\\:"
13+
"#popover-trigger-\\-..."
1414
]
1515
}
1616
]

e2e/tests/a11y/desktop/__snapshots__/guest/checkout-a11y-violations-step-0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"html": "<a class=\"...\" aria-label=\"Back to cart, number of items: 2\" href=\"/cart\">",
2727
"failureSummary": "Fix any of the following:\n Some page content is not contained by landmarks",
2828
"target": [
29-
".css-1k2aozt"
29+
".css-..."
3030
]
3131
}
3232
]

e2e/tests/a11y/desktop/__snapshots__/guest/checkout-a11y-violations-step-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"html": "<a class=\"...\" aria-label=\"Back to cart, number of items: 2\" href=\"/cart\">",
2727
"failureSummary": "Fix any of the following:\n Some page content is not contained by landmarks",
2828
"target": [
29-
".css-1k2aozt"
29+
".css-..."
3030
]
3131
}
3232
]

e2e/tests/a11y/desktop/__snapshots__/guest/checkout-a11y-violations-step-2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"html": "<a class=\"...\" aria-label=\"Back to cart, number of items: 2\" href=\"/cart\">",
2727
"failureSummary": "Fix any of the following:\n Some page content is not contained by landmarks",
2828
"target": [
29-
".css-1k2aozt"
29+
".css-..."
3030
]
3131
}
3232
]

e2e/tests/a11y/desktop/__snapshots__/guest/checkout-a11y-violations-step-3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"html": "<a class=\"...\" aria-label=\"Back to cart, number of items: 2\" href=\"/cart\">",
2727
"failureSummary": "Fix any of the following:\n Some page content is not contained by landmarks",
2828
"target": [
29-
".css-1k2aozt"
29+
".css-..."
3030
]
3131
}
3232
]

e2e/tests/a11y/desktop/__snapshots__/guest/checkout-a11y-violations-step-4-order-confirmation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"html": "<a class=\"...\" aria-label=\"Back to cart, number of items: 2\" href=\"/cart\">",
2727
"failureSummary": "Fix any of the following:\n Some page content is not contained by landmarks",
2828
"target": [
29-
".css-1k2aozt"
29+
".css-..."
3030
]
3131
}
3232
]

e2e/tests/a11y/desktop/__snapshots__/guest/homepage-a11y-violations.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"helpUrl": "https://dequeuniversity.com/rules/axe/4.10/aria-allowed-attr?application=playwright",
88
"nodes": [
99
{
10-
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-:rh:\">",
10+
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-...\">",
1111
"failureSummary": "Fix all of the following:\n ARIA attribute is not allowed: aria-expanded=\"false\"",
1212
"target": [
13-
"#popover-trigger-\\:rh\\:"
13+
"#popover-trigger-\\-..."
1414
]
1515
}
1616
]

e2e/tests/a11y/desktop/__snapshots__/guest/pdp-a11y-violations.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"helpUrl": "https://dequeuniversity.com/rules/axe/4.10/aria-allowed-attr?application=playwright",
88
"nodes": [
99
{
10-
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-:rh:\">",
10+
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-...\">",
1111
"failureSummary": "Fix all of the following:\n ARIA attribute is not allowed: aria-expanded=\"false\"",
1212
"target": [
13-
"#popover-trigger-\\:rh\\:"
13+
"#popover-trigger-\\-..."
1414
]
1515
}
1616
]

e2e/tests/a11y/desktop/__snapshots__/guest/plp-a11y-violations.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"helpUrl": "https://dequeuniversity.com/rules/axe/4.10/aria-allowed-attr?application=playwright",
88
"nodes": [
99
{
10-
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-:rh:\">",
10+
"html": "<form id=\"...\" aria-haspopup=\"dialog\" aria-expanded=\"false\" aria-controls=\"popover-content-...\">",
1111
"failureSummary": "Fix all of the following:\n ARIA attribute is not allowed: aria-expanded=\"false\"",
1212
"target": [
13-
"#popover-trigger-\\:rh\\:"
13+
"#popover-trigger-\\-..."
1414
]
1515
}
1616
]

0 commit comments

Comments
 (0)