isInteractiveElement-test.js
2.72 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* eslint-env mocha */
import expect from 'expect';
import { elementType } from 'jsx-ast-utils';
import isInteractiveElement from '../../../src/util/isInteractiveElement';
import JSXElementMock from '../../../__mocks__/JSXElementMock';
import {
genElementSymbol,
genIndeterminantInteractiveElements,
genInteractiveElements,
genInteractiveRoleElements,
genNonInteractiveElements,
genNonInteractiveRoleElements,
} from '../../../__mocks__/genInteractives';
describe('isInteractiveElement', () => {
describe('JSX Components (no tagName)', () => {
it('should identify them as interactive elements', () => {
expect(isInteractiveElement(undefined, []))
.toBe(false);
});
});
describe('interactive elements', () => {
genInteractiveElements().forEach(({ openingElement }) => {
it(`should identify \`${genElementSymbol(openingElement)}\` as an interactive element`, () => {
expect(isInteractiveElement(
elementType(openingElement),
openingElement.attributes,
)).toBe(true);
});
});
});
describe('interactive role elements', () => {
genInteractiveRoleElements().forEach(({ openingElement }) => {
it(`should NOT identify \`${genElementSymbol(openingElement)}\` as an interactive element`, () => {
expect(isInteractiveElement(
elementType(openingElement),
openingElement.attributes,
)).toBe(false);
});
});
});
describe('non-interactive elements', () => {
genNonInteractiveElements().forEach(({ openingElement }) => {
it(`should NOT identify \`${genElementSymbol(openingElement)}\` as an interactive element`, () => {
expect(isInteractiveElement(
elementType(openingElement),
openingElement.attributes,
)).toBe(false);
});
});
});
describe('non-interactive role elements', () => {
genNonInteractiveRoleElements().forEach(({ openingElement }) => {
it(`should NOT identify \`${genElementSymbol(openingElement)}\` as an interactive element`, () => {
expect(isInteractiveElement(
elementType(openingElement),
openingElement.attributes,
)).toBe(false);
});
});
});
describe('indeterminate elements', () => {
genIndeterminantInteractiveElements().forEach(({ openingElement }) => {
it(`should NOT identify \`${openingElement.name.name}\` as an interactive element`, () => {
expect(isInteractiveElement(
elementType(openingElement),
openingElement.attributes,
)).toBe(false);
});
});
});
describe('JSX elements', () => {
it('is not interactive', () => {
expect(isInteractiveElement('CustomComponent', JSXElementMock())).toBe(false);
});
});
});