@@ -17,22 +17,21 @@ describe( 'FocusCycler', () => {
1717 testUtils . createSinonSandbox ( ) ;
1818
1919 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+ ] ) ;
2128 focusTracker = {
2229 focusedElement : null
2330 } ;
2431 cycler = new FocusCycler ( {
2532 focusables,
2633 focusTracker
2734 } ) ;
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 ( ) ) ;
3635 } ) ;
3736
3837 describe ( 'constructor()' , ( ) => {
@@ -60,12 +59,9 @@ describe( 'FocusCycler', () => {
6059 } ) ;
6160
6261 it ( 'returns null when no focusable items' , ( ) => {
63- focusables = new ViewCollection ( ) ;
62+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
6463 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
6564
66- focusables . add ( nonFocusable ( ) ) ;
67- focusables . add ( nonFocusable ( ) ) ;
68-
6965 expect ( cycler . first ) . to . be . null ;
7066 } ) ;
7167
@@ -83,12 +79,9 @@ describe( 'FocusCycler', () => {
8379 } ) ;
8480
8581 it ( 'returns null when no focusable items' , ( ) => {
86- focusables = new ViewCollection ( ) ;
82+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
8783 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
8884
89- focusables . add ( nonFocusable ( ) ) ;
90- focusables . add ( nonFocusable ( ) ) ;
91-
9285 expect ( cycler . last ) . to . be . null ;
9386 } ) ;
9487
@@ -126,23 +119,16 @@ describe( 'FocusCycler', () => {
126119 } ) ;
127120
128121 it ( 'returns null when no focusable items' , ( ) => {
129- focusables = new ViewCollection ( ) ;
122+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
130123 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
131124
132- focusables . add ( nonFocusable ( ) ) ;
133- focusables . add ( nonFocusable ( ) ) ;
134-
135125 expect ( cycler . next ) . to . be . null ;
136126 } ) ;
137127
138128 it ( 'returns null if the only focusable in focusables' , ( ) => {
139- focusables = new ViewCollection ( ) ;
129+ focusables = new ViewCollection ( [ nonFocusable ( ) , focusable ( ) , nonFocusable ( ) ] ) ;
140130 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
141131
142- focusables . add ( nonFocusable ( ) ) ;
143- focusables . add ( focusable ( ) ) ;
144- focusables . add ( nonFocusable ( ) ) ;
145-
146132 focusTracker . focusedElement = focusables . get ( 1 ) . element ;
147133
148134 expect ( cycler . first ) . to . equal ( focusables . get ( 1 ) ) ;
@@ -176,23 +162,16 @@ describe( 'FocusCycler', () => {
176162 } ) ;
177163
178164 it ( 'returns null when no focusable items' , ( ) => {
179- focusables = new ViewCollection ( ) ;
165+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
180166 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
181167
182- focusables . add ( nonFocusable ( ) ) ;
183- focusables . add ( nonFocusable ( ) ) ;
184-
185168 expect ( cycler . previous ) . to . be . null ;
186169 } ) ;
187170
188171 it ( 'returns null if the only focusable in focusables' , ( ) => {
189- focusables = new ViewCollection ( ) ;
172+ focusables = new ViewCollection ( [ nonFocusable ( ) , focusable ( ) , nonFocusable ( ) ] ) ;
190173 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
191174
192- focusables . add ( nonFocusable ( ) ) ;
193- focusables . add ( focusable ( ) ) ;
194- focusables . add ( nonFocusable ( ) ) ;
195-
196175 focusTracker . focusedElement = focusables . get ( 1 ) . element ;
197176
198177 expect ( cycler . first ) . to . equal ( focusables . get ( 1 ) ) ;
@@ -208,12 +187,9 @@ describe( 'FocusCycler', () => {
208187 } ) ;
209188
210189 it ( 'does not throw when no focusable items' , ( ) => {
211- focusables = new ViewCollection ( ) ;
190+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
212191 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
213192
214- focusables . add ( nonFocusable ( ) ) ;
215- focusables . add ( nonFocusable ( ) ) ;
216-
217193 expect ( ( ) => {
218194 cycler . focusFirst ( ) ;
219195 } ) . to . not . throw ( ) ;
@@ -231,11 +207,7 @@ describe( 'FocusCycler', () => {
231207 it ( 'ignores invisible items' , ( ) => {
232208 const item = focusable ( ) ;
233209
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 ] ) ;
239211 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
240212
241213 cycler . focusFirst ( ) ;
@@ -251,12 +223,9 @@ describe( 'FocusCycler', () => {
251223 } ) ;
252224
253225 it ( 'does not throw when no focusable items' , ( ) => {
254- focusables = new ViewCollection ( ) ;
226+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
255227 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
256228
257- focusables . add ( nonFocusable ( ) ) ;
258- focusables . add ( nonFocusable ( ) ) ;
259-
260229 expect ( ( ) => {
261230 cycler . focusLast ( ) ;
262231 } ) . to . not . throw ( ) ;
@@ -281,12 +250,9 @@ describe( 'FocusCycler', () => {
281250 } ) ;
282251
283252 it ( 'does not throw when no focusable items' , ( ) => {
284- focusables = new ViewCollection ( ) ;
253+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
285254 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
286255
287- focusables . add ( nonFocusable ( ) ) ;
288- focusables . add ( nonFocusable ( ) ) ;
289-
290256 expect ( ( ) => {
291257 cycler . focusNext ( ) ;
292258 } ) . to . not . throw ( ) ;
@@ -311,12 +277,9 @@ describe( 'FocusCycler', () => {
311277 } ) ;
312278
313279 it ( 'does not throw when no focusable items' , ( ) => {
314- focusables = new ViewCollection ( ) ;
280+ focusables = new ViewCollection ( [ nonFocusable ( ) , nonFocusable ( ) ] ) ;
315281 cycler = new FocusCycler ( { focusables, focusTracker } ) ;
316282
317- focusables . add ( nonFocusable ( ) ) ;
318- focusables . add ( nonFocusable ( ) ) ;
319-
320283 expect ( ( ) => {
321284 cycler . focusPrevious ( ) ;
322285 } ) . to . not . throw ( ) ;
0 commit comments