@@ -840,26 +840,53 @@ describe('MatSelectionList with forms', () => {
840
840
describe ( 'and formControl' , ( ) => {
841
841
let fixture : ComponentFixture < SelectionListWithFormControl > ;
842
842
let listOptions : MatListOption [ ] ;
843
+ let selectionList : MatSelectionList ;
843
844
844
845
beforeEach ( ( ) => {
845
846
fixture = TestBed . createComponent ( SelectionListWithFormControl ) ;
846
847
fixture . detectChanges ( ) ;
847
848
849
+ selectionList = fixture . debugElement . query ( By . directive ( MatSelectionList ) ) . componentInstance ;
848
850
listOptions = fixture . debugElement . queryAll ( By . directive ( MatListOption ) )
849
851
. map ( optionDebugEl => optionDebugEl . componentInstance ) ;
850
852
} ) ;
851
853
852
854
it ( 'should be able to disable options from the control' , ( ) => {
855
+ expect ( selectionList . disabled )
856
+ . toBe ( false , 'Expected the selection list to be enabled.' ) ;
853
857
expect ( listOptions . every ( option => ! option . disabled ) )
854
858
. toBe ( true , 'Expected every list option to be enabled.' ) ;
855
859
856
860
fixture . componentInstance . formControl . disable ( ) ;
857
861
fixture . detectChanges ( ) ;
858
862
863
+ expect ( selectionList . disabled )
864
+ . toBe ( true , 'Expected the selection list to be disabled.' ) ;
859
865
expect ( listOptions . every ( option => option . disabled ) )
860
866
. toBe ( true , 'Expected every list option to be disabled.' ) ;
861
867
} ) ;
862
868
869
+ it ( 'should be able to update the disabled property after form control disabling' , ( ) => {
870
+ expect ( listOptions . every ( option => ! option . disabled ) )
871
+ . toBe ( true , 'Expected every list option to be enabled.' ) ;
872
+
873
+ fixture . componentInstance . formControl . disable ( ) ;
874
+ fixture . detectChanges ( ) ;
875
+
876
+ expect ( listOptions . every ( option => option . disabled ) )
877
+ . toBe ( true , 'Expected every list option to be disabled.' ) ;
878
+
879
+ // Previously the selection list has been disabled through FormControl#disable. Now we
880
+ // want to verify that we can still change the disabled state through updating the disabled
881
+ // property. Calling FormControl#disable should not lock the disabled property.
882
+ // See: https://github.com/angular/material2/issues/12107
883
+ selectionList . disabled = false ;
884
+ fixture . detectChanges ( ) ;
885
+
886
+ expect ( listOptions . every ( option => ! option . disabled ) )
887
+ . toBe ( true , 'Expected every list option to be enabled.' ) ;
888
+ } ) ;
889
+
863
890
it ( 'should be able to set the value through the form control' , ( ) => {
864
891
expect ( listOptions . every ( option => ! option . selected ) )
865
892
. toBe ( true , 'Expected every list option to be unselected.' ) ;
0 commit comments