@@ -57,7 +57,7 @@ describe('MatSelectionList without forms', () => {
57
57
} ) ) ;
58
58
59
59
it ( 'should be able to set a value on a list option' , ( ) => {
60
- const optionValues = [ 'inbox' , 'starred' , 'sent-mail' , 'drafts' ] ;
60
+ const optionValues = [ 'inbox' , 'starred' , 'sent-mail' , 'archive' , ' drafts'] ;
61
61
62
62
optionValues . forEach ( ( optionValue , index ) => {
63
63
expect ( listOptions [ index ] . componentInstance . value ) . toBe ( optionValue ) ;
@@ -337,35 +337,35 @@ describe('MatSelectionList without forms', () => {
337
337
it ( 'should restore focus if active option is destroyed' , ( ) => {
338
338
const manager = selectionList . componentInstance . _keyManager ;
339
339
340
- spyOn ( listOptions [ 2 ] . componentInstance , 'focus' ) . and . callThrough ( ) ;
341
- listOptions [ 3 ] . componentInstance . _handleFocus ( ) ;
340
+ spyOn ( listOptions [ 3 ] . componentInstance , 'focus' ) . and . callThrough ( ) ;
341
+ listOptions [ 4 ] . componentInstance . _handleFocus ( ) ;
342
342
343
- expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
343
+ expect ( manager . activeItemIndex ) . toBe ( 4 ) ;
344
344
345
345
fixture . componentInstance . showLastOption = false ;
346
346
fixture . detectChanges ( ) ;
347
347
348
- expect ( manager . activeItemIndex ) . toBe ( 2 ) ;
349
- expect ( listOptions [ 2 ] . componentInstance . focus ) . toHaveBeenCalled ( ) ;
348
+ expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
349
+ expect ( listOptions [ 3 ] . componentInstance . focus ) . toHaveBeenCalled ( ) ;
350
350
} ) ;
351
351
352
352
it ( 'should not attempt to focus the next option when the destroyed option was not focused' ,
353
353
( ) => {
354
354
const manager = selectionList . componentInstance . _keyManager ;
355
355
356
356
// Focus and blur the option to move the active item index.
357
- listOptions [ 3 ] . componentInstance . _handleFocus ( ) ;
358
- listOptions [ 3 ] . componentInstance . _handleBlur ( ) ;
357
+ listOptions [ 4 ] . componentInstance . _handleFocus ( ) ;
358
+ listOptions [ 4 ] . componentInstance . _handleBlur ( ) ;
359
359
360
- spyOn ( listOptions [ 2 ] . componentInstance , 'focus' ) . and . callThrough ( ) ;
360
+ spyOn ( listOptions [ 3 ] . componentInstance , 'focus' ) . and . callThrough ( ) ;
361
361
362
- expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
362
+ expect ( manager . activeItemIndex ) . toBe ( 4 ) ;
363
363
364
364
fixture . componentInstance . showLastOption = false ;
365
365
fixture . detectChanges ( ) ;
366
366
367
- expect ( manager . activeItemIndex ) . toBe ( 2 ) ;
368
- expect ( listOptions [ 2 ] . componentInstance . focus ) . not . toHaveBeenCalled ( ) ;
367
+ expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
368
+ expect ( listOptions [ 3 ] . componentInstance . focus ) . not . toHaveBeenCalled ( ) ;
369
369
} ) ;
370
370
371
371
it ( 'should focus previous item when press UP ARROW' , ( ) => {
@@ -475,7 +475,7 @@ describe('MatSelectionList without forms', () => {
475
475
const event = dispatchKeyboardEvent ( selectionList . nativeElement , 'keydown' , END ) ;
476
476
fixture . detectChanges ( ) ;
477
477
478
- expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
478
+ expect ( manager . activeItemIndex ) . toBe ( 4 ) ;
479
479
expect ( event . defaultPrevented ) . toBe ( true ) ;
480
480
} ) ;
481
481
@@ -551,19 +551,33 @@ describe('MatSelectionList without forms', () => {
551
551
fixture . detectChanges ( ) ;
552
552
tick ( 200 ) ;
553
553
554
- expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
554
+ expect ( manager . activeItemIndex ) . toBe ( 4 ) ;
555
555
} ) ) ;
556
556
557
557
it ( 'should be able to skip to an item by typing' , fakeAsync ( ( ) => {
558
558
const manager = selectionList . componentInstance . _keyManager ;
559
559
560
- expect ( manager . activeItemIndex ) . not . toBe ( 3 ) ;
560
+ expect ( manager . activeItemIndex ) . not . toBe ( 4 ) ;
561
561
562
562
const event = createKeyboardEvent ( 'keydown' , D , 'd' ) ;
563
563
selectionList . componentInstance . _keydown ( event ) ;
564
564
fixture . detectChanges ( ) ;
565
565
tick ( 200 ) ;
566
566
567
+ expect ( manager . activeItemIndex ) . toBe ( 4 ) ;
568
+ } ) ) ;
569
+
570
+ // Test for "A" specifically, because it's a special case that can be used to select all values.
571
+ it ( 'should be able to skip to an item by typing the letter "A"' , fakeAsync ( ( ) => {
572
+ const manager = selectionList . componentInstance . _keyManager ;
573
+
574
+ expect ( manager . activeItemIndex ) . not . toBe ( 3 ) ;
575
+
576
+ const event = createKeyboardEvent ( 'keydown' , A , 'a' ) ;
577
+ selectionList . componentInstance . _keydown ( event ) ;
578
+ fixture . detectChanges ( ) ;
579
+ tick ( 200 ) ;
580
+
567
581
expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
568
582
} ) ) ;
569
583
@@ -588,7 +602,7 @@ describe('MatSelectionList without forms', () => {
588
602
fixture . detectChanges ( ) ;
589
603
tick ( 100 ) ; // Tick the rest of the timeout.
590
604
591
- expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
605
+ expect ( manager . activeItemIndex ) . toBe ( 4 ) ;
592
606
expect ( model . isEmpty ( ) ) . toBe ( true ) ;
593
607
} ) ) ;
594
608
@@ -902,7 +916,7 @@ describe('MatSelectionList without forms', () => {
902
916
903
917
describe ( 'with single selection' , ( ) => {
904
918
let fixture : ComponentFixture < SelectionListWithListOptions > ;
905
- let listOption : DebugElement [ ] ;
919
+ let listOptions : DebugElement [ ] ;
906
920
let selectionList : DebugElement ;
907
921
908
922
beforeEach ( async ( ( ) => {
@@ -915,14 +929,14 @@ describe('MatSelectionList without forms', () => {
915
929
916
930
fixture = TestBed . createComponent ( SelectionListWithListOptions ) ;
917
931
fixture . componentInstance . multiple = false ;
918
- listOption = fixture . debugElement . queryAll ( By . directive ( MatListOption ) ) ;
932
+ listOptions = fixture . debugElement . queryAll ( By . directive ( MatListOption ) ) ;
919
933
selectionList = fixture . debugElement . query ( By . directive ( MatSelectionList ) ) ! ;
920
934
fixture . detectChanges ( ) ;
921
935
} ) ) ;
922
936
923
937
it ( 'should select one option at a time' , ( ) => {
924
- const testListItem1 = listOption [ 1 ] . injector . get < MatListOption > ( MatListOption ) ;
925
- const testListItem2 = listOption [ 2 ] . injector . get < MatListOption > ( MatListOption ) ;
938
+ const testListItem1 = listOptions [ 1 ] . injector . get < MatListOption > ( MatListOption ) ;
939
+ const testListItem2 = listOptions [ 2 ] . injector . get < MatListOption > ( MatListOption ) ;
926
940
const selectList =
927
941
selectionList . injector . get < MatSelectionList > ( MatSelectionList ) . selectedOptions ;
928
942
@@ -932,16 +946,16 @@ describe('MatSelectionList without forms', () => {
932
946
fixture . detectChanges ( ) ;
933
947
934
948
expect ( selectList . selected ) . toEqual ( [ testListItem1 ] ) ;
935
- expect ( listOption [ 1 ] . nativeElement . classList . contains ( 'mat-list-single-selected-option' ) )
949
+ expect ( listOptions [ 1 ] . nativeElement . classList . contains ( 'mat-list-single-selected-option' ) )
936
950
. toBe ( true ) ;
937
951
938
952
dispatchFakeEvent ( testListItem2 . _getHostElement ( ) , 'click' ) ;
939
953
fixture . detectChanges ( ) ;
940
954
941
955
expect ( selectList . selected ) . toEqual ( [ testListItem2 ] ) ;
942
- expect ( listOption [ 1 ] . nativeElement . classList . contains ( 'mat-list-single-selected-option' ) )
956
+ expect ( listOptions [ 1 ] . nativeElement . classList . contains ( 'mat-list-single-selected-option' ) )
943
957
. toBe ( false ) ;
944
- expect ( listOption [ 2 ] . nativeElement . classList . contains ( 'mat-list-single-selected-option' ) )
958
+ expect ( listOptions [ 2 ] . nativeElement . classList . contains ( 'mat-list-single-selected-option' ) )
945
959
. toBe ( true ) ;
946
960
} ) ;
947
961
@@ -950,7 +964,7 @@ describe('MatSelectionList without forms', () => {
950
964
} ) ;
951
965
952
966
it ( 'should not deselect the target option on click' , ( ) => {
953
- const testListItem1 = listOption [ 1 ] . injector . get < MatListOption > ( MatListOption ) ;
967
+ const testListItem1 = listOptions [ 1 ] . injector . get < MatListOption > ( MatListOption ) ;
954
968
const selectList =
955
969
selectionList . injector . get < MatSelectionList > ( MatSelectionList ) . selectedOptions ;
956
970
@@ -972,6 +986,19 @@ describe('MatSelectionList without forms', () => {
972
986
expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( new Error (
973
987
'Cannot change `multiple` mode of mat-selection-list after initialization.' ) ) ;
974
988
} ) ;
989
+
990
+ it ( 'should do nothing when pressing ctrl + a' , ( ) => {
991
+ const event = createKeyboardEvent ( 'keydown' , A , selectionList . nativeElement ) ;
992
+ Object . defineProperty ( event , 'ctrlKey' , { get : ( ) => true } ) ;
993
+
994
+ expect ( listOptions . every ( option => ! option . componentInstance . selected ) ) . toBe ( true ) ;
995
+
996
+ dispatchEvent ( selectionList . nativeElement , event ) ;
997
+ fixture . detectChanges ( ) ;
998
+
999
+ expect ( listOptions . every ( option => ! option . componentInstance . selected ) ) . toBe ( true ) ;
1000
+ } ) ;
1001
+
975
1002
} ) ;
976
1003
} ) ;
977
1004
@@ -1369,12 +1396,15 @@ describe('MatSelectionList with forms', () => {
1369
1396
<mat-list-option checkboxPosition="before" value="sent-mail">
1370
1397
Sent Mail
1371
1398
</mat-list-option>
1399
+ <mat-list-option checkboxPosition="before" value="archive">
1400
+ Archive
1401
+ </mat-list-option>
1372
1402
<mat-list-option checkboxPosition="before" value="drafts" *ngIf="showLastOption">
1373
1403
Drafts
1374
1404
</mat-list-option>
1375
1405
</mat-selection-list>` } )
1376
1406
class SelectionListWithListOptions {
1377
- showLastOption : boolean = true ;
1407
+ showLastOption = true ;
1378
1408
listRippleDisabled = false ;
1379
1409
multiple = true ;
1380
1410
selectionListColor : ThemePalette ;
0 commit comments