Skip to content

Commit 8af9a8a

Browse files
committed
test(TreeGrid): Adding a test for order of records after hierarchizing
1 parent 7f538ff commit 8af9a8a

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,74 @@ describe('IgxTreeGrid - Integration #tGrid', () => {
198198
treeGrid = fix.componentInstance.treeGrid;
199199
});
200200

201+
it('should preserve the order of records on inner levels', () => {
202+
fix.componentInstance.sortByName = true;
203+
fix.detectChanges();
204+
treeGrid.columns[0].hidden = true;
205+
treeGrid.columns[1].hidden = true;
206+
fix.detectChanges();
207+
208+
const expectedFlatData = [
209+
{
210+
"ID": 1,
211+
"ParentID": -1,
212+
"Name": "Casey Houston",
213+
"JobTitle": "Vice President",
214+
"Age": 32
215+
},
216+
{
217+
"ID": 2,
218+
"ParentID": 1,
219+
"Name": "Gilberto Todd",
220+
"JobTitle": "Director",
221+
"Age": 41
222+
},
223+
{
224+
"ID": 7,
225+
"ParentID": 2,
226+
"Name": "Debra Morton",
227+
"JobTitle": "Associate Software Developer",
228+
"Age": 35
229+
},
230+
{
231+
"ID": 3,
232+
"ParentID": 2,
233+
"Name": "Tanya Bennett",
234+
"JobTitle": "Director",
235+
"Age": 29
236+
},
237+
{
238+
"ID": 4,
239+
"ParentID": 1,
240+
"Name": "Jack Simon",
241+
"JobTitle": "Software Developer",
242+
"Age": 33
243+
},
244+
{
245+
"ID": 10,
246+
"ParentID": -1,
247+
"Name": "Eduardo Ramirez",
248+
"JobTitle": "Manager",
249+
"Age": 53
250+
},
251+
{
252+
"ID": 9,
253+
"ParentID": 10,
254+
"Name": "Leslie Hansen",
255+
"JobTitle": "Associate Software Developer",
256+
"Age": 44
257+
},
258+
{
259+
"ID": 6,
260+
"ParentID": -1,
261+
"Name": "Erma Walsh",
262+
"JobTitle": "CEO",
263+
"Age": 52
264+
},
265+
]
266+
expect(treeGrid.flatData).toEqual(expectedFlatData);
267+
});
268+
201269
it('should transform a non-tree column into a tree column when pinning it', () => {
202270
TreeGridFunctions.verifyTreeColumn(fix, 'ID', 5);
203271

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,17 @@ export class IgxTreeGridWithNoScrollsComponent {
159159
`,
160160
imports: [IgxTreeGridComponent, IgxColumnComponent, IgxPaginatorComponent]
161161
})
162-
export class IgxTreeGridPrimaryForeignKeyComponent {
162+
export class IgxTreeGridPrimaryForeignKeyComponent implements OnInit {
163163
@ViewChild(IgxTreeGridComponent, { static: true }) public treeGrid: IgxTreeGridComponent;
164-
public data = SampleTestData.employeePrimaryForeignKeyTreeData();
164+
public data = [];
165165
public paging = false;
166+
public sortByName = false;
167+
168+
public ngOnInit(): void {
169+
this.data = !this.sortByName
170+
? SampleTestData.employeePrimaryForeignKeyTreeData()
171+
: SampleTestData.employeePrimaryForeignKeyTreeData().sort((a, b) => a.Name.localeCompare(b.Name));
172+
}
166173
}
167174

168175
@Component({

0 commit comments

Comments
 (0)