@@ -30,6 +30,8 @@ import {
3030 MatListOptionTogglePosition ,
3131 MatSelectionList ,
3232 MatSelectionListChange ,
33+ MatListConfig ,
34+ MAT_LIST_CONFIG ,
3335} from './index' ;
3436
3537describe ( 'MDC-based MatSelectionList without forms' , ( ) => {
@@ -663,7 +665,7 @@ describe('MDC-based MatSelectionList without forms', () => {
663665 } ) ;
664666 } ) ;
665667
666- describe ( 'with list option selected' , ( ) => {
668+ describe ( 'multiple-selection with list option selected' , ( ) => {
667669 let fixture : ComponentFixture < SelectionListWithSelectedOption > ;
668670 let listOptionElements : DebugElement [ ] ;
669671 let selectionList : DebugElement ;
@@ -703,6 +705,79 @@ describe('MDC-based MatSelectionList without forms', () => {
703705 } ) ) ;
704706 } ) ;
705707
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+
706781 describe ( 'with option disabled' , ( ) => {
707782 let fixture : ComponentFixture < SelectionListWithDisabledOption > ;
708783 let listOptionEl : HTMLElement ;
@@ -1727,6 +1802,15 @@ class SelectionListWithDisabledOption {
17271802} )
17281803class SelectionListWithSelectedOption { }
17291804
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+
17301814@Component ( {
17311815 template : `
17321816 <mat-selection-list>
0 commit comments