-
Notifications
You must be signed in to change notification settings - Fork 82
/
maintain.hidden.test.js
223 lines (181 loc) · 7.25 KB
/
maintain.hidden.test.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
define(function(require) {
'use strict';
var bdd = require('intern!bdd');
var expect = require('intern/chai!expect');
var customFixture = require('../helper/fixtures/custom.fixture');
var maintainHidden = require('ally/maintain/hidden');
bdd.describe('maintain/hidden', function() {
var fixture;
var handle;
function before() {
fixture = customFixture([
/* eslint-disable indent */
'<div id="uncle-1">',
'<div id="cousin-1"></div>',
'</div>',
'<div id="family">',
'<div id="parent">',
'<div id="target"></div>',
'<div id="sibling"></div>',
'</div>',
'<div id="uncle-2">',
'<div id="cousin-2"></div>',
'<div id="target-2"></div>',
'</div>',
'</div>',
/*eslint-disable indent */
]);
}
function after() {
handle && handle.disengage({ force: true });
fixture && fixture.remove();
fixture = null;
}
bdd.describe('with filter', function() {
var uncle;
var target;
bdd.before(function() {
before();
uncle = document.getElementById('uncle-1');
target = document.getElementById('target');
});
bdd.after(after);
bdd.it('should set aria-hidden upon engaging', function() {
handle = maintainHidden({
filter: '#target',
});
expect(handle.disengage).to.be.a('function');
expect(fixture.root.getAttribute('aria-hidden')).to.equal(null, 'ancestry not hidden');
expect(target.getAttribute('aria-hidden')).to.equal(null, 'filter not hidden');
expect(uncle.getAttribute('aria-hidden')).to.equal('true', 'uncle hidden');
});
bdd.it('should unset aria-hidden upon disengaging', function() {
handle.disengage();
expect(uncle.getAttribute('aria-hidden')).to.equal(null, 'uncle not hidden');
});
});
bdd.describe('with context and filter', function() {
var sibling;
var cousin;
var target;
var family;
bdd.before(function() {
before();
sibling = document.getElementById('sibling');
cousin = document.getElementById('cousin-2');
target = document.getElementById('target');
family = document.getElementById('family');
});
bdd.after(after);
bdd.it('should set aria-hidden upon engaging', function() {
handle = maintainHidden({
context: '#family',
filter: '#target, #target-2',
});
expect(handle.disengage).to.be.a('function');
expect(fixture.root.getAttribute('aria-hidden')).to.equal(null, 'ancestry not hidden');
expect(family.getAttribute('aria-hidden')).to.equal(null, 'context not hidden');
expect(target.getAttribute('aria-hidden')).to.equal(null, 'target not hidden');
expect(sibling.getAttribute('aria-hidden')).to.equal('true', 'sibling hidden');
expect(cousin.getAttribute('aria-hidden')).to.equal('true', 'cousin hidden');
});
bdd.it('should unset aria-hidden upon disengaging', function() {
handle.disengage();
expect(sibling.getAttribute('aria-hidden')).to.equal(null, 'sibling not hidden');
expect(cousin.getAttribute('aria-hidden')).to.equal(null, 'cousin not hidden');
});
});
bdd.describe('for concurrent instances', function() {
var handle2;
var container;
var dynamicSibling;
var sibling;
var target;
var family;
bdd.before(function() {
before();
container = fixture.add('<div id="dynamic-sibling"></div><div id="dynamic-target"></div>', 'dynamic-wrapper');
dynamicSibling = document.getElementById('dynamic-sibling');
sibling = document.getElementById('sibling');
family = document.getElementById('family');
target = document.getElementById('target');
});
bdd.after(function() {
after();
handle2 && handle.disengage();
});
bdd.it('should set aria-hidden upon engaging first context', function() {
handle = maintainHidden({
context: '#family',
filter: '#target',
});
expect(family.getAttribute('aria-hidden')).to.equal(null, 'ancestry not hidden');
expect(target.getAttribute('aria-hidden')).to.equal(null, 'target not hidden');
expect(sibling.getAttribute('aria-hidden')).to.equal('true', 'sibling hidden');
expect(dynamicSibling.getAttribute('aria-hidden')).to.equal(null, 'dynamic-sibling not hidden');
});
bdd.it('should set aria-hidden upon engaging second context', function() {
handle2 = maintainHidden({
context: container,
filter: '#dynamic-target',
});
expect(family.getAttribute('aria-hidden')).to.equal(null, 'ancestry not hidden');
expect(target.getAttribute('aria-hidden')).to.equal(null, 'target not hidden');
expect(sibling.getAttribute('aria-hidden')).to.equal('true', 'sibling hidden');
expect(dynamicSibling.getAttribute('aria-hidden')).to.equal('true', 'dynamic-sibling hidden');
});
bdd.it('should unset aria-hidden upon disengaging', function() {
handle.disengage();
expect(sibling.getAttribute('aria-hidden')).to.equal(null, 'sibling not hidden');
expect(dynamicSibling.getAttribute('aria-hidden')).to.equal('true', 'dynamic-sibling still hidden');
});
});
bdd.describe('for DOM Mutation', function() {
var target;
var uncle;
var child;
var cousin;
bdd.before(function() {
if (!window.MutationObserver) {
this.skip('MutationObserver not supported');
}
before();
target = document.getElementById('target');
handle = maintainHidden({
context: fixture.root,
filter: '#target',
});
});
bdd.after(after);
bdd.it('should ingest added uncles', function() {
var deferred = this.async(10000);
uncle = fixture.add('<div></div>');
setTimeout(deferred.callback(function() {
expect(uncle.getAttribute('aria-hidden')).to.equal('true', 'uncled hidden');
}), 50);
});
bdd.it('should not ingest elements added to filter', function() {
var deferred = this.async(10000);
child = document.createElement('div');
target.appendChild(child);
setTimeout(deferred.callback(function() {
expect(child.getAttribute('aria-hidden')).to.equal(null, 'child not hidden');
}), 50);
});
bdd.it('should not ingest elements added to hidden elements', function() {
var deferred = this.async(10000);
cousin = document.createElement('div');
uncle.appendChild(cousin);
setTimeout(deferred.callback(function() {
expect(cousin.getAttribute('aria-hidden')).to.equal(null, 'cousin not hidden');
}), 50);
});
bdd.it('should unset aria-hidden upon disengage', function() {
handle.disengage();
expect(uncle.getAttribute('aria-hidden')).to.equal(null, 'uncle not hidden');
expect(child.getAttribute('aria-hidden')).to.equal(null, 'child not hidden');
expect(cousin.getAttribute('aria-hidden')).to.equal(null, 'cousin not hidden');
});
});
});
});