-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cypress a11y: expanded coverage, improved reporting
- Loading branch information
1 parent
b6ffd5a
commit 4d3cafb
Showing
8 changed files
with
154 additions
and
86 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
60 changes: 60 additions & 0 deletions
60
frontend/packages/integration-tests-cypress/support/a11y.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'cypress-jest-adapter'; | ||
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>; | ||
} | ||
} | ||
} | ||
|
||
export const a11yTestResults: a11yTestResultsType = { | ||
numberViolations: 0, | ||
numberChecks: 0, | ||
}; | ||
|
||
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, | ||
})); | ||
a11yTestResults.numberViolations += violations.length; | ||
cy.task( | ||
'log', | ||
`${violations.length} accessibility violation${violations.length === 1 ? '' : 's'} ${ | ||
violations.length === 1 ? 'was' : 'were' | ||
} detected ${target ? `for ${target}` : ''}`, | ||
); | ||
cy.task('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 | ||
], | ||
}); | ||
a11yTestResults.numberChecks += 1; | ||
cy.checkA11y( | ||
null, | ||
{ | ||
includedImpacts: ['serious', 'critical'], | ||
}, | ||
(violations) => cy.logA11yViolations(violations, target), | ||
true, | ||
); | ||
}); | ||
|
||
type a11yTestResultsType = { | ||
numberViolations: number; | ||
numberChecks: number; | ||
}; |
This file contains 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
This file contains 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
54 changes: 54 additions & 0 deletions
54
frontend/packages/integration-tests-cypress/tests/crud/other-routes.spec.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { checkErrors } from '../../support'; | ||
|
||
describe('Visiting other routes', () => { | ||
before(() => { | ||
cy.login(); | ||
}); | ||
|
||
afterEach(() => { | ||
checkErrors(); | ||
}); | ||
|
||
after(() => { | ||
cy.logout(); | ||
}); | ||
|
||
const otherRoutes = [ | ||
'/', | ||
'/k8s/cluster/clusterroles/view', | ||
'/k8s/cluster/nodes', | ||
'/k8s/all-namespaces/events', | ||
'/k8s/all-namespaces/import', | ||
'/api-explorer', | ||
'/api-resource/ns/default/core~v1~Pod', | ||
'/api-resource/ns/default/core~v1~Pod/schema', | ||
'/api-resource/ns/default/core~v1~Pod/instances', | ||
...(Cypress.env('openshift') === true | ||
? [ | ||
'/api-resource/ns/default/core~v1~Pod/access', | ||
'/k8s/cluster/user.openshift.io~v1~User', | ||
'/k8s/ns/openshift-machine-api/machine.openshift.io~v1beta1~Machine', | ||
'/k8s/ns/openshift-machine-api/machine.openshift.io~v1beta1~MachineSet', | ||
'/k8s/ns/openshift-machine-api/autoscaling.openshift.io~v1beta1~MachineAutoscaler', | ||
'/k8s/ns/openshift-machine-api/machine.openshift.io~v1beta1~MachineHealthCheck', | ||
'/k8s/cluster/machineconfiguration.openshift.io~v1~MachineConfig', | ||
'/k8s/cluster/machineconfiguration.openshift.io~v1~MachineConfigPool', | ||
'/k8s/all-namespaces/monitoring.coreos.com~v1~Alertmanager', | ||
'/k8s/ns/openshift-monitoring/monitoring.coreos.com~v1~Alertmanager/main', | ||
'/settings/cluster', | ||
'/monitoring/query-browser', | ||
// Test loading search page for a kind with no static model. | ||
'/search/all-namespaces?kind=config.openshift.io~v1~Console', | ||
] | ||
: []), | ||
]; | ||
otherRoutes.forEach((route) => { | ||
it(`successfully displays view for route: ${route}`, () => { | ||
cy.visit(`${route}`); | ||
// eslint-disable-next-line cypress/no-unnecessary-waiting | ||
cy.wait(5000); // wait for page to load | ||
cy.byLegacyTestID('error-page').should('not.be.visible'); | ||
cy.testA11y(`${route} page`); | ||
}); | ||
}); | ||
}); |
This file contains 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