1
1
import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
2
2
import { FormControl , FormsModule , NgModel , ReactiveFormsModule } from '@angular/forms' ;
3
- import { Component , DebugElement } from '@angular/core' ;
3
+ import { Component , DebugElement , ViewChild } from '@angular/core' ;
4
4
import { By } from '@angular/platform-browser' ;
5
5
import { dispatchFakeEvent } from '@angular/cdk/testing' ;
6
6
import { defaultRippleAnimationConfig } from '@angular/material/core' ;
@@ -12,6 +12,7 @@ describe('MatRadio', () => {
12
12
TestBed . configureTestingModule ( {
13
13
imports : [ MatRadioModule , FormsModule , ReactiveFormsModule ] ,
14
14
declarations : [
15
+ DisableableRadioButton ,
15
16
FocusableRadioButton ,
16
17
RadiosInsideRadioGroup ,
17
18
RadioGroupWithNgModel ,
@@ -515,6 +516,38 @@ describe('MatRadio', () => {
515
516
} ) ;
516
517
} ) ;
517
518
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
+
518
551
describe ( 'as standalone' , ( ) => {
519
552
let fixture : ComponentFixture < StandaloneRadioButtons > ;
520
553
let radioDebugElements : DebugElement [ ] ;
@@ -795,6 +828,17 @@ class RadioGroupWithNgModel {
795
828
lastEvent : MatRadioChange ;
796
829
}
797
830
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
+
798
842
@Component ( {
799
843
template : `
800
844
<mat-radio-group [formControl]="formControl">
0 commit comments