22 ComponentFixture ,
33 fakeAsync ,
44 TestBed ,
5- tick ,
65 flush ,
76 flushMicrotasks ,
87} from '@angular/core/testing' ;
@@ -11,7 +10,6 @@ import {Component, DebugElement, ViewChild, Type} from '@angular/core';
1110import { By } from '@angular/platform-browser' ;
1211import { dispatchFakeEvent } from '@angular/cdk/testing' ;
1312import { MatCheckbox , MatCheckboxChange , MatCheckboxModule } from './index' ;
14- import { defaultRippleAnimationConfig } from '@angular/material/core' ;
1513import { MAT_CHECKBOX_CLICK_ACTION } from './checkbox-config' ;
1614import { MutationObserverFactory } from '@angular/cdk/observers' ;
1715
@@ -379,74 +377,59 @@ describe('MatCheckbox', () => {
379377 expect ( inputElement . value ) . toBe ( 'basic_checkbox' ) ;
380378 } ) ;
381379
382- it ( 'should show a ripple when focused by a keyboard action' , fakeAsync ( ( ) => {
383- expect ( fixture . nativeElement . querySelectorAll ( '.mat-ripple-element' ) . length )
384- . toBe ( 0 , 'Expected no ripples on load.' ) ;
385-
386- dispatchFakeEvent ( inputElement , 'keydown' ) ;
387- dispatchFakeEvent ( inputElement , 'focus' ) ;
388-
389- tick ( defaultRippleAnimationConfig . enterDuration ) ;
390-
391- expect ( fixture . nativeElement . querySelectorAll ( '.mat-ripple-element' ) . length )
392- . toBe ( 1 , 'Expected ripple after element is focused.' ) ;
393-
394- dispatchFakeEvent ( checkboxInstance . _inputElement . nativeElement , 'blur' ) ;
395- tick ( defaultRippleAnimationConfig . exitDuration ) ;
396-
397- expect ( fixture . nativeElement . querySelectorAll ( '.mat-ripple-element' ) . length )
398- . toBe ( 0 , 'Expected no ripple after element is blurred.' ) ;
399- } ) ) ;
400-
401380 it ( 'should remove the SVG checkmark from the tab order' , ( ) => {
402381 expect ( checkboxNativeElement . querySelector ( 'svg' ) ! . getAttribute ( 'focusable' ) ) . toBe ( 'false' ) ;
403382 } ) ;
404383
405384 describe ( 'ripple elements' , ( ) => {
406385
407386 it ( 'should show ripples on label mousedown' , ( ) => {
408- expect ( checkboxNativeElement . querySelector ( '.mat-ripple-element' ) ) . toBeFalsy ( ) ;
387+ const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)' ;
388+
389+ expect ( checkboxNativeElement . querySelector ( rippleSelector ) ) . toBeFalsy ( ) ;
409390
410391 dispatchFakeEvent ( labelElement , 'mousedown' ) ;
411392 dispatchFakeEvent ( labelElement , 'mouseup' ) ;
412393
413- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
394+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
414395 } ) ;
415396
416397 it ( 'should not show ripples when disabled' , ( ) => {
398+ const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)' ;
417399 testComponent . isDisabled = true ;
418400 fixture . detectChanges ( ) ;
419401
420402 dispatchFakeEvent ( labelElement , 'mousedown' ) ;
421403 dispatchFakeEvent ( labelElement , 'mouseup' ) ;
422404
423- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
405+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 0 ) ;
424406
425407 testComponent . isDisabled = false ;
426408 fixture . detectChanges ( ) ;
427409
428410 dispatchFakeEvent ( labelElement , 'mousedown' ) ;
429411 dispatchFakeEvent ( labelElement , 'mouseup' ) ;
430412
431- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
413+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
432414 } ) ;
433415
434416 it ( 'should remove ripple if matRippleDisabled input is set' , ( ) => {
417+ const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)' ;
435418 testComponent . disableRipple = true ;
436419 fixture . detectChanges ( ) ;
437420
438421 dispatchFakeEvent ( labelElement , 'mousedown' ) ;
439422 dispatchFakeEvent ( labelElement , 'mouseup' ) ;
440423
441- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
424+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 0 ) ;
442425
443426 testComponent . disableRipple = false ;
444427 fixture . detectChanges ( ) ;
445428
446429 dispatchFakeEvent ( labelElement , 'mousedown' ) ;
447430 dispatchFakeEvent ( labelElement , 'mouseup' ) ;
448431
449- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
432+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
450433 } ) ;
451434 } ) ;
452435
@@ -842,19 +825,20 @@ describe('MatCheckbox', () => {
842825 } ) ;
843826
844827 it ( 'should toggle checkbox ripple disabledness correctly' , ( ) => {
828+ const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)' ;
845829 const labelElement = checkboxNativeElement . querySelector ( 'label' ) as HTMLLabelElement ;
846830
847831 testComponent . isDisabled = true ;
848832 fixture . detectChanges ( ) ;
849833 dispatchFakeEvent ( labelElement , 'mousedown' ) ;
850834 dispatchFakeEvent ( labelElement , 'mouseup' ) ;
851- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
835+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 0 ) ;
852836
853837 testComponent . isDisabled = false ;
854838 fixture . detectChanges ( ) ;
855839 dispatchFakeEvent ( labelElement , 'mousedown' ) ;
856840 dispatchFakeEvent ( labelElement , 'mouseup' ) ;
857- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
841+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
858842 } ) ;
859843 } ) ;
860844
0 commit comments