generated from hmcts/expressjs-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
a11y.ts
48 lines (40 loc) · 1.36 KB
/
a11y.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-disable jest/no-done-callback,jest/expect-expect */
import { PageUrls } from '../../main/definitions/constants';
const pa11y = require('pa11y');
const envUrl = process.env.TEST_URL || 'http://localhost:3002';
const options = ['WCAG2AA.Principle1.Guideline1_3.1_3_1.H42.2'];
// Ignore pages that are passing in WAVE evaluation tool
const ignoredPages = ['/pension', '/pay', '/new-job-pay', '/compensation', PageUrls.CITIZEN_HUB];
class PallyIssue {
code: string;
context: string;
message: string;
selector: string;
type: string;
typeCode: number;
}
function expectNoErrors(messages: PallyIssue[]): void {
const errors = messages.filter(m => m.type === 'error');
if (errors.length > 0) {
const errorsAsJson = `${JSON.stringify(errors, null, 2)}`;
console.warn(`There are accessibility issues: \n${errorsAsJson}\n`);
}
}
function testAccessibility(url: string): void {
describe(`Page ${url}`, () => {
it('should have no accessibility errors', async () => {
if (!ignoredPages.includes(url)) {
const pageUrl = envUrl + url;
const messages = await pa11y(pageUrl, {
ignore: options,
});
expectNoErrors(messages.issues);
}
});
});
}
describe('Accessibility', () => {
Object.values({ ...PageUrls, CITIZEN_HUB: '/citizen-hub/a11y' }).forEach(url => {
testAccessibility(url);
});
});