Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Added Cypress Axe.
Browse files Browse the repository at this point in the history
Fixes issue #20 using cypress axe.
Signed-off-by: Donald Labaj <[email protected]>
  • Loading branch information
dlabaj committed Dec 3, 2020
1 parent a4c0f81 commit 1c55d6a
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 8 deletions.
3 changes: 2 additions & 1 deletion client/Bootstrap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/>
</head>
<body>
<div id="root" role="main"></div>
<div id="root" class="root" role="main"></div>
<p tabindex=“0” aria-hidden=“true”>Some text</p>
</body>
</html>
1 change: 1 addition & 0 deletions e2e/features/step_definitions/coreUX.stepdef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Given('I am on the strimzi-ui homepage', () => {

Then(`the welcome message appears`, () => {
cy.get('#root').contains(`Welcome to the Strimzi UI`);
cy.testA11y("Checking accessibility for home page");
});

And(`version information about this UI is displayed`, () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ module.exports = (on: (evt: string, callback: () => void) => void) => {
const cucumberPreProcessor = cucumber.default;

on('file:preprocessor', cucumberPreProcessor(options));
};
};
54 changes: 54 additions & 0 deletions e2e/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,57 @@
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
import 'cypress-axe';
import { Result } from 'axe-core';

declare global {
namespace Cypress {
interface Chainable<Subject> {
logA11yViolations(violations: Result[], target: string): Chainable<Element>;
testA11y(target: string): Chainable<Element>;
}
}
}

Cypress.Commands.add(
'logA11yViolations',
(violations: Result[], target: string) => {
// pluck specific keys to keep the table readable
const violationData = violations.map(
({ id, impact, description, nodes }) => ({
id,
impact,
description,
nodes: nodes.length,
})
);
cy.log(
'Accessibility violation',
`${violations.length} accessibility violation${
violations.length === 1 ? '' : 's'
} ${violations.length === 1 ? 'was' : 'were'} detected ${
target ? `for ${target}` : ''
}`
);
cy.log('logTable', violationData);
}
);

Cypress.Commands.add('testA11y', (target: string) => {
cy.injectAxe();
cy.configureAxe({
rules: [
{ id: 'color-contrast', enabled: false }, // seem to be somewhat inaccurate and has difficulty always picking up the correct colors, tons of open issues for it on axe-core
{ id: 'focusable-content', enabled: false }, // recently updated and need to give the PF team time to fix issues before enabling
{ id: 'scrollable-region-focusable', enabled: false }, // recently updated and need to give the PF team time to fix issues before enabling
],
});
cy.checkA11y(
undefined,
{
includedImpacts: ['serious', 'critical'],
},
(violations) => cy.logA11yViolations(violations, target),
true
);
});
2 changes: 1 addition & 1 deletion e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"types": ["cypress", "node"]
"types": ["cypress", "cypress-axe", "node"]
},
"include": ["./**/*.ts"]
}
43 changes: 39 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@storybook/react": "^6.0.28",
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.1",
"@types/cypress-axe": "^0.8.0",
"@testing-library/react-hooks": "^3.4.2",
"@testing-library/user-event": "^12.2.2",
"@types/cypress-cucumber-preprocessor": "^4.0.0",
Expand All @@ -106,11 +107,13 @@
"@types/ws": "^7.2.7",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.6.1",
"axe-core": "^4.0.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"commitlint": "^11.0.0",
"css-loader": "^5.0.1",
"cypress": "^5.5.0",
"cypress": "^5.6.0",
"cypress-axe": "0.9.1",
"cypress-cucumber-preprocessor": "^4.0.0",
"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
Expand Down

0 comments on commit 1c55d6a

Please sign in to comment.