11import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
22import { FormControl , FormsModule , NgModel , ReactiveFormsModule } from '@angular/forms' ;
3- import { Component , DebugElement } from '@angular/core' ;
3+ import { Component , DebugElement , ViewChild } from '@angular/core' ;
44import { By } from '@angular/platform-browser' ;
55import { dispatchFakeEvent } from '@angular/cdk/testing' ;
66import { defaultRippleAnimationConfig } from '@angular/material/core' ;
@@ -12,6 +12,7 @@ describe('MatRadio', () => {
1212 TestBed . configureTestingModule ( {
1313 imports : [ MatRadioModule , FormsModule , ReactiveFormsModule ] ,
1414 declarations : [
15+ DisableableRadioButton ,
1516 FocusableRadioButton ,
1617 RadiosInsideRadioGroup ,
1718 RadioGroupWithNgModel ,
@@ -515,6 +516,38 @@ describe('MatRadio', () => {
515516 } ) ;
516517 } ) ;
517518
519+ describe ( 'disableable' , ( ) => {
520+ let fixture : ComponentFixture < DisableableRadioButton > ;
521+ let radioInstance : MatRadioButton ;
522+ let radioNativeElement : HTMLInputElement ;
523+ let testComponent : DisableableRadioButton ;
524+
525+ beforeEach ( ( ) => {
526+ fixture = TestBed . createComponent ( DisableableRadioButton ) ;
527+ fixture . detectChanges ( ) ;
528+
529+ testComponent = fixture . debugElement . componentInstance ;
530+ const radioDebugElement = fixture . debugElement . query ( By . directive ( MatRadioButton ) ) ;
531+ radioInstance = radioDebugElement . injector . get < MatRadioButton > ( MatRadioButton ) ;
532+ radioNativeElement = radioDebugElement . nativeElement . querySelector ( 'input' ) ;
533+ } ) ;
534+
535+ it ( 'should toggle the disabled state' , ( ) => {
536+ expect ( radioInstance . disabled ) . toBeFalsy ( ) ;
537+ expect ( radioNativeElement . disabled ) . toBeFalsy ( ) ;
538+
539+ testComponent . disabled = true ;
540+ fixture . detectChanges ( ) ;
541+ expect ( radioInstance . disabled ) . toBeTruthy ( ) ;
542+ expect ( radioNativeElement . disabled ) . toBeTruthy ( ) ;
543+
544+ testComponent . disabled = false ;
545+ fixture . detectChanges ( ) ;
546+ expect ( radioInstance . disabled ) . toBeFalsy ( ) ;
547+ expect ( radioNativeElement . disabled ) . toBeFalsy ( ) ;
548+ } ) ;
549+ } ) ;
550+
518551 describe ( 'as standalone' , ( ) => {
519552 let fixture : ComponentFixture < StandaloneRadioButtons > ;
520553 let radioDebugElements : DebugElement [ ] ;
@@ -795,6 +828,17 @@ class RadioGroupWithNgModel {
795828 lastEvent : MatRadioChange ;
796829}
797830
831+ @Component ( {
832+ template : `<mat-radio-button>One</mat-radio-button>`
833+ } )
834+ class DisableableRadioButton {
835+ @ViewChild ( MatRadioButton ) matRadioButton ;
836+
837+ set disabled ( value : boolean ) {
838+ this . matRadioButton . disabled = value ;
839+ }
840+ }
841+
798842@Component ( {
799843 template : `
800844 <mat-radio-group [formControl]="formControl">
0 commit comments