2021-06-02 20:53:22 -04:00
|
|
|
// / <reference types="Cypress" />
|
|
|
|
|
2021-10-04 08:43:33 -07:00
|
|
|
/**
|
|
|
|
* The a11y check will use a cypress-axe library:
|
|
|
|
* - https://www.npmjs.com/package/cypress-axe
|
|
|
|
*
|
|
|
|
* This implements Deque's axe.run:
|
|
|
|
* - https://www.deque.com/axe/core-documentation/api-documentation/#api-name-axerun
|
|
|
|
*
|
|
|
|
* The table of rule descriptions that are seen in the terminal can be seen in totality here:
|
|
|
|
* - https://github.com/dequelabs/axe-core/blob/master/doc/rule-descriptions.md
|
|
|
|
*
|
|
|
|
*/
|
2021-06-02 20:53:22 -04:00
|
|
|
|
2022-04-07 13:14:54 -04:00
|
|
|
import {PAGES_ENDPOINTS} from './constants';
|
|
|
|
|
|
|
|
const rawEndpoints = Object.values(PAGES_ENDPOINTS);
|
|
|
|
|
|
|
|
const endpoints = rawEndpoints.map((endpoint) => `en${endpoint}`);
|
2021-10-04 08:43:33 -07:00
|
|
|
|
|
|
|
// The violation callback will post the violations into the terminal
|
2021-06-02 20:53:22 -04:00
|
|
|
// eslint-disable-next-line require-jsdoc
|
|
|
|
function terminalLog(violations) {
|
|
|
|
cy.task(
|
|
|
|
'log',
|
|
|
|
`${violations.length} accessibility violation${
|
|
|
|
violations.length === 1 ? '' : 's'
|
|
|
|
} ${violations.length === 1 ? 'was' : 'were'} detected`,
|
|
|
|
);
|
2021-10-04 08:43:33 -07:00
|
|
|
|
2021-06-02 20:53:22 -04:00
|
|
|
// pluck specific keys to keep the table readable
|
|
|
|
const violationData = violations.map(
|
2021-10-04 08:43:33 -07:00
|
|
|
// The results array is described here:
|
|
|
|
// - https://www.deque.com/axe/core-documentation/api-documentation/#result-arrays
|
|
|
|
// Unable to figure out how add the HTML element that the violation is occuring on. Using
|
|
|
|
// Axe chrome plugin instead.
|
|
|
|
({id, impact, description}) => ({
|
2021-06-02 20:53:22 -04:00
|
|
|
id,
|
|
|
|
impact,
|
|
|
|
description,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.task('table', violationData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-05 15:52:03 -04:00
|
|
|
describe('Do the accessibility checks pass on each page?', () => {
|
2021-10-04 08:43:33 -07:00
|
|
|
endpoints.forEach((endpoint) => {
|
2021-10-05 15:52:03 -04:00
|
|
|
it(`Check accessibility on ${endpoint} page`, () => {
|
2021-10-04 08:43:33 -07:00
|
|
|
cy.visit(endpoint).get('main').then(() => {
|
|
|
|
cy.injectAxe();
|
|
|
|
cy.checkA11y(null, null, terminalLog);
|
|
|
|
});
|
|
|
|
});
|
2021-06-02 20:53:22 -04:00
|
|
|
});
|
|
|
|
});
|