Skip to content

Commit

Permalink
test(Link): add RTL, add a11y tests, add Accessibility Checker/Axe (#…
Browse files Browse the repository at this point in the history
…7284)

* test(Link): add RTL, add a11y tests, add AC

* Update packages/react/src/components/Link/Link-test.js

Co-authored-by: Josh Black <[email protected]>

* Update packages/react/src/components/Link/Link-test.js

Co-authored-by: Josh Black <[email protected]>

* test(Link): change import style/use RTL cleanup

* test(Link): change import style/use RTL cleanup

Co-authored-by: Josh Black <[email protected]>
Co-authored-by: TJ Egan <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2020
1 parent 5f92371 commit 1253a6c
Show file tree
Hide file tree
Showing 52 changed files with 487 additions and 6 deletions.
Binary file added .yarn/offline-mirror/@babel-runtime-7.12.5.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@jest-types-26.6.2.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-aria-query-4.2.0.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-jest-26.0.15.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-yauzl-2.9.1.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/agent-base-5.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/aria-query-4.2.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/axios-0.19.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/base64-js-1.5.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/bl-4.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/buffer-5.7.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/buffer-crc32-0.2.13.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/chromedriver-83.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/css-3.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/css.escape-1.5.1.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/diff-sequences-26.6.2.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/extract-zip-2.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/fd-slicer-1.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/get-stream-5.2.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/https-proxy-agent-4.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/ieee754-1.2.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-diff-26.6.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-get-type-26.3.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/lz-string-1.4.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/mkdirp-1.0.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/mkdirp-classic-0.5.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/node-fetch-2.6.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pretty-format-26.6.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/puppeteer-5.4.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/readable-stream-3.6.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/source-map-resolve-0.6.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/tar-fs-2.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/tar-stream-2.1.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/unbzip2-stream-1.4.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/yauzl-2.10.0.tgz
Binary file not shown.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@ibma/aat": "https://able.ibm.com/tools/dist/ibma-aat-2.0.6.tgz",
"@testing-library/dom": "^7.26.6",
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.1",
"@testing-library/user-event": "^12.2.0",
"accessibility-checker": "^3.1.1",
"all-contributors-cli": "^6.19.0",
"axe-core": "^3.3.2",
"babel-jest": "^26.0.1",
Expand Down
57 changes: 57 additions & 0 deletions packages/react/src/components/Link/Link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ import React from 'react';
import Link from '../Link';
import { shallow } from 'enzyme';
import { settings } from 'carbon-components';
import { cleanup, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import { describe, document } from 'window-or-global';

const { prefix } = settings;

describe('Link', () => {
afterEach(cleanup);

describe('Renders as expected', () => {
const link = shallow(
<Link href="www.google.com" className="some-class">
Expand Down Expand Up @@ -56,4 +62,55 @@ describe('Link', () => {
expect(link.props().rel).toEqual('noopener');
});
});

describe('automated verification testing', () => {
it('should have no Axe violations', async () => {
render(
<Link href="/" className="some-class">
A simple link
</Link>
);

await expect(screen.getByText('A simple link')).toHaveNoAxeViolations();
});

it('should have no Accessibility Checker violations', async () => {
render(
<main>
<Link href="/" className="some-class">
A simple link
</Link>
</main>
);

await expect(screen.getByText('A simple link')).toHaveNoACViolations(
'Link'
);
});
});

describe('keyboard support', () => {
it('should recieve keyboard focus', () => {
render(
<Link href="/" className="some-class">
A simple link
</Link>
);

expect(document.body).toHaveFocus();
userEvent.tab();
expect(screen.getByText('A simple link')).toHaveFocus();
});

it('should not receive keyboard focus when disabled', () => {
render(
<Link href="/" disabled className="some-class">
A simple link
</Link>
);
expect(document.body).toHaveFocus();
userEvent.tab();
expect(document.body).toHaveFocus();
});
});
});
32 changes: 32 additions & 0 deletions packages/react/src/components/Link/link-avt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Link Component Accessibility Verification Testing

Developers or designers wanting to manually verify the accessibility of the
component can carry out the following steps:

## Keyboard

- [ ] the user can focus the link with `tab`
- [ ] the user can activate the link with `enter`

## Contrast

- [ ] the link text has a contrast of 4.5:1 minimum against the background color
- [ ] the link focus outline has a contrast of 4.5:1 minimum against the
background color

## Screen reader

Each screen reader should be tested when paired with it's preferred browser.

### VoiceOver on Safari

"{link text}, link. You are currently on a link. To click this link, press
Control-Option-Space."

### JAWS on Edge/Chrome

"Main region. {link text}, link."

### NVDA on Firefox (optional, but recommended)

"link {link text}"
19 changes: 19 additions & 0 deletions tasks/jest/matchers/toHaveNoACViolations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const aChecker = require('accessibility-checker');

async function toHaveNoACViolations(node, label) {
let results = await aChecker.getCompliance(node, label);
if (aChecker.assertCompliance(results.report) === 0) {
return {
pass: true,
};
} else {
return {
pass: false,
message: () => aChecker.stringifyResults(results.report),
};
}
}

module.exports = toHaveNoACViolations;
7 changes: 6 additions & 1 deletion tasks/jest/setupAfterEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const chalk = require('chalk');
const util = require('util');
const toHaveNoAxeViolations = require('./matchers/toHaveNoAxeViolations');
const toHaveNoDAPViolations = require('./matchers/toHaveNoDAPViolations');
const toHaveNoACViolations = require('./matchers/toHaveNoACViolations');

// We can extend `expect` using custom matchers as defined by:
// https://jest-bot.github.io/jest/docs/expect.html#expectextendmatchers
Expand All @@ -21,7 +22,11 @@ const toHaveNoDAPViolations = require('./matchers/toHaveNoDAPViolations');
//
// For more information, check out the docs here:
// https://jestjs.io/docs/en/configuration.html#setupfilesafterenv-array
expect.extend({ toHaveNoAxeViolations, toHaveNoDAPViolations });
expect.extend({
toHaveNoAxeViolations,
toHaveNoDAPViolations,
toHaveNoACViolations,
});

// Have our test suite throw an error if one of the below console methods are
// called when we are not expecting them. This is often helpful for React
Expand Down
Loading

0 comments on commit 1253a6c

Please sign in to comment.