@@ -2,6 +2,7 @@ describe('aria-required-children', function () {
2
2
'use strict' ;
3
3
4
4
var fixture = document . getElementById ( 'fixture' ) ;
5
+ var shadowSupported = axe . testUtils . shadowSupport . v1 ;
5
6
6
7
var checkContext = {
7
8
_data : null ,
@@ -10,97 +11,141 @@ describe('aria-required-children', function () {
10
11
}
11
12
} ;
12
13
14
+ function checkSetup ( html , options , target ) {
15
+ fixture . innerHTML = html ;
16
+ axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
17
+ var node = fixture . querySelector ( target || '#target' ) ;
18
+ var virtualNode = axe . utils . getNodeFromTree ( axe . _tree [ 0 ] , node ) ;
19
+ return [ node , options , virtualNode ] ;
20
+ }
21
+
13
22
afterEach ( function ( ) {
14
23
fixture . innerHTML = '' ;
24
+ axe . _tree = undefined ;
15
25
checkContext . _data = null ;
16
26
} ) ;
17
27
18
28
it ( 'should detect missing sole required child' , function ( ) {
19
- fixture . innerHTML = '<div role="list" id="target"><p>Nothing here.</p></div>' ;
20
- var node = fixture . querySelector ( '#target' ) ;
21
- assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
29
+ var params = checkSetup ( '<div role="list" id="target"><p>Nothing here.</p></div>' ) ;
30
+
31
+ assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
32
+ assert . deepEqual ( checkContext . _data , [ 'listitem' ] ) ;
33
+ } ) ;
34
+
35
+ ( shadowSupported ? it : xit )
36
+ ( 'should detect missing sole required child in shadow tree' , function ( ) {
37
+ fixture . innerHTML = '<div id="target" role="list"></div>' ;
38
+
39
+ var target = document . querySelector ( '#target' ) ;
40
+ var shadowRoot = target . attachShadow ( { mode : 'open' } ) ;
41
+ shadowRoot . innerHTML = '<p>Nothing here.</p>' ;
42
+
43
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
44
+ var virtualTarget = axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ;
45
+
46
+ var params = [ target , undefined , virtualTarget ] ;
47
+ assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
22
48
assert . deepEqual ( checkContext . _data , [ 'listitem' ] ) ;
23
49
} ) ;
24
50
25
51
it ( 'should detect multiple missing required children when one required' , function ( ) {
26
- fixture . innerHTML = '<div role="grid" id="target"><p>Nothing here.</p></div>' ;
27
- var node = fixture . querySelector ( '#target' ) ;
28
- assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
52
+ var params = checkSetup ( '<div role="grid" id="target"><p>Nothing here.</p></div>' ) ;
53
+
54
+ assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
55
+ assert . deepEqual ( checkContext . _data , [ 'rowgroup' , 'row' ] ) ;
56
+ } ) ;
57
+
58
+ ( shadowSupported ? it : xit )
59
+ ( 'should detect missing multiple required children in shadow tree when one required' , function ( ) {
60
+ fixture . innerHTML = '<div role="grid" id="target"></div>' ;
61
+
62
+ var target = document . querySelector ( '#target' ) ;
63
+ var shadowRoot = target . attachShadow ( { mode : 'open' } ) ;
64
+ shadowRoot . innerHTML = '<p>Nothing here.</p>' ;
65
+
66
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
67
+ var virtualTarget = axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ;
68
+
69
+ var params = [ target , undefined , virtualTarget ] ;
70
+ assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
29
71
assert . deepEqual ( checkContext . _data , [ 'rowgroup' , 'row' ] ) ;
30
72
} ) ;
31
73
32
74
it ( 'should detect multiple missing required children when all required' , function ( ) {
33
- fixture . innerHTML = '<div role="combobox" id="target"><p>Nothing here.</p></div>' ;
34
- var node = fixture . querySelector ( '#target' ) ;
35
- assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
75
+ var params = checkSetup ( '<div role="combobox" id="target"><p>Nothing here.</p></div>' ) ;
76
+ assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
36
77
assert . deepEqual ( checkContext . _data , [ 'listbox' , 'textbox' ] ) ;
37
78
} ) ;
38
79
39
80
it ( 'should detect single missing required child when all required' , function ( ) {
40
- fixture . innerHTML = '<div role="combobox" id="target"><p role="listbox">Nothing here.</p></div>' ;
41
- var node = fixture . querySelector ( '#target' ) ;
42
- assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
81
+ var params = checkSetup ( '<div role="combobox" id="target"><p role="listbox">Nothing here.</p></div>' ) ;
82
+ assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
43
83
assert . deepEqual ( checkContext . _data , [ 'textbox' ] ) ;
44
84
} ) ;
45
85
46
86
it ( 'should pass all existing required children when all required' , function ( ) {
47
- fixture . innerHTML = '<div role="combobox" id="target"><p role="listbox">Nothing here.</p><p role="textbox">Textbox</p></div>' ;
48
- var node = fixture . querySelector ( '#target' ) ;
49
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
87
+ var params = checkSetup ( '<div role="combobox" id="target"><p role="listbox">Nothing here.</p><p role="textbox">Textbox</p></div>' ) ;
88
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
89
+ } ) ;
90
+
91
+ ( shadowSupported ? it : xit )
92
+ ( 'should pass all existing required children in shadow tree when all required' , function ( ) {
93
+ fixture . innerHTML = '<div role="combobox" id="target"></div>' ;
94
+
95
+ var target = document . querySelector ( '#target' ) ;
96
+ var shadowRoot = target . attachShadow ( { mode : 'open' } ) ;
97
+ shadowRoot . innerHTML = '<p role="listbox">Nothing here.</p><p role="textbox">Textbox</p>' ;
98
+
99
+ var tree = axe . _tree = axe . utils . getFlattenedTree ( fixture ) ;
100
+ var virtualTarget = axe . utils . getNodeFromTree ( tree [ 0 ] , target ) ;
101
+
102
+ var params = [ target , undefined , virtualTarget ] ;
103
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
50
104
} ) ;
51
105
52
106
it ( 'should pass one indirectly aria-owned child when one required' , function ( ) {
53
- fixture . innerHTML = '<div role="grid" id="target" aria-owns="r"></div><div id="r"><div role="row">Nothing here.</div></div>' ;
54
- var node = fixture . querySelector ( '#target' ) ;
55
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
107
+ var params = checkSetup ( '<div role="grid" id="target" aria-owns="r"></div><div id="r"><div role="row">Nothing here.</div></div>' ) ;
108
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
56
109
} ) ;
57
110
58
111
it ( 'should not break if aria-owns points to non-existent node' , function ( ) {
59
- fixture . innerHTML = '<div role="grid" id="target" aria-owns="nonexistent"></div>' ;
60
- var node = fixture . querySelector ( '#target' ) ;
61
- assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
112
+ var params = checkSetup ( '<div role="grid" id="target" aria-owns="nonexistent"></div>' ) ;
113
+ assert . isFalse ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
62
114
} ) ;
63
115
64
116
it ( 'should pass one existing aria-owned child when one required' , function ( ) {
65
- fixture . innerHTML = '<div role="grid" id="target" aria-owns="r"></div><p id="r" role="row">Nothing here.</p>' ;
66
- var node = fixture . querySelector ( '#target' ) ;
67
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
117
+ var params = checkSetup ( '<div role="grid" id="target" aria-owns="r"></div><p id="r" role="row">Nothing here.</p>' ) ;
118
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
68
119
} ) ;
69
120
70
121
it ( 'should pass one existing required child when one required' , function ( ) {
71
- fixture . innerHTML = '<div role="grid" id="target"><p role="row">Nothing here.</p></div>' ;
72
- var node = fixture . querySelector ( '#target' ) ;
73
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
122
+ var params = checkSetup ( '<div role="grid" id="target"><p role="row">Nothing here.</p></div>' ) ;
123
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
74
124
} ) ;
75
125
76
126
it ( 'should pass one existing required child when one required because of implicit role' , function ( ) {
77
- fixture . innerHTML = '<table id="target"><p role="row">Nothing here.</p></table>' ;
78
- var node = fixture . querySelector ( '#target' ) ;
79
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
127
+ var params = checkSetup ( '<table id="target"><p role="row">Nothing here.</p></table>' ) ;
128
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
80
129
} ) ;
81
130
82
131
it ( 'should pass when a child with an implicit role is present' , function ( ) {
83
- fixture . innerHTML = '<table role="grid" id="target"><tr><td>Nothing here.</td></tr></table>' ;
84
- var node = fixture . querySelector ( '#target' ) ;
85
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
132
+ var params = checkSetup ( '<table role="grid" id="target"><tr><td>Nothing here.</td></tr></table>' ) ;
133
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
86
134
} ) ;
87
135
88
136
it ( 'should pass direct existing required children' , function ( ) {
89
- fixture . innerHTML = '<div role="list" id="target"><p role="listitem">Nothing here.</p></div>' ;
90
- var node = fixture . querySelector ( '#target' ) ;
91
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
137
+ var params = checkSetup ( '<div role="list" id="target"><p role="listitem">Nothing here.</p></div>' ) ;
138
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
92
139
} ) ;
93
140
94
141
it ( 'should pass indirect required children' , function ( ) {
95
- fixture . innerHTML = '<div role="list" id="target"><p>Just a regular ol p that contains a... <p role="listitem">Nothing here.</p></p></div>' ;
96
- var node = fixture . querySelector ( '#target' ) ;
97
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
142
+ var params = checkSetup ( '<div role="list" id="target"><p>Just a regular ol p that contains a... <p role="listitem">Nothing here.</p></p></div>' ) ;
143
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
98
144
} ) ;
99
145
100
146
it ( 'should return true when a role has no required owned' , function ( ) {
101
- fixture . innerHTML = '<div role="listitem" id="target"><p>Nothing here.</p></div>' ;
102
- var node = fixture . querySelector ( '#target' ) ;
103
- assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . call ( checkContext , node ) ) ;
147
+ var params = checkSetup ( '<div role="listitem" id="target"><p>Nothing here.</p></div>' ) ;
148
+ assert . isTrue ( checks [ 'aria-required-children' ] . evaluate . apply ( checkContext , params ) ) ;
104
149
} ) ;
105
150
106
151
} ) ;
0 commit comments