@@ -3,6 +3,7 @@ import {Component, ViewChild} from '@angular/core';
3
3
import { MdRipple , MdRippleModule } from './ripple' ;
4
4
import { ViewportRuler } from '../overlay/position/viewport-ruler' ;
5
5
import { RIPPLE_FADE_OUT_DURATION , RIPPLE_FADE_IN_DURATION } from './ripple-renderer' ;
6
+ import { dispatchMouseEvent } from '../testing/dispatch-events' ;
6
7
7
8
8
9
/** Creates a DOM mouse event. */
@@ -65,15 +66,6 @@ describe('MdRipple', () => {
65
66
document . body . style . margin = originalBodyMargin ;
66
67
} ) ;
67
68
68
- function dispatchMouseEvent ( type : string , offsetX = 0 , offsetY = 0 ) {
69
- let mouseEvent = createMouseEvent ( type , {
70
- clientX : rippleTarget . clientLeft + offsetX ,
71
- clientY : rippleTarget . clientTop + offsetY
72
- } ) ;
73
-
74
- rippleTarget . dispatchEvent ( mouseEvent ) ;
75
- }
76
-
77
69
describe ( 'basic ripple' , ( ) => {
78
70
let rippleDirective : MdRipple ;
79
71
@@ -89,20 +81,20 @@ describe('MdRipple', () => {
89
81
} ) ;
90
82
91
83
it ( 'creates ripple on mousedown' , ( ) => {
92
- dispatchMouseEvent ( 'mousedown' ) ;
93
- dispatchMouseEvent ( 'mouseup' ) ;
84
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
85
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
94
86
95
87
expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
96
88
97
- dispatchMouseEvent ( 'mousedown' ) ;
98
- dispatchMouseEvent ( 'mouseup' ) ;
89
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
90
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
99
91
100
92
expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 2 ) ;
101
93
} ) ;
102
94
103
95
it ( 'removes ripple after timeout' , fakeAsync ( ( ) => {
104
- dispatchMouseEvent ( 'mousedown' ) ;
105
- dispatchMouseEvent ( 'mouseup' ) ;
96
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
97
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
106
98
107
99
expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
108
100
@@ -140,8 +132,8 @@ describe('MdRipple', () => {
140
132
let elementRect = rippleTarget . getBoundingClientRect ( ) ;
141
133
142
134
// Dispatch a ripple at the following relative coordinates (X: 50| Y: 75)
143
- dispatchMouseEvent ( 'mousedown' , 50 , 75 ) ;
144
- dispatchMouseEvent ( 'mouseup' ) ;
135
+ dispatchMouseEvent ( rippleTarget , 'mousedown' , 50 , 75 ) ;
136
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
145
137
146
138
// Calculate distance from the click to farthest edge of the ripple target.
147
139
let maxDistanceX = TARGET_WIDTH - 50 ;
@@ -174,8 +166,8 @@ describe('MdRipple', () => {
174
166
fixture . componentInstance . isDestroyed = true ;
175
167
fixture . detectChanges ( ) ;
176
168
177
- dispatchMouseEvent ( 'mousedown' ) ;
178
- dispatchMouseEvent ( 'mouseup' ) ;
169
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
170
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
179
171
180
172
expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
181
173
} ) ;
@@ -245,15 +237,10 @@ describe('MdRipple', () => {
245
237
rippleTarget . style . top = `${ elementTop } px` ;
246
238
247
239
// Simulate a keyboard-triggered click by setting event coordinates to 0.
248
- let clickEvent = createMouseEvent ( 'mousedown' , {
249
- clientX : left + elementLeft - pageScrollLeft ,
250
- clientY : top + elementTop - pageScrollTop ,
251
- screenX : left + elementLeft ,
252
- screenY : top + elementTop
253
- } ) ;
254
-
255
- rippleTarget . dispatchEvent ( clickEvent ) ;
256
- dispatchMouseEvent ( 'mouseup' ) ;
240
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ,
241
+ left + elementLeft - pageScrollLeft ,
242
+ top + elementTop - pageScrollTop
243
+ ) ;
257
244
258
245
let expectedRadius = Math . sqrt ( 250 * 250 + 125 * 125 ) ;
259
246
let expectedLeft = left - expectedRadius ;
@@ -298,8 +285,8 @@ describe('MdRipple', () => {
298
285
controller . color = backgroundColor ;
299
286
fixture . detectChanges ( ) ;
300
287
301
- dispatchMouseEvent ( 'mousedown' ) ;
302
- dispatchMouseEvent ( 'mouseup' ) ;
288
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
289
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
303
290
304
291
let ripple = rippleTarget . querySelector ( '.mat-ripple-element' ) ;
305
292
expect ( window . getComputedStyle ( ripple ) . backgroundColor ) . toBe ( backgroundColor ) ;
@@ -309,16 +296,16 @@ describe('MdRipple', () => {
309
296
controller . disabled = true ;
310
297
fixture . detectChanges ( ) ;
311
298
312
- dispatchMouseEvent ( 'mousedown' ) ;
313
- dispatchMouseEvent ( 'mouseup' ) ;
299
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
300
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
314
301
315
302
expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 0 ) ;
316
303
317
304
controller . disabled = false ;
318
305
fixture . detectChanges ( ) ;
319
306
320
- dispatchMouseEvent ( 'mousedown' ) ;
321
- dispatchMouseEvent ( 'mouseup' ) ;
307
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
308
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
322
309
323
310
expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length ) . toBe ( 1 ) ;
324
311
} ) ;
@@ -352,8 +339,8 @@ describe('MdRipple', () => {
352
339
let elementRect = rippleTarget . getBoundingClientRect ( ) ;
353
340
354
341
// Click the ripple element 50 px to the right and 75px down from its upper left.
355
- dispatchMouseEvent ( 'mousedown' , 50 , 75 ) ;
356
- dispatchMouseEvent ( 'mouseup' ) ;
342
+ dispatchMouseEvent ( rippleTarget , 'mousedown' , 50 , 75 ) ;
343
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
357
344
358
345
// Because the centered input is true, the center of the ripple should be the midpoint of the
359
346
// bounding rect. The ripple should expand to cover the rect corners, which are 150px
@@ -379,8 +366,8 @@ describe('MdRipple', () => {
379
366
let elementRect = rippleTarget . getBoundingClientRect ( ) ;
380
367
381
368
// Click the ripple element 50 px to the right and 75px down from its upper left.
382
- dispatchMouseEvent ( 'mousedown' , 50 , 75 ) ;
383
- dispatchMouseEvent ( 'mouseup' ) ;
369
+ dispatchMouseEvent ( rippleTarget , 'mousedown' , 50 , 75 ) ;
370
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
384
371
385
372
let expectedLeft = elementRect . left + 50 - customRadius ;
386
373
let expectedTop = elementRect . top + 75 - customRadius ;
0 commit comments