|
1 | 1 | import {TestBed, ComponentFixture, fakeAsync, tick, inject} from '@angular/core/testing';
|
2 | 2 | import {Component, ViewChild} from '@angular/core';
|
3 |
| -import {MdRipple, MdRippleModule} from './index'; |
| 3 | +import {MdRipple, MdRippleModule, 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';
|
@@ -77,6 +77,39 @@ describe('MdRipple', () => {
|
77 | 77 | expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
|
78 | 78 | }));
|
79 | 79 |
|
| 80 | + it('should remove ripples after mouseup', fakeAsync(() => { |
| 81 | + dispatchMouseEvent(rippleTarget, 'mousedown'); |
| 82 | + |
| 83 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 84 | + |
| 85 | + // Fakes the duration of fading-in and fading-out normal ripples. |
| 86 | + // The fade-out duration has been added to ensure that didn't start fading out. |
| 87 | + tick(RIPPLE_FADE_IN_DURATION + RIPPLE_FADE_OUT_DURATION); |
| 88 | + |
| 89 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 90 | + |
| 91 | + dispatchMouseEvent(rippleTarget, 'mouseup'); |
| 92 | + tick(RIPPLE_FADE_OUT_DURATION); |
| 93 | + |
| 94 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
| 95 | + })); |
| 96 | + |
| 97 | + it('should not hide ripples while animating.', fakeAsync(() => { |
| 98 | + // Calculates the duration for fading-in and fading-out the ripple. |
| 99 | + let hideDuration = RIPPLE_FADE_IN_DURATION + RIPPLE_FADE_OUT_DURATION; |
| 100 | + |
| 101 | + dispatchMouseEvent(rippleTarget, 'mousedown'); |
| 102 | + dispatchMouseEvent(rippleTarget, 'mouseup'); |
| 103 | + |
| 104 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 105 | + |
| 106 | + tick(hideDuration - 10); |
| 107 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 108 | + |
| 109 | + tick(10); |
| 110 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
| 111 | + })); |
| 112 | + |
80 | 113 | it('creates ripples when manually triggered', () => {
|
81 | 114 | expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
|
82 | 115 |
|
@@ -270,6 +303,47 @@ describe('MdRipple', () => {
|
270 | 303 | expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
|
271 | 304 | }));
|
272 | 305 |
|
| 306 | + it('should remove ripples that are not done fading-in', fakeAsync(() => { |
| 307 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
| 308 | + |
| 309 | + rippleDirective.launch(0, 0); |
| 310 | + |
| 311 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 312 | + |
| 313 | + tick(RIPPLE_FADE_IN_DURATION / 2); |
| 314 | + |
| 315 | + rippleDirective.fadeOutAll(); |
| 316 | + |
| 317 | + tick(RIPPLE_FADE_OUT_DURATION); |
| 318 | + |
| 319 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length) |
| 320 | + .toBe(0, 'Expected no ripples to be active after calling fadeOutAll.'); |
| 321 | + })); |
| 322 | + |
| 323 | + it('should properly set ripple states', fakeAsync(() => { |
| 324 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
| 325 | + |
| 326 | + let rippleRef = rippleDirective.launch(0, 0, { persistent: true }); |
| 327 | + |
| 328 | + expect(rippleRef.state).toBe(RippleState.FADING_IN); |
| 329 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 330 | + |
| 331 | + tick(RIPPLE_FADE_IN_DURATION); |
| 332 | + |
| 333 | + expect(rippleRef.state).toBe(RippleState.VISIBLE); |
| 334 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 335 | + |
| 336 | + rippleRef.fadeOut(); |
| 337 | + |
| 338 | + expect(rippleRef.state).toBe(RippleState.FADING_OUT); |
| 339 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 340 | + |
| 341 | + tick(RIPPLE_FADE_OUT_DURATION); |
| 342 | + |
| 343 | + expect(rippleRef.state).toBe(RippleState.HIDDEN); |
| 344 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
| 345 | + })); |
| 346 | + |
273 | 347 | });
|
274 | 348 |
|
275 | 349 | describe('configuring behavior', () => {
|
|
0 commit comments