-
Notifications
You must be signed in to change notification settings - Fork 743
/
th-has-data-cells.js
159 lines (138 loc) · 4.73 KB
/
th-has-data-cells.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
describe('th-has-data-cells', function() {
'use strict';
var fixture = document.getElementById('fixture');
var shadowSupport = axe.testUtils.shadowSupport.v1;
var checkContext = axe.testUtils.MockCheckContext();
afterEach(function() {
fixture.innerHTML = '';
checkContext.reset();
});
it('should return true each row header has a non-empty cell', function() {
fixture.innerHTML =
'<table>' +
' <tr> <th>hi</th> <td>hello</td> </tr>' +
' <tr> <th>hi</th> <td>hello</td> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return true each non-empty column header has a cell', function() {
fixture.innerHTML =
'<table>' +
' <tr> <th>H</th> <th>H</th> </tr>' +
' <tr> <td>hi</td> <td>hello</td></tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return true if referred to with headers attr', function() {
fixture.innerHTML =
'<table>' +
' <tr> <td headers="a">hi</td> <td headers="b">hello</td></tr>' +
' <tr> <th id="a">H</th> <th id="b">H</th> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return true if referred to with aria-labelledby', function() {
fixture.innerHTML =
'<table>' +
' <tr> <td aria-labelledby="a">hi</td> <td aria-labelledby="b">hello</td></tr>' +
' <tr> <th id="a">H</th> <th id="b">H</th> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return true if the th element is empty', function() {
fixture.innerHTML =
'<table>' +
' <tr> <th></th> <th></th> </tr>' +
' <tr> <th></th> <th></th> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return true when the td has a content element', function() {
fixture.innerHTML =
'<table>' +
' <tr> <th>hi</th> <td><input type="text"></td> </tr>' +
' <tr> <th>hi</th> <td><textarea></textarea></td> </tr>' +
' <tr> <th>hi</th> <td><select><option>a</option></select></td> </tr>' +
' <tr> <th>hi</th> <td><img src="" alt="foo"></td> </tr>' +
' <tr> <th>hi</th> <td><video></video></td> </tr>' +
' <tr> <th>hi</th> <td><audio></audio></td> </tr>' +
' <tr> <th>hi</th> <td><span role="img"></span></td> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return undefined if a th has no data cells', function() {
fixture.innerHTML =
'<table>' +
' <tr> <th>hi</th> </tr>' +
' <tr> <th>hi</th> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isUndefined(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return true if all data cells are empty', function() {
fixture.innerHTML =
'<table>' +
' <tr> <th>hi</th> <td></td> </tr>' +
' <tr> <th>hi</th> <td></td> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
it('should return undefined if a td with role=columnheader is used that has no data cells', function() {
fixture.innerHTML =
'<table id="fail4">' +
' <tr> <td>axe</td> <td role="columnheader">AXE</th> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = fixture.querySelector('table');
assert.isUndefined(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
(shadowSupport ? it : xit)('recognizes shadow tree content', function() {
fixture.innerHTML = '<div id="shadow"> <b>data</b> </div>';
var shadow = fixture
.querySelector('#shadow')
.attachShadow({ mode: 'open' });
shadow.innerHTML =
'<table>' +
' <tr> <th> header </th> </tr>' +
' <tr> <td><slot></slot></td> </tr>' +
'</table>';
axe.testUtils.flatTreeSetup(fixture);
var node = axe.utils.querySelectorAll(axe._tree, 'table')[0].actualNode;
assert.isTrue(
checks['th-has-data-cells'].evaluate.call(checkContext, node)
);
});
});