Skip to content

Commit c0805ca

Browse files
authored
Add accessibility checks with axe-core to component tests (#9488)
1 parent efbf8da commit c0805ca

File tree

7 files changed

+57
-11
lines changed

7 files changed

+57
-11
lines changed

h/static/scripts/group-forms/components/EditGroupMembersForm.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ function RoleSelect({
158158
buttonContent={roleStrings[current]}
159159
data-testid={`role-${username}`}
160160
disabled={disabled}
161+
aria-label="Select role"
161162
>
162163
{available.map(role => (
163164
<Select.Option key={role} value={role}>

h/static/scripts/group-forms/components/forms/test/TextField-test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mount } from '@hypothesis/frontend-testing';
1+
import { checkAccessibility, mount } from '@hypothesis/frontend-testing';
22

33
import TextField from '../TextField';
44

@@ -78,4 +78,11 @@ describe('TextField', () => {
7878
'Must be 5 characters or more.',
7979
);
8080
});
81+
82+
it(
83+
'should pass a11y checks',
84+
checkAccessibility({
85+
content: () => mount(<TextField value="" label="Text field" />),
86+
}),
87+
);
8188
});

h/static/scripts/group-forms/components/test/AppRoot-test.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mount } from '@hypothesis/frontend-testing';
1+
import { checkAccessibility, mount } from '@hypothesis/frontend-testing';
22
import { useContext } from 'preact/hooks';
33

44
import { $imports, default as AppRoot } from '../AppRoot';
@@ -31,9 +31,13 @@ describe('AppRoot', () => {
3131
$imports.$restore();
3232
});
3333

34+
function createComponent() {
35+
return mount(<AppRoot config={config} />);
36+
}
37+
3438
it('renders style links', () => {
3539
config.styles = ['/static/styles/foo.css'];
36-
const links = mount(<AppRoot config={config} />).find('link');
40+
const links = createComponent().find('link');
3741
assert.equal(links.length, 1);
3842
assert.equal(links.at(0).prop('rel'), 'stylesheet');
3943
assert.equal(links.at(0).prop('href'), '/static/styles/foo.css');
@@ -51,14 +55,14 @@ describe('AppRoot', () => {
5155

5256
it('passes config to route', () => {
5357
navigate('/groups/new', () => {
54-
mount(<AppRoot config={config} />);
58+
createComponent();
5559
assert.strictEqual(configContext, config);
5660
});
5761
});
5862

5963
it('passes saved group to group settings route', () => {
6064
navigate('/groups/1234/edit', () => {
61-
const wrapper = mount(<AppRoot config={config} />);
65+
const wrapper = createComponent();
6266
assert.equal(
6367
wrapper.find('CreateEditGroupForm').prop('group'),
6468
config.context.group,
@@ -68,7 +72,7 @@ describe('AppRoot', () => {
6872

6973
it('passes updated group to group settings route', () => {
7074
navigate('/groups/1234/edit', () => {
71-
const wrapper = mount(<AppRoot config={config} />);
75+
const wrapper = createComponent();
7276
const updatedGroup = { name: 'foobar' };
7377
wrapper.find('CreateEditGroupForm').prop('onUpdateGroup')(updatedGroup);
7478
wrapper.update();
@@ -99,10 +103,15 @@ describe('AppRoot', () => {
99103
].forEach(({ path, selector }) => {
100104
it(`renders expected component for URL (${path})`, () => {
101105
navigate(path, () => {
102-
const wrapper = mount(<AppRoot config={config} />);
106+
const wrapper = createComponent();
103107
const component = wrapper.find(selector);
104108
assert.isTrue(component.exists());
105109
});
106110
});
107111
});
112+
113+
it(
114+
'should pass a11y checks',
115+
checkAccessibility({ content: createComponent }),
116+
);
108117
});

h/static/scripts/group-forms/components/test/CreateEditGroupForm-test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { act } from 'preact/test-utils';
2-
import { delay, mount, waitForElement } from '@hypothesis/frontend-testing';
2+
import {
3+
checkAccessibility,
4+
delay,
5+
mount,
6+
waitForElement,
7+
} from '@hypothesis/frontend-testing';
38

49
import {
510
$imports,
@@ -581,6 +586,11 @@ describe('CreateEditGroupForm', () => {
581586

582587
assert.equal(getSelectedGroupType(wrapper), 'private');
583588
});
589+
590+
it(
591+
'should pass a11y checks',
592+
checkAccessibility({ content: () => createWrapper().wrapper }),
593+
);
584594
});
585595

586596
async function assertInLoadingState(wrapper, inLoadingState) {

h/static/scripts/group-forms/components/test/EditGroupMembersForm-test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
checkAccessibility,
23
delay,
34
mount,
45
waitFor,
@@ -537,4 +538,11 @@ describe('EditGroupMembersForm', () => {
537538
assert.equal(bobRole.prop('value'), originalRole);
538539
assert.isFalse(controlsDisabled(wrapper, 'bob'));
539540
});
541+
542+
it('should pass a11y checks', async () => {
543+
const wrapper = createForm();
544+
await waitForTable(wrapper);
545+
546+
await checkAccessibility({ content: () => wrapper })();
547+
});
540548
});

h/static/scripts/group-forms/components/test/GroupFormHeader-test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mount } from '@hypothesis/frontend-testing';
1+
import { checkAccessibility, mount } from '@hypothesis/frontend-testing';
22

33
import GroupFormHeader from '../GroupFormHeader';
44

@@ -43,4 +43,6 @@ describe('GroupFormHeader', () => {
4343
assert.isFalse(getLink(header, 'settings-link').exists());
4444
assert.isFalse(getLink(header, 'members-link').exists());
4545
});
46+
47+
it('should pass a11y checks', checkAccessibility({ content: createHeader }));
4648
});

h/static/scripts/group-forms/components/test/SaveStateIcon-test.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { mount } from '@hypothesis/frontend-testing';
1+
import { checkAccessibility, mount } from '@hypothesis/frontend-testing';
22
import SaveStateIcon from '../SaveStateIcon';
33

44
describe('SaveStateIcon', () => {
5+
function createComponent(state) {
6+
return mount(<SaveStateIcon state={state} />);
7+
}
8+
59
[
610
{
711
state: 'unsaved',
@@ -20,9 +24,14 @@ describe('SaveStateIcon', () => {
2024
},
2125
].forEach(({ state, checkIcon, spinnerIcon }) => {
2226
it(`shows expected icons in "${state}" state`, () => {
23-
const wrapper = mount(<SaveStateIcon state={state} />);
27+
const wrapper = createComponent(state);
2428
assert.equal(wrapper.exists('CheckIcon'), checkIcon);
2529
assert.equal(wrapper.exists('SpinnerSpokesIcon'), spinnerIcon);
2630
});
31+
32+
it(
33+
'should pass a11y checks',
34+
checkAccessibility({ content: () => createComponent(state) }),
35+
);
2736
});
2837
});

0 commit comments

Comments
 (0)