| 1 | import test from 'tape';
|
|---|
| 2 | import { elementType } from 'jsx-ast-utils';
|
|---|
| 3 |
|
|---|
| 4 | import isInteractiveRole from '../../../src/util/isInteractiveRole';
|
|---|
| 5 | import {
|
|---|
| 6 | genElementSymbol,
|
|---|
| 7 | genInteractiveRoleElements,
|
|---|
| 8 | genNonInteractiveRoleElements,
|
|---|
| 9 | } from '../../../__mocks__/genInteractives';
|
|---|
| 10 |
|
|---|
| 11 | test('isInteractiveRole', (t) => {
|
|---|
| 12 | t.equal(
|
|---|
| 13 | isInteractiveRole(undefined, []),
|
|---|
| 14 | false,
|
|---|
| 15 | 'identifies JSX Components (no tagName) as interactive role elements',
|
|---|
| 16 | );
|
|---|
| 17 |
|
|---|
| 18 | t.test('elements with a non-interactive role', (st) => {
|
|---|
| 19 | genNonInteractiveRoleElements().forEach(({ openingElement }) => {
|
|---|
| 20 | const { attributes } = openingElement;
|
|---|
| 21 |
|
|---|
| 22 | st.equal(
|
|---|
| 23 | isInteractiveRole(
|
|---|
| 24 | elementType(openingElement),
|
|---|
| 25 | attributes,
|
|---|
| 26 | ),
|
|---|
| 27 | false,
|
|---|
| 28 | `does NOT identify \`${genElementSymbol(openingElement)}\` as an interactive role element`,
|
|---|
| 29 | );
|
|---|
| 30 | });
|
|---|
| 31 |
|
|---|
| 32 | st.end();
|
|---|
| 33 | });
|
|---|
| 34 |
|
|---|
| 35 | t.equal(
|
|---|
| 36 | isInteractiveRole('div', []),
|
|---|
| 37 | false,
|
|---|
| 38 | 'does NOT identify elements without a role as interactive role elements',
|
|---|
| 39 | );
|
|---|
| 40 |
|
|---|
| 41 | t.test('elements with an interactive role', (st) => {
|
|---|
| 42 | genInteractiveRoleElements().forEach(({ openingElement }) => {
|
|---|
| 43 | const { attributes } = openingElement;
|
|---|
| 44 |
|
|---|
| 45 | st.equal(
|
|---|
| 46 | isInteractiveRole(
|
|---|
| 47 | elementType(openingElement),
|
|---|
| 48 | attributes,
|
|---|
| 49 | ),
|
|---|
| 50 | true,
|
|---|
| 51 | `identifies \`${genElementSymbol(openingElement)}\` as an interactive role element`,
|
|---|
| 52 | );
|
|---|
| 53 | });
|
|---|
| 54 |
|
|---|
| 55 | st.end();
|
|---|
| 56 | });
|
|---|
| 57 |
|
|---|
| 58 | t.end();
|
|---|
| 59 | });
|
|---|