@@ -30,6 +30,8 @@ import {
30
30
MatListOptionTogglePosition ,
31
31
MatSelectionList ,
32
32
MatSelectionListChange ,
33
+ MatListConfig ,
34
+ MAT_LIST_CONFIG ,
33
35
} from './index' ;
34
36
35
37
describe ( 'MDC-based MatSelectionList without forms' , ( ) => {
@@ -663,7 +665,7 @@ describe('MDC-based MatSelectionList without forms', () => {
663
665
} ) ;
664
666
} ) ;
665
667
666
- describe ( 'with list option selected' , ( ) => {
668
+ describe ( 'multiple-selection with list option selected' , ( ) => {
667
669
let fixture : ComponentFixture < SelectionListWithSelectedOption > ;
668
670
let listOptionElements : DebugElement [ ] ;
669
671
let selectionList : DebugElement ;
@@ -703,6 +705,79 @@ describe('MDC-based MatSelectionList without forms', () => {
703
705
} ) ) ;
704
706
} ) ;
705
707
708
+ describe ( 'single-selection with list option selected' , ( ) => {
709
+ let fixture : ComponentFixture < SingleSelectionListWithSelectedOption > ;
710
+ let listOptionElements : DebugElement [ ] ;
711
+
712
+ beforeEach ( waitForAsync ( ( ) => {
713
+ TestBed . configureTestingModule ( {
714
+ imports : [ MatListModule ] ,
715
+ declarations : [ SingleSelectionListWithSelectedOption ] ,
716
+ } ) ;
717
+
718
+ TestBed . compileComponents ( ) ;
719
+ } ) ) ;
720
+
721
+ beforeEach ( waitForAsync ( ( ) => {
722
+ fixture = TestBed . createComponent ( SingleSelectionListWithSelectedOption ) ;
723
+ listOptionElements = fixture . debugElement . queryAll ( By . directive ( MatListOption ) ) ! ;
724
+ fixture . detectChanges ( ) ;
725
+ } ) ) ;
726
+
727
+ it ( 'displays radio indicators by default' , ( ) => {
728
+ expect (
729
+ listOptionElements [ 0 ] . nativeElement . querySelector ( 'input[type="radio"]' ) ,
730
+ ) . not . toBeNull ( ) ;
731
+ expect (
732
+ listOptionElements [ 1 ] . nativeElement . querySelector ( 'input[type="radio"]' ) ,
733
+ ) . not . toBeNull ( ) ;
734
+
735
+ expect ( listOptionElements [ 0 ] . nativeElement . classList ) . not . toContain (
736
+ 'mdc-list-item--selected' ,
737
+ ) ;
738
+ expect ( listOptionElements [ 1 ] . nativeElement . classList ) . not . toContain (
739
+ 'mdc-list-item--selected' ,
740
+ ) ;
741
+ } ) ;
742
+ } ) ;
743
+
744
+ describe ( 'with token to hide radio indicators' , ( ) => {
745
+ let fixture : ComponentFixture < SingleSelectionListWithSelectedOption > ;
746
+ let listOptionElements : DebugElement [ ] ;
747
+
748
+ beforeEach ( waitForAsync ( ( ) => {
749
+ const matListConfig : MatListConfig = { hideSingleSelectionIndicator : true } ;
750
+
751
+ TestBed . configureTestingModule ( {
752
+ imports : [ MatListModule ] ,
753
+ declarations : [ SingleSelectionListWithSelectedOption ] ,
754
+ providers : [ { provide : MAT_LIST_CONFIG , useValue : matListConfig } ] ,
755
+ } ) ;
756
+
757
+ TestBed . compileComponents ( ) ;
758
+ } ) ) ;
759
+
760
+ beforeEach ( waitForAsync ( ( ) => {
761
+ fixture = TestBed . createComponent ( SingleSelectionListWithSelectedOption ) ;
762
+ listOptionElements = fixture . debugElement . queryAll ( By . directive ( MatListOption ) ) ! ;
763
+ fixture . detectChanges ( ) ;
764
+ } ) ) ;
765
+
766
+ it ( 'does not display radio indicators' , ( ) => {
767
+ expect ( listOptionElements [ 0 ] . nativeElement . querySelector ( 'input[type="radio"]' ) ) . toBeNull ( ) ;
768
+ expect ( listOptionElements [ 1 ] . nativeElement . querySelector ( 'input[type="radio"]' ) ) . toBeNull ( ) ;
769
+
770
+ expect ( listOptionElements [ 0 ] . nativeElement . classList ) . not . toContain (
771
+ 'mdc-list-item--selected' ,
772
+ ) ;
773
+
774
+ expect ( listOptionElements [ 1 ] . nativeElement . getAttribute ( 'aria-selected' ) )
775
+ . withContext ( 'Expected second option to be selected' )
776
+ . toBe ( 'true' ) ;
777
+ expect ( listOptionElements [ 1 ] . nativeElement . classList ) . toContain ( 'mdc-list-item--selected' ) ;
778
+ } ) ;
779
+ } ) ;
780
+
706
781
describe ( 'with option disabled' , ( ) => {
707
782
let fixture : ComponentFixture < SelectionListWithDisabledOption > ;
708
783
let listOptionEl : HTMLElement ;
@@ -1727,6 +1802,15 @@ class SelectionListWithDisabledOption {
1727
1802
} )
1728
1803
class SelectionListWithSelectedOption { }
1729
1804
1805
+ @Component ( {
1806
+ template : `
1807
+ <mat-selection-list [multiple]="false">
1808
+ <mat-list-option>Not selected - Item #1</mat-list-option>
1809
+ <mat-list-option [selected]="true">Pre-selected - Item #2</mat-list-option>
1810
+ </mat-selection-list>` ,
1811
+ } )
1812
+ class SingleSelectionListWithSelectedOption { }
1813
+
1730
1814
@Component ( {
1731
1815
template : `
1732
1816
<mat-selection-list>
0 commit comments