Skip to content

Commit 226a6e7

Browse files
committed
test(hgrid): hgrid navigation test fixes
1 parent f510c87 commit 226a6e7

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -951,13 +951,15 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
951951

952952
for (let i = start; i < end && this.igxForOf[i] !== undefined; i++) {
953953
const embView = this._embeddedViews.shift();
954-
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
955-
|| embView.rootNodes[0].nextElementSibling);
956-
const view = container.detach(0);
954+
if (!embView.destroyed) {
955+
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
956+
|| embView.rootNodes[0].nextElementSibling);
957+
const view = container.detach(0);
957958

958-
this.updateTemplateContext(embView.context, i);
959-
container.insert(view);
960-
this._embeddedViews.push(embView);
959+
this.updateTemplateContext(embView.context, i);
960+
container.insert(view);
961+
this._embeddedViews.push(embView);
962+
}
961963
}
962964
}
963965

@@ -969,13 +971,15 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
969971
const container = this.dc.instance._vcr as ViewContainerRef;
970972
for (let i = prevIndex - 1; i >= this.state.startIndex && this.igxForOf[i] !== undefined; i--) {
971973
const embView = this._embeddedViews.pop();
972-
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
973-
|| embView.rootNodes[0].nextElementSibling);
974-
const view = container.detach(container.length - 1);
975-
976-
this.updateTemplateContext(embView.context, i);
977-
container.insert(view, 0);
978-
this._embeddedViews.unshift(embView);
974+
if (!embView.destroyed) {
975+
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
976+
|| embView.rootNodes[0].nextElementSibling);
977+
const view = container.detach(container.length - 1);
978+
979+
this.updateTemplateContext(embView.context, i);
980+
container.insert(view, 0);
981+
this._embeddedViews.unshift(embView);
982+
}
979983
}
980984
}
981985

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-api.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ export class IgxHierarchicalGridAPIService extends GridBaseAPIService<GridType>
4242
}
4343

