@@ -138,14 +138,6 @@ describe('combobox-nav', function() {
138
138
assert . equal ( options [ 5 ] . getAttribute ( 'aria-selected' ) , 'true' )
139
139
assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'link' )
140
140
141
- press ( input , 'Home' )
142
- assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
143
- assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'baymax' )
144
-
145
- press ( input , 'End' )
146
- assert . equal ( options [ 5 ] . getAttribute ( 'aria-selected' ) , 'true' )
147
- assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'link' )
148
-
149
141
press ( input , 'Enter' )
150
142
assert . equal ( expectedTargets . length , 2 )
151
143
assert . equal ( expectedTargets [ 0 ] , 'hubot' )
@@ -230,4 +222,68 @@ describe('combobox-nav', function() {
230
222
assert . equal ( list . scrollTop , 36 )
231
223
} )
232
224
} )
225
+
226
+ describe ( 'with Home key navigation enabled' , function ( ) {
227
+ let input , list , options , combobox
228
+ beforeEach ( function ( ) {
229
+ document . body . innerHTML = `
230
+ <input type="text">
231
+ <ul role="listbox" id="list-id">
232
+ <li id="baymax" role="option">Baymax</li>
233
+ <li><del>BB-8</del></li>
234
+ <li id="hubot" role="option">Hubot</li>
235
+ <li id="r2-d2" role="option">R2-D2</li>
236
+ <li id="johnny-5" hidden role="option">Johnny 5</li>
237
+ <li id="wall-e" role="option" aria-disabled="true">Wall-E</li>
238
+ <li><a href="#link" role="option" id="link">Link</a></li>
239
+ </ul>
240
+ `
241
+ input = document . querySelector ( 'input' )
242
+ list = document . querySelector ( 'ul' )
243
+ options = document . querySelectorAll ( '[role=option]' )
244
+ combobox = new Combobox ( input , list , { optionalNavigationKeys : [ 'Home' ] } )
245
+ combobox . start ( )
246
+ } )
247
+
248
+ it ( 'updates attributes on keyboard events' , function ( ) {
249
+ press ( input , 'ArrowDown' )
250
+ press ( input , 'ArrowDown' )
251
+
252
+ assert . equal ( options [ 1 ] . getAttribute ( 'aria-selected' ) , 'true' )
253
+ assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'hubot' )
254
+
255
+ press ( input , 'Home' )
256
+ assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
257
+ assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'baymax' )
258
+ } )
259
+ } )
260
+
261
+ describe ( 'with End key navigation enabled' , function ( ) {
262
+ let input , list , options , combobox
263
+ beforeEach ( function ( ) {
264
+ document . body . innerHTML = `
265
+ <input type="text">
266
+ <ul role="listbox" id="list-id">
267
+ <li id="baymax" role="option">Baymax</li>
268
+ <li><del>BB-8</del></li>
269
+ <li id="hubot" role="option">Hubot</li>
270
+ <li id="r2-d2" role="option">R2-D2</li>
271
+ <li id="johnny-5" hidden role="option">Johnny 5</li>
272
+ <li id="wall-e" role="option" aria-disabled="true">Wall-E</li>
273
+ <li><a href="#link" role="option" id="link">Link</a></li>
274
+ </ul>
275
+ `
276
+ input = document . querySelector ( 'input' )
277
+ list = document . querySelector ( 'ul' )
278
+ options = document . querySelectorAll ( '[role=option]' )
279
+ combobox = new Combobox ( input , list , { optionalNavigationKeys : [ 'End' ] } )
280
+ combobox . start ( )
281
+ } )
282
+
283
+ it ( 'updates attributes on keyboard events' , function ( ) {
284
+ press ( input , 'End' )
285
+ assert . equal ( options [ 5 ] . getAttribute ( 'aria-selected' ) , 'true' )
286
+ assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'link' )
287
+ } )
288
+ } )
233
289
} )
0 commit comments