1
1
import { TestBed , ComponentFixture , fakeAsync , tick , inject } from '@angular/core/testing' ;
2
2
import { Component , ViewChild } from '@angular/core' ;
3
- import { MdRipple , MdRippleModule , RippleState } from './index' ;
3
+ import { MdRipple , MdRippleModule , MD_DISABLE_RIPPLES , RippleState } from './index' ;
4
4
import { ViewportRuler } from '../overlay/position/viewport-ruler' ;
5
5
import { RIPPLE_FADE_OUT_DURATION , RIPPLE_FADE_IN_DURATION } from './ripple-renderer' ;
6
6
import { dispatchMouseEvent } from '../testing/dispatch-events' ;
@@ -18,7 +18,7 @@ describe('MdRipple', () => {
18
18
19
19
beforeEach ( ( ) => {
20
20
TestBed . configureTestingModule ( {
21
- imports : [ MdRippleModule . forRoot ( ) ] ,
21
+ imports : [ MdRippleModule ] ,
22
22
declarations : [
23
23
BasicRippleContainer ,
24
24
RippleContainerWithInputBindings ,
@@ -346,6 +346,50 @@ describe('MdRipple', () => {
346
346
347
347
} ) ;
348
348
349
+ describe ( 'with ripples disabled' , ( ) => {
350
+ let rippleDirective : MdRipple ;
351
+
352
+ beforeEach ( ( ) => {
353
+ // Reset the previously configured testing module to be able to disable ripples globally.
354
+ // The testing module has been initialized in the root describe group for the ripples.
355
+ TestBed . resetTestingModule ( ) ;
356
+ TestBed . configureTestingModule ( {
357
+ imports : [ MdRippleModule ] ,
358
+ declarations : [ BasicRippleContainer ] ,
359
+ providers : [ { provide : MD_DISABLE_RIPPLES , useValue : true } ]
360
+ } ) ;
361
+ } ) ;
362
+
363
+ beforeEach ( ( ) => {
364
+ fixture = TestBed . createComponent ( BasicRippleContainer ) ;
365
+ fixture . detectChanges ( ) ;
366
+
367
+ rippleTarget = fixture . nativeElement . querySelector ( '[mat-ripple]' ) ;
368
+ rippleDirective = fixture . componentInstance . ripple ;
369
+ } ) ;
370
+
371
+ it ( 'should not show any ripples on mousedown' , ( ) => {
372
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
373
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
374
+
375
+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
376
+
377
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
378
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
379
+
380
+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
381
+ } ) ;
382
+
383
+ it ( 'should still allow manual ripples' , ( ) => {
384
+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
385
+
386
+ rippleDirective . launch ( 0 , 0 ) ;
387
+
388
+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
389
+ } ) ;
390
+
391
+ } ) ;
392
+
349
393
describe ( 'configuring behavior' , ( ) => {
350
394
let controller : RippleContainerWithInputBindings ;
351
395
let rippleComponent : MdRipple ;
0 commit comments