source: frontend/node_modules/eslint-plugin-jsx-a11y/__tests__/src/util/isInteractiveElement-test.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.6 KB
Line 
1import test from 'tape';
2import { elementType } from 'jsx-ast-utils';
3
4import isInteractiveElement from '../../../src/util/isInteractiveElement';
5import JSXElementMock from '../../../__mocks__/JSXElementMock';
6import {
7 genElementSymbol,
8 genIndeterminantInteractiveElements,
9 genInteractiveElements,
10 genInteractiveRoleElements,
11 genNonInteractiveElements,
12 genNonInteractiveRoleElements,
13} from '../../../__mocks__/genInteractives';
14
15test('isInteractiveElement', (t) => {
16 t.equal(
17 isInteractiveElement(undefined, []),
18 false,
19 'identifies them as interactive elements',
20 );
21
22 t.test('interactive elements', (st) => {
23 genInteractiveElements().forEach(({ openingElement }) => {
24 st.equal(
25 isInteractiveElement(
26 elementType(openingElement),
27 openingElement.attributes,
28 ),
29 true,
30 `identifies \`${genElementSymbol(openingElement)}\` as an interactive element`,
31 );
32 });
33
34 st.end();
35 });
36
37 t.test('interactive role elements', (st) => {
38 genInteractiveRoleElements().forEach(({ openingElement }) => {
39 st.equal(
40 isInteractiveElement(
41 elementType(openingElement),
42 openingElement.attributes,
43 ),
44 false,
45 `identifies \`${genElementSymbol(openingElement)}\` as an interactive element`,
46 );
47 });
48
49 st.end();
50 });
51
52 t.test('non-interactive elements', (st) => {
53 genNonInteractiveElements().forEach(({ openingElement }) => {
54 st.equal(
55 isInteractiveElement(
56 elementType(openingElement),
57 openingElement.attributes,
58 ),
59 false,
60 `identifies \`${genElementSymbol(openingElement)}\` as an interactive element`,
61 );
62 });
63
64 st.end();
65 });
66
67 t.test('non-interactive role elements', (st) => {
68 genNonInteractiveRoleElements().forEach(({ openingElement }) => {
69 st.equal(
70 isInteractiveElement(
71 elementType(openingElement),
72 openingElement.attributes,
73 ),
74 false,
75 `identifies \`${genElementSymbol(openingElement)}\` as an interactive element`,
76 );
77 });
78
79 st.end();
80 });
81
82 t.test('indeterminate elements', (st) => {
83 genIndeterminantInteractiveElements().forEach(({ openingElement }) => {
84 st.equal(
85 isInteractiveElement(
86 elementType(openingElement),
87 openingElement.attributes,
88 ),
89 false,
90 `identifies \`${genElementSymbol(openingElement)}\` as an interactive element`,
91 );
92 });
93
94 st.end();
95 });
96
97 t.equal(
98 isInteractiveElement('CustomComponent', JSXElementMock()),
99 false,
100 'JSX elements are not interactive',
101 );
102
103 t.end();
104});
Note: See TracBrowser for help on using the repository browser.