4444
public getChildGrids(inDepth?: boolean) {
45-
const allChildren: GridType [] = [];
45+
let allChildren: GridType [] = [];
4646
this.childGrids.forEach((layoutMap) => {
4747
layoutMap.forEach((grid) => {
4848
allChildren.push(grid);
4949
if (inDepth) {
5050
const children = grid.gridAPI.getChildGrids(inDepth);
51-
children.forEach((item) => {
52-
allChildren.push(item);
53-
});
51+
allChildren = allChildren.concat(children);
5452
}
5553
});
5654
});

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.navigation.spec.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('IgxHierarchicalGrid Navigation', () => {
118118
it('should allow navigating up in child grid when child grid selected cell moves outside the parent view port.', async () => {
119119
hierarchicalGrid.verticalScrollContainer.scrollTo(2);
120120
fixture.detectChanges();
121-
await wait();
121+
await wait(DEBOUNCE_TIME);
122122

123123
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
124124
const childCell = childGrid.dataRowList.toArray()[4].cells.first;
@@ -129,7 +129,7 @@ describe('IgxHierarchicalGrid Navigation', () => {
129129
const childGridContent = fixture.debugElement.queryAll(By.css(GRID_CONTENT_CLASS))[1];
130130
UIInteractions.triggerEventHandlerKeyDown('arrowup', childGridContent, false, false, false);
131131
fixture.detectChanges();
132-
await wait();
132+
await wait(DEBOUNCE_TIME);
133133
// parent should scroll up so that cell in child is in view.
134134
const currScrTop = hierarchicalGrid.verticalScrollContainer.getScroll().scrollTop;
135135
expect(prevScrTop - currScrTop).toBeGreaterThanOrEqual(childGrid.rowHeight);
@@ -189,7 +189,7 @@ describe('IgxHierarchicalGrid Navigation', () => {
189189

190190
it('should allow navigating to bottom in child grid when child grid target row moves outside the parent view port.', async () => {
191191
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
192-
const childCell = childGrid.dataRowList.toArray()[0].cells.toArray()[0];
192+
const childCell = childGrid.dataRowList.first.cells.first;
193193
GridFunctions.focusCell(fixture, childCell);
194194

195195
const childGridContent = fixture.debugElement.queryAll(By.css(GRID_CONTENT_CLASS))[1];
@@ -244,16 +244,16 @@ describe('IgxHierarchicalGrid Navigation', () => {
244244
it('should allow navigating to top in child grid when child grid target row moves outside the parent view port.', async () => {
245245
hierarchicalGrid.verticalScrollContainer.scrollTo(2);
246246
fixture.detectChanges();
247-
await wait();
247+
await wait(DEBOUNCE_TIME);
248248

249249
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
250250
const childLastRowCell = childGrid.dataRowList.toArray()[9].cells.first;
251+
const childGridContent = fixture.debugElement.queryAll(By.css(GRID_CONTENT_CLASS))[1];
251252
GridFunctions.focusCell(fixture, childLastRowCell);
252253

253-
const childGridContent = fixture.debugElement.queryAll(By.css(GRID_CONTENT_CLASS))[1];
254254
UIInteractions.triggerEventHandlerKeyDown('arrowup', childGridContent, false, false, true);
255255
fixture.detectChanges();
256-
await wait();
256+
await wait(DEBOUNCE_TIME);
257257

258258
const childFirstRowCell = childGrid.dataRowList.first.cells.first;
259259
const selectedCell = fixture.componentInstance.selectedCell;
@@ -271,20 +271,20 @@ describe('IgxHierarchicalGrid Navigation', () => {
271271
});
272272

273273
it('should scroll top of child grid into view when pressing Ctrl + Arrow Up when cell is selected in it.', async () => {
274-
hierarchicalGrid.verticalScrollContainer.scrollTo(7);
274+
hierarchicalGrid.verticalScrollContainer.scrollTo(2);
275275
fixture.detectChanges();
276-
await wait();
276+
await wait(DEBOUNCE_TIME);
277277

278-
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[3];
279-
const childLastRowCell = childGrid.dataRowList.toArray()[9].cells.toArray()[0];
278+
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
279+
const childLastRowCell = childGrid.dataRowList.toArray()[9].cells.first;
280280
const childGridContent = fixture.debugElement.queryAll(By.css(GRID_CONTENT_CLASS))[1];
281281
GridFunctions.focusCell(fixture, childLastRowCell);
282282

283283
UIInteractions.triggerEventHandlerKeyDown('arrowup', childGridContent, false, false, true);
284284
fixture.detectChanges();
285-
await wait();
285+
await wait(DEBOUNCE_TIME);
286286

287-
const childFirstRowCell = childGrid.dataRowList.toArray()[0].cells.toArray()[0];
287+
const childFirstRowCell = childGrid.dataRowList.first.cells.first;
288288
const selectedCell = fixture.componentInstance.selectedCell;
289289
expect(selectedCell.row.index).toBe(childFirstRowCell.row.index);
290290
expect(selectedCell.column.visibleIndex).toBe(childFirstRowCell.column.visibleIndex);
@@ -296,18 +296,17 @@ describe('IgxHierarchicalGrid Navigation', () => {
296296
const rowElem = childGrid.gridAPI.get_row_by_index(selectedCell.row.index);
297297
const rowOffsets = rowElem.nativeElement.getBoundingClientRect();
298298
expect(rowOffsets.top).toBeGreaterThanOrEqual(gridOffsets.top);
299-
// expect(rowOffsets.bottom).toBeLessThanOrEqual(gridOffsets.bottom);
299+
expect(rowOffsets.bottom).toBeLessThanOrEqual(gridOffsets.bottom);
300300
});
301301

302302
it('when navigating down from parent into child should scroll child grid to top and start navigation from first row.', async () => {
303303
const ri = fixture.componentInstance.rowIsland;
304304
ri.height = '200px';
305305
fixture.detectChanges();
306-
await wait();
307306

308307
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
309308
childGrid.verticalScrollContainer.scrollTo(9);
310-
await wait();
309+
await wait(DEBOUNCE_TIME);
311310
fixture.detectChanges();
312311

313312
let currScrTop = childGrid.verticalScrollContainer.getScroll().scrollTop;
@@ -317,7 +316,7 @@ describe('IgxHierarchicalGrid Navigation', () => {
317316
GridFunctions.focusCell(fixture, fCell);
318317

319318
UIInteractions.triggerEventHandlerKeyDown('arrowdown', baseHGridContent, false, false, false);
320-
await wait(DEBOUNCE_TIME * 3);
319+
await wait(DEBOUNCE_TIME);
321320
fixture.detectChanges();
322321

323322
const childFirstCell = childGrid.dataRowList.toArray()[0].cells.toArray()[0];
@@ -368,7 +367,7 @@ describe('IgxHierarchicalGrid Navigation', () => {
368367
it('if next child cell is not in view should scroll parent so that it is in view.', async () => {
369368
hierarchicalGrid.verticalScrollContainer.scrollTo(4);
370369
fixture.detectChanges();
371-
await wait();
370+
await wait(DEBOUNCE_TIME);
372371

373372
const parentCell = hierarchicalGrid.dataRowList.toArray()[0].cells.toArray()[0];
374373
GridFunctions.focusCell(fixture, parentCell);
@@ -410,11 +409,11 @@ describe('IgxHierarchicalGrid Navigation', () => {
410409
const lastDataIndex = hierarchicalGrid.dataView.length - 2;
411410
hierarchicalGrid.verticalScrollContainer.scrollTo(lastDataIndex);
412411
fixture.detectChanges();
413-
await wait();
412+
await wait(DEBOUNCE_TIME);
414413

415414
hierarchicalGrid.verticalScrollContainer.scrollTo(lastDataIndex);
416415
fixture.detectChanges();
417-
await wait();
416+
await wait(DEBOUNCE_TIME);
418417

419418
let parentCell = hierarchicalGrid.gridAPI.get_cell_by_index(38, 'ID');
420419
GridFunctions.focusCell(fixture, parentCell);
@@ -786,8 +785,8 @@ describe('IgxHierarchicalGrid Navigation', () => {
786785

787786
it('should allow navigating down between sibling child grids.', async () => {
788787
hierarchicalGrid.verticalScrollContainer.scrollTo(2);
788+
await wait(DEBOUNCE_TIME);
789789
fixture.detectChanges();
790-
await wait();
791790

792791
const child1 = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
793792
const child2 = hierarchicalGrid.gridAPI.getChildGrids(false)[5];

0 commit comments

Comments
 (0)