11import { TestBed , ComponentFixture , fakeAsync , tick , inject } from '@angular/core/testing' ;
22import { Component , ViewChild } from '@angular/core' ;
3- import { MdRipple , MdRippleModule , RippleState } from './index' ;
3+ import { MdRipple , MdRippleModule , MD_DISABLE_RIPPLES , RippleState } from './index' ;
44import { ViewportRuler } from '../overlay/position/viewport-ruler' ;
55import { RIPPLE_FADE_OUT_DURATION , RIPPLE_FADE_IN_DURATION } from './ripple-renderer' ;
66import { dispatchMouseEvent } from '../testing/dispatch-events' ;
@@ -18,7 +18,7 @@ describe('MdRipple', () => {
1818
1919 beforeEach ( ( ) => {
2020 TestBed . configureTestingModule ( {
21- imports : [ MdRippleModule . forRoot ( ) ] ,
21+ imports : [ MdRippleModule ] ,
2222 declarations : [
2323 BasicRippleContainer ,
2424 RippleContainerWithInputBindings ,
@@ -346,6 +346,50 @@ describe('MdRipple', () => {
346346
347347 } ) ;
348348
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+
349393 describe ( 'configuring behavior' , ( ) => {
350394 let controller : RippleContainerWithInputBindings ;
351395 let rippleComponent : MdRipple ;
0 commit comments