Skip to content

Commit fa92efb

Browse files
authored
Merge pull request #2455 from IgniteUI/mkirova/refactoring-tests-master
chore(*): Removing duplicated functions and using the ones from the t…
2 parents d6a78ed + e90c313 commit fa92efb

File tree

4 files changed

+89
-131
lines changed

4 files changed

+89
-131
lines changed

projects/igniteui-angular/src/lib/chips/chip.spec.ts

+4-19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IgxConnectorDirective } from './connector.directive';
1414
import { IgxLabelDirective } from './../directives/label/label.directive';
1515
import { IgxSuffixDirective } from './../directives/suffix/suffix.directive';
1616
import { DisplayDensity } from 'dist/igniteui-angular/lib/core/utils';
17+
import { UIInteractions} from '../test-utils/ui-interactions.spec';
1718

1819
@Component({
1920
template: `
@@ -81,22 +82,6 @@ describe('IgxChip', () => {
8182
const CHIP_ITEM_AREA = 'igx-chip__item';
8283
const CHIP_CONNECTOR = 'igx-chip__connector';
8384

84-
function simulatePointerEvent(eventName: string, element, x, y) {
85-
const options: PointerEventInit = {
86-
view: window,
87-
bubbles: true,
88-
cancelable: true,
89-
pointerId: 1
90-
};
91-
const pointerEvent = new PointerEvent(eventName, options);
92-
Object.defineProperty(pointerEvent, 'pageX', { value: x, enumerable: true });
93-
Object.defineProperty(pointerEvent, 'pageY', { value: y, enumerable: true });
94-
return new Promise((resolve, reject) => {
95-
element.dispatchEvent(pointerEvent);
96-
resolve();
97-
});
98-
}
99-
10085
beforeEach(async(() => {
10186
TestBed.configureTestingModule({
10287
declarations: [
@@ -416,12 +401,12 @@ describe('IgxChip', () => {
416401
const startingX = (startingLeft + startingRight) / 2;
417402
const startingY = (startingTop + startingBottom) / 2;
418403

419-
simulatePointerEvent('pointerdown', thirdChipElem, startingX, startingY);
404+
UIInteractions.simulatePointerEvent('pointerdown', thirdChipElem, startingX, startingY);
420405
fix.detectChanges();
421406

422407
fix.whenStable().then(() => {
423408
fix.detectChanges();
424-
simulatePointerEvent('pointermove', thirdChipElem, startingX + 10, startingY + 10);
409+
UIInteractions.simulatePointerEvent('pointermove', thirdChipElem, startingX + 10, startingY + 10);
425410

426411
return fix.whenStable();
427412
}).then(() => {
@@ -432,7 +417,7 @@ describe('IgxChip', () => {
432417
return fix.whenStable();
433418
}).then(() => {
434419
fix.detectChanges();
435-
simulatePointerEvent('pointerup', thirdChip.dragDir['_dragGhost'], startingX + 10, startingY + 10);
420+
UIInteractions.simulatePointerEvent('pointerup', thirdChip.dragDir['_dragGhost'], startingX + 10, startingY + 10);
436421

437422
done();
438423
});

projects/igniteui-angular/src/lib/chips/chips-area.spec.ts

+55-40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IgxIconModule } from '../icon/index';
1010
import { IgxChipsModule } from './chips.module';
1111
import { IgxChipComponent } from './chip.component';
1212
import { 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
})

projects/igniteui-angular/src/lib/grid/grid-selection.spec.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IgxColumnComponent } from './column.component';
1111
import { IgxGridComponent } from './grid.component';
1212
import { IgxGridModule } from './index';
1313
import { IgxStringFilteringOperand } from '../../public_api';
14+
import { UIInteractions} from '../test-utils/ui-interactions.spec';
1415

1516
const selectedCellClass = '.igx-grid__td--selected';
1617
let data = [
@@ -26,19 +27,6 @@ let data = [
2627
{ ID: 10, Name: 'Eduardo Ramirez', JobTitle: 'Manager', HireDate: '2011-11-28T11:23:17.714Z' }
2728
];
2829

29-
function simulateKeyDown(element, key) {
30-
const keyOptions: KeyboardEventInit = {
31-
key
32-
};
33-
34-
const keypressEvent = new KeyboardEvent('keydown', keyOptions);
35-
36-
return new Promise((resolve, reject) => {
37-
element.dispatchEvent(keypressEvent);
38-
resolve();
39-
});
40-
}
41-
4230
describe('IgxGrid - Row Selection', () => {
4331

4432
beforeEach(async(() => {
@@ -202,7 +190,7 @@ describe('IgxGrid - Row Selection', () => {
202190
fix.detectChanges();
203191
expect(targetCell.focused).toEqual(true);
204192
const targetCellDebugElement = fix.debugElement.query(By.css('.igx-grid__td--selected'));
205-
simulateKeyDown(targetCellElement, 'ArrowDown').then(() => {
193+
UIInteractions.simulateKeyDownEvent(targetCellElement, 'ArrowDown').then(() => {
206194
setTimeout(() => {
207195
fix.whenStable().then(() => {
208196
fix.detectChanges();

0 commit comments

Comments
 (0)