1- import { Component , DebugElement } from '@angular/core' ;
2- import { ComponentFixture , fakeAsync , flushMicrotasks , TestBed , tick , flush } from '@angular/core/testing' ;
3- import { FormControl , FormsModule , NgModel , ReactiveFormsModule } from '@angular/forms' ;
4- import { By } from '@angular/platform-browser' ;
1+ import { Component , DebugElement } from '@angular/core' ;
2+ import { ComponentFixture , fakeAsync , flushMicrotasks , TestBed , tick , flush , async } from '@angular/core/testing' ;
3+ import { FormControl , FormsModule , NgModel , ReactiveFormsModule } from '@angular/forms' ;
4+ import { By } from '@angular/platform-browser' ;
55
6- import { dispatchFakeEvent , dispatchMouseEvent } from '../testing/dispatch-events' ;
6+ import { dispatchFakeEvent , dispatchMouseEvent } from '../testing/dispatch-events' ;
77
8- import { MdcSwitch , MdcSwitchModule } from '@angular-mdc/web' ;
8+ import { MdcSwitch , MdcSwitchModule } from '@angular-mdc/web' ;
99
1010describe ( 'MdcSwitch' , ( ) => {
1111 let fixture : ComponentFixture < any > ;
@@ -16,13 +16,36 @@ describe('MdcSwitch', () => {
1616 declarations : [
1717 SingleSwitch ,
1818 SwitchWithModel ,
19- SwitchWithFormControl
19+ SwitchWithFormControl ,
20+ DisabledSwitch
2021 ]
2122 } ) ;
2223
2324 TestBed . compileComponents ( ) ;
2425 } ) ) ;
2526
27+ describe ( 'disabled switch' , ( ) => {
28+ let switchDebugElement : DebugElement ;
29+ let switchNativeElement : HTMLElement ;
30+ let switchInstance : MdcSwitch ;
31+ let testComponent : DisabledSwitch ;
32+
33+ beforeEach ( async ( ( ) => {
34+ fixture = TestBed . createComponent ( DisabledSwitch ) ;
35+ fixture . detectChanges ( ) ;
36+
37+ switchDebugElement = fixture . debugElement . query ( By . directive ( MdcSwitch ) ) ;
38+ switchNativeElement = switchDebugElement . nativeElement ;
39+ switchInstance = switchDebugElement . componentInstance ;
40+ testComponent = fixture . debugElement . componentInstance ;
41+ } ) ) ;
42+
43+ it ( '#should be disabled' , ( ) => {
44+ fixture . detectChanges ( ) ;
45+ expect ( switchInstance . _inputElement . nativeElement . disabled ) . toBe ( true ) ;
46+ } ) ;
47+ } ) ;
48+
2649 describe ( 'basic behaviors' , ( ) => {
2750 let switchDebugElement : DebugElement ;
2851 let switchNativeElement : HTMLElement ;
@@ -243,7 +266,7 @@ describe('MdcSwitch with forms', () => {
243266 fixture . detectChanges ( ) ;
244267 tick ( ) ;
245268
246- expect ( spy ) . toHaveBeenCalledWith ( jasmine . objectContaining ( { checked : true } ) ) ;
269+ expect ( spy ) . toHaveBeenCalledWith ( jasmine . objectContaining ( { checked : true } ) ) ;
247270 subscription . unsubscribe ( ) ;
248271 } ) ) ;
249272
@@ -313,7 +336,7 @@ class SingleSwitch {
313336 slideTabindex : number ;
314337 switchValue : string = 'single_switch' ;
315338
316- onChange : ( ) => void = ( ) => { } ;
339+ onChange : ( ) => void = ( ) => { } ;
317340}
318341
319342@Component ( {
@@ -328,11 +351,16 @@ class SwitchWithFormControl {
328351 formControl = new FormControl ( ) ;
329352}
330353
354+ @Component ( {
355+ template : `<mdc-switch disabled></mdc-switch>` ,
356+ } )
357+ class DisabledSwitch { }
358+
331359/** Simple component for testing with ngModel in a form. */
332360@Component ( {
333361 template : `<mdc-switch name="cb" [(ngModel)]="modelValue" (change)="onChange()">Be good</mdc-switch>` ,
334362} )
335363class SwitchWithModel {
336364 modelValue : boolean = false ;
337- onChange : ( ) => void = ( ) => { } ;
365+ onChange : ( ) => void = ( ) => { } ;
338366}
0 commit comments