@@ -17,22 +17,21 @@ describe( 'FocusCycler', () => {
17
17
testUtils . createSinonSandbox ( ) ;
18
18
19
19
beforeEach ( ( ) => {
20
- focusables = new ViewCollection ( ) ;
20
+ testUtils . sinon . stub ( global . window , 'getComputedStyle' ) ;
21
+ focusables = new ViewCollection ( [
22
+ nonFocusable ( ) ,
23
+ focusable ( ) ,
24
+ focusable ( ) ,
25
+ focusable ( ) ,
26
+ nonFocusable ( )
27
+ ] ) ;
21
28
focusTracker = {
22
29
focusedElement : null
23
30
} ;
24
31
cycler = new FocusCycler ( {
25
32
focusables,
26
33
focusTracker
27
34
} ) ;
28
-
29
- testUtils . sinon . stub ( global . window , 'getComputedStyle' ) ;
30
-
31
- focusables . add ( nonFocusable ( ) ) ;
32
- focusables . add ( focusable ( ) ) ;
33
- focusables . add ( focusable ( ) ) ;
34
- focusables . add ( focusable ( ) ) ;
35
- focusables . add ( nonFocusable ( ) ) ;
36
35
} ) ;
37
36
38
37
describe ( 'constructor()' , ( ) => {
@@ -60,12 +59,9 @@ describe( 'FocusCycler', () => {
60
59
} ) ;
61
60
62
61
it ( 'returns null when no focusable items' , ( ) => {
63
- focusables = new ViewCollection ( ) ;
62
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
64
63
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
65
64
66
- focusables . add ( nonFocusable ( ) ) ;
67
- focusables . add ( nonFocusable ( ) ) ;
68
-
69
65
expect ( cycler . first ) . to . be . null ;
70
66
} ) ;
71
67
@@ -83,12 +79,9 @@ describe( 'FocusCycler', () => {
83
79
} ) ;
84
80
85
81
it ( 'returns null when no focusable items' , ( ) => {
86
- focusables = new ViewCollection ( ) ;
82
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
87
83
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
88
84
89
- focusables . add ( nonFocusable ( ) ) ;
90
- focusables . add ( nonFocusable ( ) ) ;
91
-
92
85
expect ( cycler . last ) . to . be . null ;
93
86
} ) ;
94
87
@@ -126,23 +119,16 @@ describe( 'FocusCycler', () => {
126
119
} ) ;
127
120
128
121
it ( 'returns null when no focusable items' , ( ) => {
129
- focusables = new ViewCollection ( ) ;
122
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
130
123
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
131
124
132
- focusables . add ( nonFocusable ( ) ) ;
133
- focusables . add ( nonFocusable ( ) ) ;
134
-
135
125
expect ( cycler . next ) . to . be . null ;
136
126
} ) ;
137
127
138
128
it ( 'returns null if the only focusable in focusables' , ( ) => {
139
- focusables = new ViewCollection ( ) ;
129
+ focusables = new ViewCollection ( [ nonFocusable ( ) , focusable ( ) , nonFocusable ( ) ] ) ;
140
130
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
141
131
142
- focusables . add ( nonFocusable ( ) ) ;
143
- focusables . add ( focusable ( ) ) ;
144
- focusables . add ( nonFocusable ( ) ) ;
145
-
146
132
focusTracker . focusedElement = focusables . get ( 1 ) . element ;
147
133
148
134
expect ( cycler . first ) . to . equal ( focusables . get ( 1 ) ) ;
@@ -176,23 +162,16 @@ describe( 'FocusCycler', () => {
176
162
} ) ;
177
163
178
164
it ( 'returns null when no focusable items' , ( ) => {
179
- focusables = new ViewCollection ( ) ;
165
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
180
166
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
181
167
182
- focusables . add ( nonFocusable ( ) ) ;
183
- focusables . add ( nonFocusable ( ) ) ;
184
-
185
168
expect ( cycler . previous ) . to . be . null ;
186
169
} ) ;
187
170
188
171
it ( 'returns null if the only focusable in focusables' , ( ) => {
189
- focusables = new ViewCollection ( ) ;
172
+ focusables = new ViewCollection ( [ nonFocusable ( ) , focusable ( ) , nonFocusable ( ) ] ) ;
190
173
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
191
174
192
- focusables . add ( nonFocusable ( ) ) ;
193
- focusables . add ( focusable ( ) ) ;
194
- focusables . add ( nonFocusable ( ) ) ;
195
-
196
175
focusTracker . focusedElement = focusables . get ( 1 ) . element ;
197
176
198
177
expect ( cycler . first ) . to . equal ( focusables . get ( 1 ) ) ;
@@ -208,12 +187,9 @@ describe( 'FocusCycler', () => {
208
187
} ) ;
209
188
210
189
it ( 'does not throw when no focusable items' , ( ) => {
211
- focusables = new ViewCollection ( ) ;
190
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
212
191
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
213
192
214
- focusables . add ( nonFocusable ( ) ) ;
215
- focusables . add ( nonFocusable ( ) ) ;
216
-
217
193
expect ( ( ) => {
218
194
cycler . focusFirst ( ) ;
219
195
} ) . to . not . throw ( ) ;
@@ -231,11 +207,7 @@ describe( 'FocusCycler', () => {
231
207
it ( 'ignores invisible items' , ( ) => {
232
208
const item = focusable ( ) ;
233
209
234
- focusables = new ViewCollection ( ) ;
235
- focusables . add ( nonFocusable ( ) ) ;
236
- focusables . add ( focusable ( true ) ) ;
237
- focusables . add ( item ) ;
238
-
210
+ focusables = new ViewCollection ( [ nonFocusable ( ) , focusable ( true ) , item ] ) ;
239
211
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
240
212
241
213
cycler . focusFirst ( ) ;
@@ -251,12 +223,9 @@ describe( 'FocusCycler', () => {
251
223
} ) ;
252
224
253
225
it ( 'does not throw when no focusable items' , ( ) => {
254
- focusables = new ViewCollection ( ) ;
226
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
255
227
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
256
228
257
- focusables . add ( nonFocusable ( ) ) ;
258
- focusables . add ( nonFocusable ( ) ) ;
259
-
260
229
expect ( ( ) => {
261
230
cycler . focusLast ( ) ;
262
231
} ) . to . not . throw ( ) ;
@@ -281,12 +250,9 @@ describe( 'FocusCycler', () => {
281
250
} ) ;
282
251
283
252
it ( 'does not throw when no focusable items' , ( ) => {
284
- focusables = new ViewCollection ( ) ;
253
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
285
254
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
286
255
287
- focusables . add ( nonFocusable ( ) ) ;
288
- focusables . add ( nonFocusable ( ) ) ;
289
-
290
256
expect ( ( ) => {
291
257
cycler . focusNext ( ) ;
292
258
} ) . to . not . throw ( ) ;
@@ -311,12 +277,9 @@ describe( 'FocusCycler', () => {
311
277
} ) ;
312
278
313
279
it ( 'does not throw when no focusable items' , ( ) => {
314
- focusables = new ViewCollection ( ) ;
280
+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
315
281
cycler = new FocusCycler ( { focusables, focusTracker } ) ;
316
282
317
- focusables . add ( nonFocusable ( ) ) ;
318
- focusables . add ( nonFocusable ( ) ) ;
319
-
320
283
expect ( ( ) => {
321
284
cycler . focusPrevious ( ) ;
322
285
} ) . to . not . throw ( ) ;
0 commit comments