2
2
ComponentFixture ,
3
3
fakeAsync ,
4
4
TestBed ,
5
- tick ,
6
5
flush ,
7
6
flushMicrotasks ,
8
7
} from '@angular/core/testing' ;
@@ -11,7 +10,6 @@ import {Component, DebugElement, ViewChild, Type} from '@angular/core';
11
10
import { By } from '@angular/platform-browser' ;
12
11
import { dispatchFakeEvent } from '@angular/cdk/testing' ;
13
12
import { MatCheckbox , MatCheckboxChange , MatCheckboxModule } from './index' ;
14
- import { defaultRippleAnimationConfig } from '@angular/material/core' ;
15
13
import { MAT_CHECKBOX_CLICK_ACTION } from './checkbox-config' ;
16
14
import { MutationObserverFactory } from '@angular/cdk/observers' ;
17
15
@@ -379,74 +377,59 @@ describe('MatCheckbox', () => {
379
377
expect ( inputElement . value ) . toBe ( 'basic_checkbox' ) ;
380
378
} ) ;
381
379
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
-
401
380
it ( 'should remove the SVG checkmark from the tab order' , ( ) => {
402
381
expect ( checkboxNativeElement . querySelector ( 'svg' ) ! . getAttribute ( 'focusable' ) ) . toBe ( 'false' ) ;
403
382
} ) ;
404
383
405
384
describe ( 'ripple elements' , ( ) => {
406
385
407
386
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 ( ) ;
409
390
410
391
dispatchFakeEvent ( labelElement , 'mousedown' ) ;
411
392
dispatchFakeEvent ( labelElement , 'mouseup' ) ;
412
393
413
- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
394
+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
414
395
} ) ;
415
396
416
397
it ( 'should not show ripples when disabled' , ( ) => {
398
+ const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)' ;
417
399
testComponent . isDisabled = true ;
418
400
fixture . detectChanges ( ) ;
419
401
420
402
dispatchFakeEvent ( labelElement , 'mousedown' ) ;
421
403
dispatchFakeEvent ( labelElement , 'mouseup' ) ;
422
404
423
- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
405
+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 0 ) ;
424
406
425
407
testComponent . isDisabled = false ;
426
408
fixture . detectChanges ( ) ;
427
409
428
410
dispatchFakeEvent ( labelElement , 'mousedown' ) ;
429
411
dispatchFakeEvent ( labelElement , 'mouseup' ) ;
430
412
431
- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
413
+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
432
414
} ) ;
433
415
434
416
it ( 'should remove ripple if matRippleDisabled input is set' , ( ) => {
417
+ const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)' ;
435
418
testComponent . disableRipple = true ;
436
419
fixture . detectChanges ( ) ;
437
420
438
421
dispatchFakeEvent ( labelElement , 'mousedown' ) ;
439
422
dispatchFakeEvent ( labelElement , 'mouseup' ) ;
440
423
441
- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
424
+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 0 ) ;
442
425
443
426
testComponent . disableRipple = false ;
444
427
fixture . detectChanges ( ) ;
445
428
446
429
dispatchFakeEvent ( labelElement , 'mousedown' ) ;
447
430
dispatchFakeEvent ( labelElement , 'mouseup' ) ;
448
431
449
- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
432
+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
450
433
} ) ;
451
434
} ) ;
452
435
@@ -842,19 +825,20 @@ describe('MatCheckbox', () => {
842
825
} ) ;
843
826
844
827
it ( 'should toggle checkbox ripple disabledness correctly' , ( ) => {
828
+ const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)' ;
845
829
const labelElement = checkboxNativeElement . querySelector ( 'label' ) as HTMLLabelElement ;
846
830
847
831
testComponent . isDisabled = true ;
848
832
fixture . detectChanges ( ) ;
849
833
dispatchFakeEvent ( labelElement , 'mousedown' ) ;
850
834
dispatchFakeEvent ( labelElement , 'mouseup' ) ;
851
- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
835
+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 0 ) ;
852
836
853
837
testComponent . isDisabled = false ;
854
838
fixture . detectChanges ( ) ;
855
839
dispatchFakeEvent ( labelElement , 'mousedown' ) ;
856
840
dispatchFakeEvent ( labelElement , 'mouseup' ) ;
857
- expect ( checkboxNativeElement . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
841
+ expect ( checkboxNativeElement . querySelectorAll ( rippleSelector ) . length ) . toBe ( 1 ) ;
858
842
} ) ;
859
843
} ) ;
860
844
0 commit comments