Skip to content

Commit afee6fe

Browse files
committed
test(MasterDetail): Remove unneeded asyncs and fix failing tests.
1 parent f37becc commit afee6fe

File tree

3 files changed

+68
-80
lines changed

3 files changed

+68
-80
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid-mrl-keyboard-nav.spec.ts

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -989,46 +989,6 @@ describe('IgxGrid Multi Row Layout - Keyboard navigation #grid', () => {
989989
expect(fix.componentInstance.selectedCell.column.field).toMatch('ContactName');
990990
});
991991

992-
it('should navigate correctly by pressing Ctrl + ArrowUp/ArrowDown key', () => {
993-
fix.componentInstance.colGroups = [{
994-
group: 'group1',
995-
pinned: true,
996-
columns: [
997-
{ field: 'CompanyName', rowStart: 1, colStart: 1, colEnd: 3 },
998-
{ field: 'ContactName', rowStart: 2, colStart: 1 },
999-
{ field: 'ContactTitle', rowStart: 2, colStart: 2 }
1000-
]
1001-
}];
1002-
fix.detectChanges();
1003-
1004-
let firstCell;
1005-
let secondCell;
1006-
let thirdCell;
1007-
[
1008-
firstCell, secondCell,
1009-
thirdCell,
1010-
] = fix.debugElement.queryAll(By.css(CELL_CSS_CLASS));
1011-
1012-
thirdCell.componentInstance.onFocus(null);
1013-
fix.detectChanges();
1014-
1015-
expect(fix.componentInstance.selectedCell.value).toEqual(fix.componentInstance.data[0].ContactTitle);
1016-
expect(fix.componentInstance.selectedCell.column.field).toMatch('ContactTitle');
1017-
1018-
GridFunctions.simulateCellKeydown(thirdCell.componentInstance, 'ArrowDown', false, false, true);
1019-
fix.detectChanges();
1020-
1021-
expect(fix.componentInstance.selectedCell.value)
1022-
.toEqual(fix.componentInstance.data[fix.componentInstance.data.length - 1].ContactTitle);
1023-
expect(fix.componentInstance.selectedCell.column.field).toMatch('ContactTitle');
1024-
1025-
GridFunctions.simulateCellKeydown(fix.componentInstance.selectedCell, 'ArrowUp', false, false, true);
1026-
fix.detectChanges();
1027-
1028-
expect(fix.componentInstance.selectedCell.value).toEqual(fix.componentInstance.data[0].ContactTitle);
1029-
expect(fix.componentInstance.selectedCell.column.field).toMatch('ContactTitle');
1030-
});
1031-
1032992
it('should navigate correctly with column group is hidden.', () => {
1033993
fix.componentInstance.colGroups = [{
1034994
group: 'group1',
@@ -1858,6 +1818,56 @@ describe('IgxGrid Multi Row Layout - Keyboard navigation #grid', () => {
18581818
expect(fix.componentInstance.selectedCell.column.field).toMatch('City');
18591819
});
18601820

1821+
it('should navigate correctly by pressing Ctrl + ArrowUp/ArrowDown key', async() => {
1822+
fix.componentInstance.colGroups = [{
1823+
group: 'group1',
1824+
pinned: true,
1825+
columns: [
1826+
{ field: 'CompanyName', rowStart: 1, colStart: 1, colEnd: 3 },
1827+
{ field: 'ContactName', rowStart: 2, colStart: 1 },
1828+
{ field: 'ContactTitle', rowStart: 2, colStart: 2 }
1829+
]
1830+
}];
1831+
fix.detectChanges();
1832+
1833+
let firstCell;
1834+
let secondCell;
1835+
let thirdCell;
1836+
[
1837+
firstCell, secondCell,
1838+
thirdCell,
1839+
] = fix.debugElement.queryAll(By.css(CELL_CSS_CLASS));
1840+
1841+
thirdCell.componentInstance.onFocus(null);
1842+
fix.detectChanges();
1843+
1844+
expect(fix.componentInstance.selectedCell.value).toEqual(fix.componentInstance.data[0].ContactTitle);
1845+
expect(fix.componentInstance.selectedCell.column.field).toMatch('ContactTitle');
1846+
1847+
GridFunctions.simulateCellKeydown(thirdCell.componentInstance, 'ArrowDown', false, false, true);
1848+
await wait();
1849+
zone.simulateOnStable();
1850+
fix.detectChanges();
1851+
await wait();
1852+
zone.simulateOnStable();
1853+
fix.detectChanges();
1854+
1855+
expect(fix.componentInstance.selectedCell.value)
1856+
.toEqual(fix.componentInstance.data[fix.componentInstance.data.length - 1].ContactTitle);
1857+
expect(fix.componentInstance.selectedCell.column.field).toMatch('ContactTitle');
1858+
1859+
GridFunctions.simulateCellKeydown(fix.componentInstance.selectedCell, 'ArrowUp', false, false, true);
1860+
await wait();
1861+
zone.simulateOnStable();
1862+
fix.detectChanges();
1863+
await wait();
1864+
zone.simulateOnStable();
1865+
fix.detectChanges();
1866+
1867+
expect(fix.componentInstance.selectedCell.value).toEqual(fix.componentInstance.data[0].ContactTitle);
1868+
expect(fix.componentInstance.selectedCell.column.field).toMatch('ContactTitle');
1869+
});
1870+
18611871
it('should navigate to the last cell from the layout by pressing Home/End or Ctrl + ArrowLeft/ArrowRight key', async() => {
18621872
fix.componentInstance.colGroups = [{
18631873
group: 'group1',

projects/igniteui-angular/src/lib/grids/grid/grid.master-detail.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ describe('IgxGrid Master Detail #grid', () => {
5656
expect(grid.rowList.length).toEqual(expandIcons.length);
5757
});
5858

59-
it('Should correctly expand a basic detail view, update expansionStates and the context provided should be correct', async() => {
59+
it('Should correctly expand a basic detail view, update expansionStates and the context provided should be correct', () => {
6060
GridFunctions.toggleMasterRow(fix, grid.rowList.first);
61-
await wait();
6261
fix.detectChanges();
6362

6463
const firstRowIconName = GridFunctions.getRowExpandIconName(grid.rowList.first);
@@ -70,9 +69,8 @@ describe('IgxGrid Master Detail #grid', () => {
7069
expect(getDetailAddressText(firstRowDetail)).toEqual('Obere Str. 57');
7170
});
7271

73-
it('Should render a detail view with dynamic elements and they should be clickable/focusable.', async() => {
72+
it('Should render a detail view with dynamic elements and they should be clickable/focusable.', () => {
7473
GridFunctions.toggleMasterRow(fix, grid.rowList.first);
75-
await wait();
7674
fix.detectChanges();
7775

7876
const firstDetail = GridFunctions.getMasterRowDetailDebug(fix, grid.rowList.first);
@@ -102,7 +100,6 @@ describe('IgxGrid Master Detail #grid', () => {
102100
it(`Should persist state of rendered templates, such as expansion state of expansion panel,
103101
checkbox state, etc. after scrolling them in and out of view.`, (async() => {
104102
GridFunctions.toggleMasterRow(fix, grid.rowList.first);
105-
await wait();
106103
fix.detectChanges();
107104

108105
let firstDetail = GridFunctions.getMasterRowDetailDebug(fix, grid.rowList.first);
@@ -144,9 +141,8 @@ describe('IgxGrid Master Detail #grid', () => {
144141
}));
145142

146143
it(`Should persist state of rendered templates, such as expansion state of expansion panel,
147-
checkbox state, etc. after scrolling them in and out of view.`, async() => {
144+
checkbox state, etc. after scrolling them in and out of view.`, () => {
148145
GridFunctions.toggleMasterRow(fix, grid.rowList.first);
149-
await wait();
150146
fix.detectChanges();
151147

152148
let firstRowDetail = GridFunctions.getMasterRowDetailDebug(fix, grid.rowList.first);
@@ -163,11 +159,9 @@ describe('IgxGrid Master Detail #grid', () => {
163159
fix.detectChanges();
164160

165161
GridFunctions.toggleMasterRow(fix, grid.rowList.first);
166-
await wait();
167162
fix.detectChanges();
168163

169164
GridFunctions.toggleMasterRow(fix, grid.rowList.first);
170-
await wait();
171165
fix.detectChanges();
172166

173167
firstRowDetail = GridFunctions.getMasterRowDetailDebug(fix, grid.rowList.first);
@@ -397,6 +391,9 @@ describe('IgxGrid Master Detail #grid', () => {
397391
const row = grid.getRowByIndex(6) as IgxGridRowComponent;
398392
const targetCellElement = grid.getCellByColumn(6, 'ContactName');
399393

394+
targetCellElement.onFocus(null);
395+
fix.detectChanges();
396+
400397
GridFunctions.simulateCellKeydown(targetCellElement, 'ArrowDown');
401398
await wait();
402399
fix.detectChanges();
@@ -536,6 +533,7 @@ describe('IgxGrid Master Detail #grid', () => {
536533
await wait(DEBOUNCETIME);
537534
fix.detectChanges();
538535
await wait(DEBOUNCETIME);
536+
fix.detectChanges();
539537

540538
expect(row.expanded).toBeFalsy();
541539
targetCellElement = grid.getCellByColumn(52, 'ContactName');
@@ -546,6 +544,7 @@ describe('IgxGrid Master Detail #grid', () => {
546544
await wait(DEBOUNCETIME);
547545
fix.detectChanges();
548546
await wait(DEBOUNCETIME);
547+
fix.detectChanges();
549548

550549
expect(row.expanded).toBeTruthy();
551550
targetCellElement = grid.getCellByColumn(52, 'ContactName');
@@ -987,7 +986,6 @@ describe('IgxGrid Master Detail #grid', () => {
987986
grid = fix.componentInstance.grid;
988987

989988
GridFunctions.toggleMasterRow(fix, grid.rowList.first);
990-
await wait();
991989
fix.detectChanges();
992990
});
993991

@@ -1012,7 +1010,7 @@ describe('IgxGrid Master Detail #grid', () => {
10121010
});
10131011

10141012
it(`Should navigate down through a detail view by focusing the whole row and continuing
1015-
onto the next with arrow down in multi-row layout grid.`, () => {
1013+
onto the next with arrow down in multi-row layout grid.`, async() => {
10161014
let targetCellElement = grid.getCellByColumn(0, 'ContactName');
10171015
GridFunctions.simulateCellKeydown(targetCellElement, 'ArrowDown');
10181016
fix.detectChanges();
@@ -1027,16 +1025,18 @@ describe('IgxGrid Master Detail #grid', () => {
10271025
expect(document.activeElement).toBe(firstRowDetail);
10281026

10291027
GridFunctions.simulateDetailKeydown(grid, grid.rowList.first, 'ArrowDown');
1028+
await wait();
10301029
fix.detectChanges();
10311030

10321031
targetCellElement = grid.getCellByColumn(2, 'CompanyName');
10331032
expect(targetCellElement.focused).toBeTruthy();
10341033
});
10351034

10361035
it(`Should navigate up through a detail view by
1037-
focusing the whole row and continuing onto the next with arrow up in multi-row layout grid.`, () => {
1036+
focusing the whole row and continuing onto the next with arrow up in multi-row layout grid.`, async() => {
10381037
let targetCellElement = grid.getCellByColumn(2, 'ContactName');
10391038
GridFunctions.simulateCellKeydown(targetCellElement, 'ArrowUp');
1039+
await wait();
10401040
fix.detectChanges();
10411041

10421042
targetCellElement = grid.getCellByColumn(2, 'CompanyName');

projects/igniteui-angular/src/lib/test-utils/grid-functions.spec.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -195,32 +195,6 @@ export class GridFunctions {
195195
resolve();
196196
})
197197

198-
public static simulateCellKeydown(cellComp: IgxGridCellComponent, keyName: string,
199-
altKey = false, shiftKey = false, ctrlKey = false) {
200-
const keyboardEvent = new KeyboardEvent('keydown', {
201-
key: keyName,
202-
shiftKey: shiftKey,
203-
ctrlKey: ctrlKey,
204-
altKey: altKey
205-
});
206-
cellComp.dispatchEvent(keyboardEvent);
207-
if (!altKey) {
208-
cellComp.onBlur();
209-
}
210-
}
211-
212-
public static simulateGroupRowKeydown(rowComp: IgxGridGroupByRowComponent, keyName: string,
213-
altKey = false, shiftKey = false, ctrlKey = false) {
214-
const keyboardEvent = new KeyboardEvent('keydown', {
215-
key: keyName,
216-
shiftKey: shiftKey,
217-
ctrlKey: ctrlKey,
218-
altKey: altKey
219-
});
220-
rowComp.onKeydown(keyboardEvent);
221-
rowComp.onBlur();
222-
}
223-
224198
public static simulateDetailKeydown(grid: IgxGridComponent, masterRow: IgxGridRowComponent, keyName: string,
225199
altKey = false, shiftKey = false, ctrlKey = false) {
226200
const detailRow = GridFunctions.getMasterRowDetail(masterRow);
@@ -1782,7 +1756,9 @@ export class GridFunctions {
17821756
altKey: altKey
17831757
});
17841758
cellComp.dispatchEvent(keyboardEvent);
1785-
cellComp.onBlur();
1759+
if (!altKey) {
1760+
cellComp.onBlur();
1761+
}
17861762
}
17871763

17881764
public static simulateGroupRowKeydown(rowComp: IgxGridGroupByRowComponent, keyName: string,
@@ -1794,7 +1770,9 @@ export class GridFunctions {
17941770
altKey: altKey
17951771
});
17961772
rowComp.onKeydown(keyboardEvent);
1797-
rowComp.onBlur();
1773+
if (!altKey) {
1774+
rowComp.onBlur();
1775+
}
17981776
}
17991777
}
18001778
export class GridSummaryFunctions {

0 commit comments

Comments
 (0)