@@ -190,17 +190,6 @@ describe('MdCheckbox', () => {
190
190
expect ( inputElement . disabled ) . toBe ( false ) ;
191
191
} ) ;
192
192
193
- it ( 'should not have a ripple when disabled' , ( ) => {
194
- let rippleElement = checkboxNativeElement . querySelector ( '[md-ripple]' ) ;
195
- expect ( rippleElement ) . toBeTruthy ( 'Expected an enabled checkbox to have a ripple' ) ;
196
-
197
- testComponent . isDisabled = true ;
198
- fixture . detectChanges ( ) ;
199
-
200
- rippleElement = checkboxNativeElement . querySelector ( '[md-ripple]' ) ;
201
- expect ( rippleElement ) . toBeFalsy ( 'Expected a disabled checkbox not to have a ripple' ) ;
202
- } ) ;
203
-
204
193
it ( 'should not toggle `checked` state upon interation while disabled' , ( ) => {
205
194
testComponent . isDisabled = true ;
206
195
fixture . detectChanges ( ) ;
@@ -324,6 +313,44 @@ describe('MdCheckbox', () => {
324
313
expect ( document . activeElement ) . toBe ( inputElement ) ;
325
314
} ) ;
326
315
316
+ describe ( 'ripple elements' , ( ) => {
317
+
318
+ it ( 'should show ripples on label mousedown' , ( ) => {
319
+ expect ( checkboxNativeElement . querySelector ( '.mat-ripple-element' ) ) . toBeFalsy ( ) ;
320
+
321
+ dispatchFakeEvent ( labelElement , 'mousedown' ) ;
322
+ dispatchFakeEvent ( labelElement , 'mouseup' ) ;
323
+
324
+ expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
325
+ } ) ;
326
+
327
+ it ( 'should not have a ripple when disabled' , ( ) => {
328
+ let rippleElement = checkboxNativeElement . querySelector ( '[md-ripple]' ) ;
329
+ expect ( rippleElement ) . toBeTruthy ( 'Expected an enabled checkbox to have a ripple' ) ;
330
+
331
+ testComponent . isDisabled = true ;
332
+ fixture . detectChanges ( ) ;
333
+
334
+ rippleElement = checkboxNativeElement . querySelector ( '[md-ripple]' ) ;
335
+ expect ( rippleElement ) . toBeFalsy ( 'Expected a disabled checkbox not to have a ripple' ) ;
336
+ } ) ;
337
+
338
+ it ( 'should remove ripple if mdRippleDisabled input is set' , async ( ( ) => {
339
+ testComponent . disableRipple = true ;
340
+ fixture . detectChanges ( ) ;
341
+
342
+ expect ( checkboxNativeElement . querySelectorAll ( '[md-ripple]' ) . length )
343
+ . toBe ( 0 , 'Expect no [md-ripple] in checkbox' ) ;
344
+
345
+ testComponent . disableRipple = false ;
346
+ fixture . detectChanges ( ) ;
347
+
348
+ expect ( checkboxNativeElement . querySelectorAll ( '[md-ripple]' ) . length )
349
+ . toBe ( 1 , 'Expect [md-ripple] in checkbox' ) ;
350
+ } ) ) ;
351
+
352
+ } ) ;
353
+
327
354
describe ( 'color behaviour' , ( ) => {
328
355
it ( 'should apply class based on color attribute' , ( ) => {
329
356
testComponent . checkboxColor = 'primary' ;
@@ -544,19 +571,6 @@ describe('MdCheckbox', () => {
544
571
expect ( inputElement . tabIndex ) . toBe ( 13 ) ;
545
572
} ) ;
546
573
547
- it ( 'should remove ripple if mdRippleDisabled input is set' , async ( ( ) => {
548
- testComponent . disableRipple = true ;
549
- fixture . detectChanges ( ) ;
550
-
551
- expect ( checkboxNativeElement . querySelectorAll ( '[md-ripple]' ) . length )
552
- . toBe ( 0 , 'Expect no [md-ripple] in checkbox' ) ;
553
-
554
- testComponent . disableRipple = false ;
555
- fixture . detectChanges ( ) ;
556
-
557
- expect ( checkboxNativeElement . querySelectorAll ( '[md-ripple]' ) . length )
558
- . toBe ( 1 , 'Expect [md-ripple] in checkbox' ) ;
559
- } ) ) ;
560
574
} ) ;
561
575
562
576
describe ( 'with multiple checkboxes' , ( ) => {
@@ -678,6 +692,7 @@ describe('MdCheckbox', () => {
678
692
[(indeterminate)]="isIndeterminate"
679
693
[disabled]="isDisabled"
680
694
[color]="checkboxColor"
695
+ [disableRipple]="disableRipple"
681
696
(change)="changeCount = changeCount + 1"
682
697
(click)="onCheckboxClick($event)"
683
698
(change)="onCheckboxChange($event)">
@@ -691,6 +706,7 @@ class SingleCheckbox {
691
706
isRequired : boolean = false ;
692
707
isIndeterminate : boolean = false ;
693
708
isDisabled : boolean = false ;
709
+ disableRipple : boolean = false ;
694
710
parentElementClicked : boolean = false ;
695
711
parentElementKeyedUp : boolean = false ;
696
712
lastKeydownEvent : Event = null ;
@@ -728,14 +744,12 @@ class MultipleCheckboxes { }
728
744
template : `
729
745
<md-checkbox
730
746
[tabIndex]="customTabIndex"
731
- [disabled]="isDisabled"
732
- [disableRipple]="disableRipple">
747
+ [disabled]="isDisabled">
733
748
</md-checkbox>` ,
734
749
} )
735
750
class CheckboxWithTabIndex {
736
751
customTabIndex : number = 7 ;
737
752
isDisabled : boolean = false ;
738
- disableRipple : boolean = false ;
739
753
}
740
754
741
755
/** Simple test component with an aria-label set. */
@@ -771,3 +785,10 @@ class CheckboxWithChangeEvent {
771
785
class CheckboxWithFormControl {
772
786
formControl = new FormControl ( ) ;
773
787
}
788
+
789
+ // TODO(devversion): replace with global utility once pull request #2943 is merged.
790
+ function dispatchFakeEvent ( element : HTMLElement , eventName : string ) : void {
791
+ let event = document . createEvent ( 'Event' ) ;
792
+ event . initEvent ( eventName , true , true ) ;
793
+ element . dispatchEvent ( event ) ;
794
+ }
0 commit comments