@@ -9,7 +9,11 @@ import {
9
9
CdkOption ,
10
10
CdkListboxModule , ListboxSelectionChangeEvent , CdkListbox
11
11
} from './index' ;
12
- import { dispatchKeyboardEvent , dispatchMouseEvent } from '@angular/cdk/testing/private' ;
12
+ import {
13
+ createKeyboardEvent ,
14
+ dispatchKeyboardEvent ,
15
+ dispatchMouseEvent
16
+ } from '@angular/cdk/testing/private' ;
13
17
import { A , DOWN_ARROW , END , HOME , SPACE } from '@angular/cdk/keycodes' ;
14
18
15
19
describe ( 'CdkOption' , ( ) => {
@@ -327,6 +331,28 @@ describe('CdkOption', () => {
327
331
expect ( fixture . componentInstance . changedOption ) . toBeDefined ( ) ;
328
332
expect ( fixture . componentInstance . changedOption . id ) . toBe ( optionInstances [ 0 ] . id ) ;
329
333
} ) ;
334
+
335
+ it ( 'should focus and toggle the next item when pressing SHIFT + DOWN_ARROW' , ( ) => {
336
+ let selectedOptions = optionInstances . filter ( option => option . selected ) ;
337
+ const downKeyEvent = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
338
+ Object . defineProperty ( downKeyEvent , 'shiftKey' , { get : ( ) => true } ) ;
339
+
340
+ expect ( selectedOptions . length ) . toBe ( 0 ) ;
341
+ expect ( optionElements [ 0 ] . hasAttribute ( 'aria-selected' ) ) . toBeFalse ( ) ;
342
+ expect ( optionInstances [ 0 ] . selected ) . toBeFalse ( ) ;
343
+ expect ( fixture . componentInstance . changedOption ) . toBeUndefined ( ) ;
344
+
345
+ listboxInstance . setActiveOption ( optionInstances [ 0 ] ) ;
346
+ listboxInstance . _keydown ( downKeyEvent ) ;
347
+ fixture . detectChanges ( ) ;
348
+
349
+ selectedOptions = optionInstances . filter ( option => option . selected ) ;
350
+ expect ( selectedOptions . length ) . toBe ( 1 ) ;
351
+ expect ( optionElements [ 1 ] . getAttribute ( 'aria-selected' ) ) . toBe ( 'true' ) ;
352
+ expect ( optionInstances [ 1 ] . selected ) . toBeTrue ( ) ;
353
+ expect ( fixture . componentInstance . changedOption ) . toBeDefined ( ) ;
354
+ expect ( fixture . componentInstance . changedOption . id ) . toBe ( optionInstances [ 1 ] . id ) ;
355
+ } ) ;
330
356
} ) ;
331
357
332
358
describe ( 'with multiple selection' , ( ) => {
0 commit comments