@@ -190,17 +190,6 @@ describe('MdCheckbox', () => {
190190 expect ( inputElement . disabled ) . toBe ( false ) ;
191191 } ) ;
192192
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-
204193 it ( 'should not toggle `checked` state upon interation while disabled' , ( ) => {
205194 testComponent . isDisabled = true ;
206195 fixture . detectChanges ( ) ;
@@ -324,6 +313,44 @@ describe('MdCheckbox', () => {
324313 expect ( document . activeElement ) . toBe ( inputElement ) ;
325314 } ) ;
326315
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+
327354 describe ( 'color behaviour' , ( ) => {
328355 it ( 'should apply class based on color attribute' , ( ) => {
329356 testComponent . checkboxColor = 'primary' ;
@@ -544,19 +571,6 @@ describe('MdCheckbox', () => {
544571 expect ( inputElement . tabIndex ) . toBe ( 13 ) ;
545572 } ) ;
546573
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- } ) ) ;
560574 } ) ;
561575
562576 describe ( 'with multiple checkboxes' , ( ) => {
@@ -678,6 +692,7 @@ describe('MdCheckbox', () => {
678692 [(indeterminate)]="isIndeterminate"
679693 [disabled]="isDisabled"
680694 [color]="checkboxColor"
695+ [disableRipple]="disableRipple"
681696 (change)="changeCount = changeCount + 1"
682697 (click)="onCheckboxClick($event)"
683698 (change)="onCheckboxChange($event)">
@@ -691,6 +706,7 @@ class SingleCheckbox {
691706 isRequired : boolean = false ;
692707 isIndeterminate : boolean = false ;
693708 isDisabled : boolean = false ;
709+ disableRipple : boolean = false ;
694710 parentElementClicked : boolean = false ;
695711 parentElementKeyedUp : boolean = false ;
696712 lastKeydownEvent : Event = null ;
@@ -728,14 +744,12 @@ class MultipleCheckboxes { }
728744 template : `
729745 <md-checkbox
730746 [tabIndex]="customTabIndex"
731- [disabled]="isDisabled"
732- [disableRipple]="disableRipple">
747+ [disabled]="isDisabled">
733748 </md-checkbox>` ,
734749} )
735750class CheckboxWithTabIndex {
736751 customTabIndex : number = 7 ;
737752 isDisabled : boolean = false ;
738- disableRipple : boolean = false ;
739753}
740754
741755/** Simple test component with an aria-label set. */
@@ -771,3 +785,10 @@ class CheckboxWithChangeEvent {
771785class CheckboxWithFormControl {
772786 formControl = new FormControl ( ) ;
773787}
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