test(mwpw-1234): add jest‐axe accessibility testing, container unit tests, and component a11y fixes#287
Open
raissanjay wants to merge 16 commits into
Open
test(mwpw-1234): add jest‐axe accessibility testing, container unit tests, and component a11y fixes#287raissanjay wants to merge 16 commits into
raissanjay wants to merge 16 commits into
Conversation
Core Web Vitals Metrics
Recorded at: 2025-06-03T23:42:30.145Z |
Core Web Vitals Metrics
Recorded at: 2025-06-03T23:46:23.231Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T03:08:19.633Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T04:42:23.797Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T04:44:06.321Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T04:45:22.787Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T05:32:11.091Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T05:51:00.021Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T06:04:52.422Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T07:06:48.527Z |
Core Web Vitals Metrics
Recorded at: 2025-06-04T07:20:38.712Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a unit-level accessibility testing framework using jest-axe, adds new a11y tests for the Container component (covering multiple API states), and fixes several accessibility gaps in existing components. Below is a summary of the changes:
1. Accessibility Test Setup
jest-axe-setup.js
Registers the
toHaveNoViolations()matcher from jest-axe, so we can assert that rendered DOM snapshots have zero a11y violations:jest.a11y.config.js
A specialized Jest config that:
*.a11y.test.js(x)files onlyUpdates to jest.config.js
Added
jest-axe-setup.jsundersetupTestFrameworkScriptFileso thatexpect(...).toHaveNoViolations()is available globally:module.exports = { // … moduleFileExtensions: ['js', 'json', 'jsx'], - setupFiles: ['<rootDir>/enzyme.config.js'], + setupFiles: ['<rootDir>/enzyme.config.js'], + setupTestFrameworkScriptFile: '<rootDir>/jest-axe-setup.js', testEnvironment: 'jest-environment-jsdom-fifteen', // … };package.json modifications
Added
react-axe,axe-core, andjest-axeto devDependencies.Introduced a new npm script to run only accessibility tests:
"scripts": { "test:unit": "jest", + "test:a11y": "jest --config=jest.a11y.config.js", }Now, running
npm run test:a11yexecutes only files matching*.a11y.test.js(x)and skips coverage.2. New Container a11y Tests
File:
react/src/js/components/Consonant/Container/Container.a11y.test.jsxCovers three API-driven states for the Container component, mocking fetch and using waitFor to ensure the DOM is updated before running
axe(container):Why this matters:
3. Component Accessibility Fixes
Card.jsx heading level logic
Ensures
headingLevelis always a valid number (defaults to 2 if invalid), preventing invalid aria-level values:PanelFooter.jsx (mobile filters)
Added an
aria-labelon the "Done" button so screen readers announce it correctly:Title.jsx (mobile filter header)
Added an explicit
aria-label="Back"on the back-button element so assistive technologies know its purpose:4. Why These Changes Matter
Unit-level a11y coverage with jest-axe
axe(container)in JSDOM gives immediate feedback on missing alt text, improper ARIA roles, focus-order issues, and color-contrast failures (to the extent JSDOM can evaluate them).waitFor, we test dynamic states—for example, opening a filters panel or handling empty/error responses—without launching a full browser.Component-level fixes
aria-label, validaria-level, etc.) reduces the chance of keyboard/navigation or screen-reader issues.headingLevelprevents rendering invalidaria-levelattributes.CI integration
npm run test:a11ycommand runs only a11y tests (matching*.a11y.test.js(x)), so our CI can block merges if any accessibility violations occur.5. Next Steps
Extend coverage as new components are built
Follow the same pattern (render parent, fire events, wait for dynamic DOM changes,
await axe(container)).Consider full-browser audits later
For screenshots, color-contrast based on compiled CSS, and real focus-navigation tests, we can add an AxePuppeteer or Pa11y job against our staging environment in a separate PR.
Summary
This PR:
test:a11yfor CI to verify no regressions in accessibilityPlease review and approve so we can catch a11y issues automatically on every merge.