@@ -10,6 +10,7 @@ import { IgxIconModule } from '../icon/index';
10
10
import { IgxChipsModule } from './chips.module' ;
11
11
import { IgxChipComponent } from './chip.component' ;
12
12
import { IgxChipsAreaComponent } from './chips-area.component' ;
13
+ import { UIInteractions } from '../test-utils/ui-interactions.spec' ;
13
14
14
15
@Component ( {
15
16
template : `
@@ -133,22 +134,6 @@ describe('IgxChipsArea', () => {
133
134
} ) . compileComponents ( ) ;
134
135
} ) ) ;
135
136
136
- function simulatePointerEvent ( eventName : string , element , x , y ) {
137
- const options : PointerEventInit = {
138
- view : window ,
139
- bubbles : true ,
140
- cancelable : true ,
141
- pointerId : 1
142
- } ;
143
- const pointerEvent = new PointerEvent ( eventName , options ) ;
144
- Object . defineProperty ( pointerEvent , 'pageX' , { value : x , enumerable : true } ) ;
145
- Object . defineProperty ( pointerEvent , 'pageY' , { value : y , enumerable : true } ) ;
146
- return new Promise ( ( resolve , reject ) => {
147
- element . dispatchEvent ( pointerEvent ) ;
148
- resolve ( ) ;
149
- } ) ;
150
- }
151
-
152
137
it ( 'should add chips when adding data items ' , ( ) => {
153
138
const fix = TestBed . createComponent ( TestChipComponent ) ;
154
139
fix . detectChanges ( ) ;
@@ -212,12 +197,12 @@ describe('IgxChipsArea', () => {
212
197
const startingX = ( startingLeft + startingRight ) / 2 ;
213
198
const startingY = ( startingTop + startingBottom ) / 2 ;
214
199
215
- simulatePointerEvent ( 'pointerdown' , firstChipElem , startingX , startingY ) ;
200
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , firstChipElem , startingX , startingY ) ;
216
201
fix . detectChanges ( ) ;
217
202
218
203
fix . whenStable ( ) . then ( ( ) => {
219
204
fix . detectChanges ( ) ;
220
- simulatePointerEvent ( 'pointermove' , firstChipElem , startingX + 10 , startingY + 10 ) ;
205
+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChipElem , startingX + 10 , startingY + 10 ) ;
221
206
222
207
return fix . whenStable ( ) ;
223
208
} ) . then ( ( ) => {
@@ -247,17 +232,17 @@ describe('IgxChipsArea', () => {
247
232
const startingX = ( startingLeft + startingRight ) / 2 ;
248
233
const startingY = ( startingTop + startingBottom ) / 2 ;
249
234
250
- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
235
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
251
236
fix . detectChanges ( ) ;
252
237
253
238
fix . whenStable ( ) . then ( ( ) => {
254
239
fix . detectChanges ( ) ;
255
- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
240
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
256
241
257
242
return fix . whenStable ( ) ;
258
243
} ) . then ( ( ) => {
259
244
fix . detectChanges ( ) ;
260
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
245
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
261
246
262
247
setTimeout ( ( ) => {
263
248
const afterDragTop = secondChip . dragDir [ '_dragGhost' ] . getBoundingClientRect ( ) . top ;
@@ -287,17 +272,17 @@ describe('IgxChipsArea', () => {
287
272
const startingX = ( startingLeft + startingRight ) / 2 ;
288
273
const startingY = ( startingTop + startingBottom ) / 2 ;
289
274
290
- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
275
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
291
276
fix . detectChanges ( ) ;
292
277
293
278
fix . whenStable ( ) . then ( ( ) => {
294
279
fix . detectChanges ( ) ;
295
- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
280
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
296
281
297
282
return fix . whenStable ( ) ;
298
283
} ) . then ( ( ) => {
299
284
fix . detectChanges ( ) ;
300
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
285
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
301
286
fix . detectChanges ( ) ;
302
287
303
288
setTimeout ( ( ) => {
@@ -330,23 +315,23 @@ describe('IgxChipsArea', () => {
330
315
331
316
const firstChip = chipComponents [ 0 ] ;
332
317
333
- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
318
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
334
319
fix . detectChanges ( ) ;
335
320
336
321
fix . whenStable ( ) . then ( ( ) => {
337
322
fix . detectChanges ( ) ;
338
- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
323
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
339
324
340
325
return fix . whenStable ( ) ;
341
326
} ) . then ( ( ) => {
342
327
fix . detectChanges ( ) ;
343
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
328
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
344
329
fix . detectChanges ( ) ;
345
330
346
331
return fix . whenRenderingDone ( ) ;
347
332
} ) . then ( ( ) => {
348
333
expect ( firstChip . nativeElement . children [ 1 ] . style . visibility ) . toEqual ( 'hidden' ) ;
349
- simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
334
+ UIInteractions . simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
350
335
return fix . whenRenderingDone ( ) ;
351
336
} ) . then ( ( ) => {
352
337
expect ( firstChip . nativeElement . children [ 1 ] . style . visibility ) . toEqual ( 'visible' ) ;
@@ -385,22 +370,22 @@ describe('IgxChipsArea', () => {
385
370
const secondChipX = ( secondChipLeft + secondChipRight ) / 2 ;
386
371
const secondChipY = ( secondChipTop + secondChipBottom ) / 2 ;
387
372
388
- simulatePointerEvent ( 'pointerdown' , firstChipElem , firstChipX , firstChipY ) ;
373
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , firstChipElem , firstChipX , firstChipY ) ;
389
374
fix . detectChanges ( ) ;
390
375
391
376
fix . whenStable ( ) . then ( ( ) => {
392
377
fix . detectChanges ( ) ;
393
- simulatePointerEvent ( 'pointermove' , firstChipElem , firstChipX + 10 , firstChipY + 10 ) ;
378
+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChipElem , firstChipX + 10 , firstChipY + 10 ) ;
394
379
395
380
return fix . whenStable ( ) ;
396
381
} ) . then ( ( ) => {
397
382
fix . detectChanges ( ) ;
398
- simulatePointerEvent ( 'pointermove' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
383
+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
399
384
fix . detectChanges ( ) ;
400
385
401
386
return fix . whenRenderingDone ( ) ;
402
387
} ) . then ( ( ) => {
403
- simulatePointerEvent ( 'pointerup' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
388
+ UIInteractions . simulatePointerEvent ( 'pointerup' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
404
389
return fix . whenRenderingDone ( ) ;
405
390
} ) . then ( ( ) => {
406
391
setTimeout ( ( ) => {
@@ -445,22 +430,22 @@ describe('IgxChipsArea', () => {
445
430
const secondChipX = ( secondChipLeft + secondChipRight ) / 2 ;
446
431
const secondChipY = ( secondChipTop + secondChipBottom ) / 2 ;
447
432
448
- simulatePointerEvent ( 'pointerdown' , secondChipElem , secondChipX , secondChipY ) ;
433
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , secondChipX , secondChipY ) ;
449
434
fix . detectChanges ( ) ;
450
435
451
436
fix . whenStable ( ) . then ( ( ) => {
452
437
fix . detectChanges ( ) ;
453
- simulatePointerEvent ( 'pointermove' , secondChipElem , secondChipX + 10 , secondChipY + 10 ) ;
438
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , secondChipX + 10 , secondChipY + 10 ) ;
454
439
455
440
return fix . whenStable ( ) ;
456
441
} ) . then ( ( ) => {
457
442
fix . detectChanges ( ) ;
458
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
443
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
459
444
fix . detectChanges ( ) ;
460
445
461
446
return fix . whenRenderingDone ( ) ;
462
447
} ) . then ( ( ) => {
463
- simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
448
+ UIInteractions . simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
464
449
return fix . whenRenderingDone ( ) ;
465
450
} ) . then ( ( ) => {
466
451
setTimeout ( ( ) => {
@@ -858,20 +843,30 @@ describe('IgxChipsArea', () => {
858
843
859
844
expect ( secondChip . selected ) . toBeTruthy ( ) ;
860
845
861
- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
846
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
862
847
fix . detectChanges ( ) ;
863
848
864
849
fix . whenStable ( ) . then ( ( ) => {
865
- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
850
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
866
851
867
852
return fix . whenStable ( ) ;
868
853
} ) . then ( ( ) => {
869
854
fix . detectChanges ( ) ;
870
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
855
+ UIInteractions . simulatePointerEvent (
856
+ 'pointermove' ,
857
+ secondChip . dragDir [ '_dragGhost' ] ,
858
+ startingX + xDragDifference ,
859
+ startingY + yDragDifference
860
+ ) ;
871
861
872
862
expect ( secondChip . selected ) . toBeTruthy ( ) ;
873
863
874
- simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
864
+ UIInteractions . simulatePointerEvent (
865
+ 'pointerup' ,
866
+ secondChip . dragDir [ '_dragGhost' ] ,
867
+ startingX + xDragDifference ,
868
+ startingY + yDragDifference
869
+ ) ;
875
870
fix . detectChanges ( ) ;
876
871
return fix . whenStable ( ) ;
877
872
} )
0 commit comments