@@ -10,6 +10,7 @@ import { IgxIconModule } from '../icon/index';
1010import { IgxChipsModule } from './chips.module' ;
1111import { IgxChipComponent } from './chip.component' ;
1212import { IgxChipsAreaComponent } from './chips-area.component' ;
13+ import { UIInteractions } from '../test-utils/ui-interactions.spec' ;
1314
1415@Component ( {
1516 template : `
@@ -133,22 +134,6 @@ describe('IgxChipsArea', () => {
133134 } ) . compileComponents ( ) ;
134135 } ) ) ;
135136
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-
152137 it ( 'should add chips when adding data items ' , ( ) => {
153138 const fix = TestBed . createComponent ( TestChipComponent ) ;
154139 fix . detectChanges ( ) ;
@@ -212,12 +197,12 @@ describe('IgxChipsArea', () => {
212197 const startingX = ( startingLeft + startingRight ) / 2 ;
213198 const startingY = ( startingTop + startingBottom ) / 2 ;
214199
215- simulatePointerEvent ( 'pointerdown' , firstChipElem , startingX , startingY ) ;
200+ UIInteractions . simulatePointerEvent ( 'pointerdown' , firstChipElem , startingX , startingY ) ;
216201 fix . detectChanges ( ) ;
217202
218203 fix . whenStable ( ) . then ( ( ) => {
219204 fix . detectChanges ( ) ;
220- simulatePointerEvent ( 'pointermove' , firstChipElem , startingX + 10 , startingY + 10 ) ;
205+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChipElem , startingX + 10 , startingY + 10 ) ;
221206
222207 return fix . whenStable ( ) ;
223208 } ) . then ( ( ) => {
@@ -247,17 +232,22 @@ describe('IgxChipsArea', () => {
247232 const startingX = ( startingLeft + startingRight ) / 2 ;
248233 const startingY = ( startingTop + startingBottom ) / 2 ;
249234
250- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
235+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
251236 fix . detectChanges ( ) ;
252237
253238 fix . whenStable ( ) . then ( ( ) => {
254239 fix . detectChanges ( ) ;
255- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
240+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
256241
257242 return fix . whenStable ( ) ;
258243 } ) . then ( ( ) => {
259244 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+ ) ;
261251
262252 setTimeout ( ( ) => {
263253 const afterDragTop = secondChip . dragDir [ '_dragGhost' ] . getBoundingClientRect ( ) . top ;
@@ -287,17 +277,22 @@ describe('IgxChipsArea', () => {
287277 const startingX = ( startingLeft + startingRight ) / 2 ;
288278 const startingY = ( startingTop + startingBottom ) / 2 ;
289279
290- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
280+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
291281 fix . detectChanges ( ) ;
292282
293283 fix . whenStable ( ) . then ( ( ) => {
294284 fix . detectChanges ( ) ;
295- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
285+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
296286
297287 return fix . whenStable ( ) ;
298288 } ) . then ( ( ) => {
299289 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+ ) ;
301296 fix . detectChanges ( ) ;
302297
303298 setTimeout ( ( ) => {
@@ -330,23 +325,33 @@ describe('IgxChipsArea', () => {
330325
331326 const firstChip = chipComponents [ 0 ] ;
332327
333- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
328+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
334329 fix . detectChanges ( ) ;
335330
336331 fix . whenStable ( ) . then ( ( ) => {
337332 fix . detectChanges ( ) ;
338- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
333+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
339334
340335 return fix . whenStable ( ) ;
341336 } ) . then ( ( ) => {
342337 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+ ) ;
344344 fix . detectChanges ( ) ;
345345
346346 return fix . whenRenderingDone ( ) ;
347347 } ) . then ( ( ) => {
348348 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+ ) ;
350355 return fix . whenRenderingDone ( ) ;
351356 } ) . then ( ( ) => {
352357 expect ( firstChip . nativeElement . children [ 1 ] . style . visibility ) . toEqual ( 'visible' ) ;
@@ -385,22 +390,22 @@ describe('IgxChipsArea', () => {
385390 const secondChipX = ( secondChipLeft + secondChipRight ) / 2 ;
386391 const secondChipY = ( secondChipTop + secondChipBottom ) / 2 ;
387392
388- simulatePointerEvent ( 'pointerdown' , firstChipElem , firstChipX , firstChipY ) ;
393+ UIInteractions . simulatePointerEvent ( 'pointerdown' , firstChipElem , firstChipX , firstChipY ) ;
389394 fix . detectChanges ( ) ;
390395
391396 fix . whenStable ( ) . then ( ( ) => {
392397 fix . detectChanges ( ) ;
393- simulatePointerEvent ( 'pointermove' , firstChipElem , firstChipX + 10 , firstChipY + 10 ) ;
398+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChipElem , firstChipX + 10 , firstChipY + 10 ) ;
394399
395400 return fix . whenStable ( ) ;
396401 } ) . then ( ( ) => {
397402 fix . detectChanges ( ) ;
398- simulatePointerEvent ( 'pointermove' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
403+ UIInteractions . simulatePointerEvent ( 'pointermove' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
399404 fix . detectChanges ( ) ;
400405
401406 return fix . whenRenderingDone ( ) ;
402407 } ) . then ( ( ) => {
403- simulatePointerEvent ( 'pointerup' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
408+ UIInteractions . simulatePointerEvent ( 'pointerup' , firstChip . dragDir [ '_dragGhost' ] , secondChipX , secondChipY ) ;
404409 return fix . whenRenderingDone ( ) ;
405410 } ) . then ( ( ) => {
406411 setTimeout ( ( ) => {
@@ -445,22 +450,22 @@ describe('IgxChipsArea', () => {
445450 const secondChipX = ( secondChipLeft + secondChipRight ) / 2 ;
446451 const secondChipY = ( secondChipTop + secondChipBottom ) / 2 ;
447452
448- simulatePointerEvent ( 'pointerdown' , secondChipElem , secondChipX , secondChipY ) ;
453+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , secondChipX , secondChipY ) ;
449454 fix . detectChanges ( ) ;
450455
451456 fix . whenStable ( ) . then ( ( ) => {
452457 fix . detectChanges ( ) ;
453- simulatePointerEvent ( 'pointermove' , secondChipElem , secondChipX + 10 , secondChipY + 10 ) ;
458+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , secondChipX + 10 , secondChipY + 10 ) ;
454459
455460 return fix . whenStable ( ) ;
456461 } ) . then ( ( ) => {
457462 fix . detectChanges ( ) ;
458- simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
463+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
459464 fix . detectChanges ( ) ;
460465
461466 return fix . whenRenderingDone ( ) ;
462467 } ) . then ( ( ) => {
463- simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
468+ UIInteractions . simulatePointerEvent ( 'pointerup' , secondChip . dragDir [ '_dragGhost' ] , firstChipX , firstChipY ) ;
464469 return fix . whenRenderingDone ( ) ;
465470 } ) . then ( ( ) => {
466471 setTimeout ( ( ) => {
@@ -858,20 +863,30 @@ describe('IgxChipsArea', () => {
858863
859864 expect ( secondChip . selected ) . toBeTruthy ( ) ;
860865
861- simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
866+ UIInteractions . simulatePointerEvent ( 'pointerdown' , secondChipElem , startingX , startingY ) ;
862867 fix . detectChanges ( ) ;
863868
864869 fix . whenStable ( ) . then ( ( ) => {
865- simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
870+ UIInteractions . simulatePointerEvent ( 'pointermove' , secondChipElem , startingX + 10 , startingY + 10 ) ;
866871
867872 return fix . whenStable ( ) ;
868873 } ) . then ( ( ) => {
869874 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+ ) ;
871881
872882 expect ( secondChip . selected ) . toBeTruthy ( ) ;
873883
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+ ) ;
875890 fix . detectChanges ( ) ;
876891 return fix . whenStable ( ) ;
877892 } )
0 commit comments