source: frontend/node_modules/eslint-plugin-jsx-a11y/__tests__/src/rules/aria-activedescendant-has-tabindex-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.7 KB
Line 
1/**
2 * @fileoverview Enforce elements with aria-activedescendant are tabbable.
3 * @author Jesse Beach <@jessebeach>
4 */
5
6// -----------------------------------------------------------------------------
7// Requirements
8// -----------------------------------------------------------------------------
9
10import { RuleTester } from 'eslint';
11import parserOptionsMapper from '../../__util__/parserOptionsMapper';
12import parsers from '../../__util__/helpers/parsers';
13import rule from '../../../src/rules/aria-activedescendant-has-tabindex';
14
15// -----------------------------------------------------------------------------
16// Tests
17// -----------------------------------------------------------------------------
18
19const ruleTester = new RuleTester();
20
21const expectedError = {
22 message: 'An element that manages focus with `aria-activedescendant` must have a tabindex',
23 type: 'JSXOpeningElement',
24};
25
26ruleTester.run('aria-activedescendant-has-tabindex', rule, {
27 valid: parsers.all([].concat(
28 {
29 code: '<CustomComponent />;',
30 },
31 {
32 code: '<CustomComponent aria-activedescendant={someID} />;',
33 },
34 {
35 code: '<CustomComponent aria-activedescendant={someID} tabIndex={0} />;',
36 },
37 {
38 code: '<CustomComponent aria-activedescendant={someID} tabIndex={-1} />;',
39 },
40 {
41 code: '<CustomComponent aria-activedescendant={someID} tabIndex={0} />;',
42 settings: { 'jsx-a11y': { components: { CustomComponent: 'div' } } },
43 },
44 {
45 code: '<div />;',
46 },
47 {
48 code: '<input />;',
49 },
50 {
51 code: '<div tabIndex={0} />;',
52 },
53 {
54 code: '<div aria-activedescendant={someID} tabIndex={0} />;',
55 },
56 {
57 code: '<div aria-activedescendant={someID} tabIndex="0" />;',
58 },
59 {
60 code: '<div aria-activedescendant={someID} tabIndex={1} />;',
61 },
62 {
63 code: '<input aria-activedescendant={someID} />;',
64 },
65 {
66 code: '<input aria-activedescendant={someID} tabIndex={1} />;',
67 },
68 {
69 code: '<input aria-activedescendant={someID} tabIndex={0} />;',
70 },
71 {
72 code: '<input aria-activedescendant={someID} tabIndex={-1} />;',
73 },
74 {
75 code: '<div aria-activedescendant={someID} tabIndex={-1} />;',
76 },
77 {
78 code: '<div aria-activedescendant={someID} tabIndex="-1" />;',
79 },
80 {
81 code: '<input aria-activedescendant={someID} tabIndex={-1} />;',
82 },
83 )).map(parserOptionsMapper),
84 invalid: parsers.all([].concat(
85 {
86 code: '<div aria-activedescendant={someID} />;',
87 errors: [expectedError],
88 },
89 {
90 code: '<CustomComponent aria-activedescendant={someID} />;',
91 errors: [expectedError],
92 settings: { 'jsx-a11y': { components: { CustomComponent: 'div' } } },
93 },
94 )).map(parserOptionsMapper),
95});
Note: See TracBrowser for help on using the repository browser.