@@ -437,6 +437,87 @@ describe('MDC-based MatSelectionList without forms', () => {
437437 ) ;
438438 } ) ;
439439
440+ it ( 'should select all items using command(metaKey) + a' , ( ) => {
441+ listOptions . forEach ( option => ( option . componentInstance . disabled = false ) ) ;
442+ fixture . detectChanges ( ) ;
443+
444+ expect ( listOptions . some ( option => option . componentInstance . selected ) ) . toBe ( false ) ;
445+
446+ listOptions [ 2 ] . nativeElement . focus ( ) ;
447+ dispatchKeyboardEvent ( listOptions [ 2 ] . nativeElement , 'keydown' , A , 'A' , { meta : true } ) ;
448+ fixture . detectChanges ( ) ;
449+
450+ expect ( listOptions . every ( option => option . componentInstance . selected ) ) . toBe ( true ) ;
451+ } ) ;
452+
453+ it ( 'should not select disabled items when pressing command(metaKey) + a' , ( ) => {
454+ listOptions . slice ( 0 , 2 ) . forEach ( option => ( option . componentInstance . disabled = true ) ) ;
455+ fixture . detectChanges ( ) ;
456+
457+ expect ( listOptions . map ( option => option . componentInstance . selected ) ) . toEqual ( [
458+ false ,
459+ false ,
460+ false ,
461+ false ,
462+ false ,
463+ ] ) ;
464+
465+ listOptions [ 3 ] . nativeElement . focus ( ) ;
466+ dispatchKeyboardEvent ( listOptions [ 3 ] . nativeElement , 'keydown' , A , 'A' , { meta : true } ) ;
467+ fixture . detectChanges ( ) ;
468+
469+ expect ( listOptions . map ( option => option . componentInstance . selected ) ) . toEqual ( [
470+ false ,
471+ false ,
472+ true ,
473+ true ,
474+ true ,
475+ ] ) ;
476+ } ) ;
477+
478+ it ( 'should select all items using command(metaKey) + a if some items are selected' , ( ) => {
479+ listOptions . slice ( 0 , 2 ) . forEach ( option => ( option . componentInstance . selected = true ) ) ;
480+ fixture . detectChanges ( ) ;
481+
482+ expect ( listOptions . some ( option => option . componentInstance . selected ) ) . toBe ( true ) ;
483+
484+ listOptions [ 2 ] . nativeElement . focus ( ) ;
485+ dispatchKeyboardEvent ( listOptions [ 2 ] . nativeElement , 'keydown' , A , 'A' , { meta : true } ) ;
486+ fixture . detectChanges ( ) ;
487+
488+ expect ( listOptions . every ( option => option . componentInstance . selected ) ) . toBe ( true ) ;
489+ } ) ;
490+
491+ it ( 'should deselect all with command(metaKey) + a if all options are selected' , ( ) => {
492+ listOptions . forEach ( option => ( option . componentInstance . selected = true ) ) ;
493+ fixture . detectChanges ( ) ;
494+
495+ expect ( listOptions . every ( option => option . componentInstance . selected ) ) . toBe ( true ) ;
496+
497+ listOptions [ 2 ] . nativeElement . focus ( ) ;
498+ dispatchKeyboardEvent ( listOptions [ 2 ] . nativeElement , 'keydown' , A , 'A' , { meta : true } ) ;
499+ fixture . detectChanges ( ) ;
500+
501+ expect ( listOptions . every ( option => option . componentInstance . selected ) ) . toBe ( false ) ;
502+ } ) ;
503+
504+ it ( 'should dispatch the selectionChange event when selecting via command(metaKey) + a' , ( ) => {
505+ const spy = spyOn ( fixture . componentInstance , 'onSelectionChange' ) ;
506+ listOptions . forEach ( option => ( option . componentInstance . disabled = false ) ) ;
507+ fixture . detectChanges ( ) ;
508+
509+ listOptions [ 2 ] . nativeElement . focus ( ) ;
510+ dispatchKeyboardEvent ( listOptions [ 2 ] . nativeElement , 'keydown' , A , 'A' , { meta : true } ) ;
511+ fixture . detectChanges ( ) ;
512+
513+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
514+ expect ( spy ) . toHaveBeenCalledWith (
515+ jasmine . objectContaining ( {
516+ options : listOptions . map ( option => option . componentInstance ) ,
517+ } ) ,
518+ ) ;
519+ } ) ;
520+
440521 it ( 'should be able to jump focus down to an item by typing' , fakeAsync ( ( ) => {
441522 const firstOption = listOptions [ 0 ] . nativeElement ;
442523
0 commit comments