Skip to content

Commit 056cc44

Browse files
committed
test(IgxGrid): verify that getRowData method returns correctly #7930
1 parent d0c3c30 commit 056cc44

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

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

+32
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,39 @@ describe('IgxGrid Component Tests #grid', () => {
16371637
scrollPosition: grid.headerContainer.getScrollForIndex(6, true),
16381638
event: horizontalScrollEvent
16391639
});
1640+
});
1641+
1642+
it(`Verify that getRowData returns correct data`, () => {
1643+
const fix = TestBed.createComponent(IgxGridDefaultRenderingComponent);
1644+
fix.componentInstance.initColumnsRows(5, 5);
1645+
fix.detectChanges();
1646+
1647+
const grid = fix.componentInstance.grid;
1648+
const cols = fix.componentInstance.columns;
1649+
1650+
const row = {'col0': 0, 'col1': 4, 'col2': 8, 'col3': 12, 'col4': 16};
1651+
const secondRow = {'col0': 0, 'col1': 1, 'col2': 2, 'col3': 3, 'col4': 4};
1652+
1653+
expect(grid.getRowData(row)).toEqual(row);
1654+
1655+
grid.primaryKey = 'col1';
1656+
fix.detectChanges();
1657+
1658+
expect(grid.getRowData(4)).toEqual(row);
1659+
1660+
grid.filter(cols[1].key, 2, IgxNumberFilteringOperand.instance().condition('greaterThan'));
1661+
fix.detectChanges();
1662+
1663+
expect(grid.getRowData(4)).toEqual(row);
1664+
expect(grid.getRowData(1)).toEqual(secondRow);
1665+
expect(grid.getRowData(7)).toEqual({});
1666+
1667+
grid.sort({ fieldName: 'col2', dir: SortingDirection.Desc, ignoreCase: true });
1668+
fix.detectChanges();
16401669

1670+
expect(grid.getRowData(4)).toEqual(row);
1671+
expect(grid.getRowData(1)).toEqual(secondRow);
1672+
expect(grid.getRowData(7)).toEqual({});
16411673
});
16421674
});
16431675

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

+20
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,26 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
225225
fixture.detectChanges();
226226
expect(childGrid.getCellByColumn(0, 'ProductName').nativeElement.innerText).toEqual('Product: A0');
227227
}));
228+
229+
it('should return correctly the rowData', () => {
230+
hierarchicalGrid.primaryKey = 'ID';
231+
fixture.detectChanges();
232+
233+
const rowData = hierarchicalGrid.getRowByKey('2').rowData;
234+
expect(hierarchicalGrid.getRowData('2')).toEqual(rowData);
235+
236+
hierarchicalGrid.sort({ fieldName: 'ChildLevels', dir: SortingDirection.Desc, ignoreCase: true });
237+
fixture.detectChanges();
238+
239+
expect(hierarchicalGrid.getRowData('2')).toEqual(rowData);
240+
expect(hierarchicalGrid.getRowData('101')).toEqual({});
241+
242+
hierarchicalGrid.filter('ID', '1', IgxStringFilteringOperand.instance().condition('startsWith'));
243+
fixture.detectChanges();
244+
245+
expect(hierarchicalGrid.getRowData('2')).toEqual(rowData);
246+
expect(hierarchicalGrid.getRowData('101')).toEqual({});
247+
});
228248
});
229249

230250
describe('Sorting', () => {

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-integration.spec.ts

+34
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,40 @@ describe('IgxTreeGrid - Integration #tGrid', () => {
11701170
expect(() => grid.addRow(grid.data, 1)).toThrow(Error(`Cannot add child row to deleted parent row`));
11711171
expect(grid.transactions.getTransactionLog().length).toBe(1);
11721172
}));
1173+
1174+
it('should return correctly the rowData', fakeAsync(() => {
1175+
const fixture = TestBed.createComponent(IgxTreeGridRowEditingTransactionComponent);
1176+
const grid = (fixture as ComponentFixture<IgxTreeGridRowEditingTransactionComponent>).componentInstance.treeGrid;
1177+
grid.cascadeOnDelete = false;
1178+
tick();
1179+
fixture.detectChanges();
1180+
1181+
const row = {'ID': 2, 'ParentID': 1, 'Name': 'Gilberto Todd', 'JobTitle': 'Director', 'Age': 41};
1182+
expect(grid.getRowData(2)).toEqual(row);
1183+
1184+
grid.sort({ fieldName: 'Age', dir: SortingDirection.Desc, ignoreCase: true });
1185+
fixture.detectChanges();
1186+
1187+
expect(grid.getRowData(2)).toEqual(row);
1188+
expect(grid.getRowData(11)).toEqual({});
1189+
1190+
grid.filter('Age', 43, IgxNumberFilteringOperand.instance().condition('greaterThan'));
1191+
fixture.detectChanges();
1192+
1193+
expect(grid.getRowData(2)).toEqual(row);
1194+
expect(grid.getRowData(11)).toEqual({});
1195+
1196+
const newRow = {'ID': 11, 'ParentID': 1, 'Name': 'Joe Peterson', 'JobTitle': 'Manager', 'Age': 37};
1197+
grid.addRow(newRow);
1198+
fixture.detectChanges();
1199+
1200+
grid.clearFilter();
1201+
tick();
1202+
fixture.detectChanges();
1203+
1204+
expect(grid.transactions.getTransactionLog().length).toEqual(1);
1205+
expect(grid.getRowData(11)).toEqual(newRow);
1206+
}));
11731207
});
11741208

11751209
describe('Multi-column header', () => {

0 commit comments

Comments
 (0)