@@ -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,22 @@ 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 (
246
+ 'pointermove' ,
247
+ secondChip . dragDir [ '_dragGhost' ] ,
248
+ startingX + xDragDifference ,
249
+ startingY + yDragDifference
250
+ ) ;
261
251
262
252
setTimeout ( ( ) => {
263
253
const afterDragTop = secondChip . dragDir [ '_dragGhost' ] . getBoundingClientRect ( ) . top ;
@@ -287,17 +277,22 @@ describe('IgxChipsArea', () => {
287
277
const startingX = ( startingLeft + startingRight ) / 2 ;
288
278
const startingY = ( startingTop + startingBottom ) / 2 ;
289
279
290
- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
280
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
291
281
fix . detectChanges ( ) ;
292
282
293
283
fix . whenStable ( ) . then ( ( ) => {
294
284
fix . detectChanges ( ) ;
295
- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
285
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
296
286
297
287
return fix . whenStable ( ) ;
298
288
} ) . then ( ( ) => {
299
289
fix . detectChanges ( ) ;
300
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
290
+ UIInteractions . simulatePointerEvent (
291
+ 'pointermove' ,
292
+ secondChip . dragDir [ '_dragGhost' ] ,
293
+ startingX + xDragDifference ,
294
+ startingY + yDragDifference
295
+ ) ;
301
296
fix . detectChanges ( ) ;
302
297
303
298
setTimeout ( ( ) => {
@@ -330,23 +325,33 @@ describe('IgxChipsArea', () => {
330
325
331
326
const firstChip = chipComponents [ 0 ] ;
332
327
333
- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
328
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
334
329
fix . detectChanges ( ) ;
335
330
336
331
fix . whenStable ( ) . then ( ( ) => {
337
332
fix . detectChanges ( ) ;
338
- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
333
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
339
334
340
335
return fix . whenStable ( ) ;
341
336
} ) . then ( ( ) => {
342
337
fix . detectChanges ( ) ;
343
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
338
+ UIInteractions . simulatePointerEvent (
339
+ 'pointermove' ,
340
+ secondChip . dragDir [ '_dragGhost' ] ,
341
+ startingX + xDragDifference ,
342
+ startingY + yDragDifference
343
+ ) ;
344
344
fix . detectChanges ( ) ;
345
345
346
346
return fix . whenRenderingDone ( ) ;
347
347
} ) . then ( ( ) => {
348
348
expect ( firstChip . nativeElement . children [ 1 ] . style . visibility ) . toEqual ( 'hidden' ) ;
349
- simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
349
+ UIInteractions . simulatePointerEvent (
350
+ 'pointerup' ,
351
+ secondChip . dragDir [ '_dragGhost' ] ,
352
+ startingX + xDragDifference ,
353
+ startingY + yDragDifference
354
+ ) ;
350
355
return fix . whenRenderingDone ( ) ;
351
356
} ) . then ( ( ) => {
352
357
expect ( firstChip . nativeElement . children [ 1 ] . style . visibility ) . toEqual ( 'visible' ) ;
@@ -385,22 +390,22 @@ describe('IgxChipsArea', () => {
385
390
const secondChipX = ( secondChipLeft + secondChipRight ) / 2 ;
386
391
const secondChipY = ( secondChipTop + secondChipBottom ) / 2 ;
387
392
388
- simulatePointerEvent ( 'pointerdown' , firstChipElem , firstChipX , firstChipY ) ;
393
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , firstChipElem , firstChipX , firstChipY ) ;
389
394
fix . detectChanges ( ) ;
390
395
391
396
fix . whenStable ( ) . then ( ( ) => {
392
397
fix . detectChanges ( ) ;
393
- simulatePointerEvent ( 'pointermove' , firstChipElem , firstChipX + 10 , firstChipY + 10 ) ;
398
+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChipElem , firstChipX + 10 , firstChipY + 10 ) ;
394
399
395
400
return fix . whenStable ( ) ;
396
401
} ) . then ( ( ) => {
397
402
fix . detectChanges ( ) ;
398
- simulatePointerEvent ( 'pointermove' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
403
+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
399
404
fix . detectChanges ( ) ;
400
405
401
406
return fix . whenRenderingDone ( ) ;
402
407
} ) . then ( ( ) => {
403
- simulatePointerEvent ( 'pointerup' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
408
+ UIInteractions . simulatePointerEvent ( 'pointerup' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
404
409
return fix . whenRenderingDone ( ) ;
405
410
} ) . then ( ( ) => {
406
411
setTimeout ( ( ) => {
@@ -445,22 +450,22 @@ describe('IgxChipsArea', () => {
445
450
const secondChipX = ( secondChipLeft + secondChipRight ) / 2 ;
446
451
const secondChipY = ( secondChipTop + secondChipBottom ) / 2 ;
447
452
448
- simulatePointerEvent ( 'pointerdown' , secondChipElem , secondChipX , secondChipY ) ;
453
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , secondChipX , secondChipY ) ;
449
454
fix . detectChanges ( ) ;
450
455
451
456
fix . whenStable ( ) . then ( ( ) => {
452
457
fix . detectChanges ( ) ;
453
- simulatePointerEvent ( 'pointermove' , secondChipElem , secondChipX + 10 , secondChipY + 10 ) ;
458
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , secondChipX + 10 , secondChipY + 10 ) ;
454
459
455
460
return fix . whenStable ( ) ;
456
461
} ) . then ( ( ) => {
457
462
fix . detectChanges ( ) ;
458
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
463
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
459
464
fix . detectChanges ( ) ;
460
465
461
466
return fix . whenRenderingDone ( ) ;
462
467
} ) . then ( ( ) => {
463
- simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
468
+ UIInteractions . simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
464
469
return fix . whenRenderingDone ( ) ;
465
470
} ) . then ( ( ) => {
466
471
setTimeout ( ( ) => {
@@ -858,20 +863,30 @@ describe('IgxChipsArea', () => {
858
863
859
864
expect ( secondChip . selected ) . toBeTruthy ( ) ;
860
865
861
- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
866
+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
862
867
fix . detectChanges ( ) ;
863
868
864
869
fix . whenStable ( ) . then ( ( ) => {
865
- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
870
+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
866
871
867
872
return fix . whenStable ( ) ;
868
873
} ) . then ( ( ) => {
869
874
fix . detectChanges ( ) ;
870
- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
875
+ UIInteractions . simulatePointerEvent (
876
+ 'pointermove' ,
877
+ secondChip . dragDir [ '_dragGhost' ] ,
878
+ startingX + xDragDifference ,
879
+ startingY + yDragDifference
880
+ ) ;
871
881
872
882
expect ( secondChip . selected ) . toBeTruthy ( ) ;
873
883
874
- simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , startingX + xDragDifference , startingY + yDragDifference ) ;
884
+ UIInteractions . simulatePointerEvent (
885
+ 'pointerup' ,
886
+ secondChip . dragDir [ '_dragGhost' ] ,
887
+ startingX + xDragDifference ,
888
+ startingY + yDragDifference
889
+ ) ;
875
890
fix . detectChanges ( ) ;
876
891
return fix . whenStable ( ) ;
877
892
} )
0 commit comments