Skip to content

Commit 4beb821

Browse files
committed
test(h-grid): fix childData and undefined errors in tests
1 parent a4b4c74 commit 4beb821

File tree

4 files changed

+71
-24
lines changed

4 files changed

+71
-24
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { QueryBuilderFunctions } from '../../query-builder/query-builder-functio
2828
import { By } from '@angular/platform-browser';
2929
import { IgxDateTimeEditorDirective } from '../../directives/date-time-editor/date-time-editor.directive';
3030
import { QueryBuilderSelectors } from '../../query-builder/query-builder.common';
31+
import { IgxHGridRemoteOnDemandComponent } from '../hierarchical-grid/hierarchical-grid.spec';
3132

3233
describe('IgxGrid - Advanced Filtering #grid - ', () => {
3334
configureTestSuite((() => {
@@ -1602,6 +1603,10 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
16021603
tick(100);
16031604
fix.detectChanges();
16041605

1606+
QueryBuilderFunctions.clickQueryBuilderExpressionCommitButton(fix, 1);
1607+
fix.detectChanges();
1608+
QueryBuilderFunctions.clickQueryBuilderExpressionCommitButton(fix, 0);
1609+
fix.detectChanges();
16051610
// Close Advanced Filtering dialog.
16061611
hgrid.closeAdvancedFilteringDialog(true);
16071612
tick(200);
@@ -1611,6 +1616,45 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
16111616
expect(hgrid.filteredData.length).toEqual(5);
16121617
expect(hgrid.rowList.length).toBe(5);
16131618
}));
1619+
1620+
it('Should correctly apply filtering expressions tree to the hgrid component through API.', fakeAsync(() => {
1621+
// Close Advanced Filtering dialog.
1622+
hgrid.closeAdvancedFilteringDialog(false);
1623+
tick(200);
1624+
fix.detectChanges();
1625+
// Spy for error messages in the console
1626+
const consoleSpy = spyOn(console, 'error');
1627+
// Apply advanced filter through API.
1628+
const innerTree = new FilteringExpressionsTree(0, undefined, 'childData', ['ID']);
1629+
innerTree.filteringOperands.push({
1630+
fieldName: 'ID',
1631+
ignoreCase: false,
1632+
conditionName: IgxStringFilteringOperand.instance().condition('contains').name,
1633+
searchVal: '1'
1634+
});
1635+
1636+
const tree = new FilteringExpressionsTree(0, undefined, 'rootData', ['ID']);
1637+
tree.filteringOperands.push({
1638+
fieldName: 'ID',
1639+
conditionName: IgxStringFilteringOperand.instance().condition('inQuery').name,
1640+
ignoreCase: false,
1641+
searchTree: innerTree
1642+
});
1643+
tree.filteringOperands.push(innerTree);
1644+
hgrid.advancedFilteringExpressionsTree = tree;
1645+
fix.detectChanges();
1646+
1647+
// Check for error messages in the console
1648+
expect(consoleSpy).not.toHaveBeenCalled();
1649+
}));
1650+
1651+
// fit('Should be able to filter hierarchicaly with load on demand through API.', fakeAsync(() => {
1652+
// const fixture = TestBed.createComponent(IgxHGridRemoteOnDemandComponent);
1653+
// const hierarchicalGrid = fixture.componentInstance.hgrid;
1654+
// hierarchicalGrid.allowAdvancedFiltering = true;
1655+
// fixture.detectChanges();
1656+
1657+
// }));
16141658
});
16151659
});
16161660

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,27 +1219,32 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
12191219

12201220
private generateSchema() {
12211221
const filterableFields = this.columns.filter((column) => !column.columnGroup && column.filterable);
1222-
const entities: EntityType[] = [
1223-
{
1224-
name: null,
1225-
fields: filterableFields.map(f => ({
1226-
field: f.field,
1227-
dataType: f.dataType,
1228-
// label: f.label,
1229-
// header: f.header,
1230-
editorOptions: f.editorOptions,
1231-
filters: f.filters,
1232-
pipeArgs: f.pipeArgs,
1233-
defaultTimeFormat: f.defaultTimeFormat,
1234-
defaultDateTimeFormat: f.defaultDateTimeFormat
1235-
})) as FieldType[]
1236-
}
1237-
];
1222+
let entities: EntityType[];
1223+
1224+
if(filterableFields.length !== 0) {
1225+
entities = [
1226+
{
1227+
name: null,
1228+
fields: filterableFields.map(f => ({
1229+
field: f.field,
1230+
dataType: f.dataType,
1231+
// label: f.label,
1232+
// header: f.header,
1233+
editorOptions: f.editorOptions,
1234+
filters: f.filters,
1235+
pipeArgs: f.pipeArgs,
1236+
defaultTimeFormat: f.defaultTimeFormat,
1237+
defaultDateTimeFormat: f.defaultDateTimeFormat
1238+
})) as FieldType[]
1239+
}
1240+
];
12381241

1239-
entities[0].childEntities = this.childLayoutList.reduce((acc, rowIsland) => {
1240-
return acc.concat(this.generateChildEntity(rowIsland, this.data[0][rowIsland.key][0]));
1242+
entities[0].childEntities = this.childLayoutList.reduce((acc, rowIsland) => {
1243+
return acc.concat(this.generateChildEntity(rowIsland, this.data[0][rowIsland.key][0]));
1244+
}
1245+
, []);
1246+
12411247
}
1242-
, []);
12431248

12441249
return entities;
12451250
}

projects/igniteui-angular/src/lib/query-builder/query-builder-tree.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
517517
/** @hidden */
518518
protected isAdvancedFiltering(): boolean {
519519
return (this.entities?.length === 1 && !this.entities[0]?.name) ||
520-
this.entities.find(e => e.childEntities?.length > 0) !== undefined ||
520+
this.entities?.find(e => e.childEntities?.length > 0) !== undefined ||
521521
this.entities !== this.queryBuilder.entities;
522522
}
523523

src/app/hierarchical-grid-remote/hierarchical-grid-remote.sample.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, OnInit, ChangeDetectorRef } from '@angular/core';
1+
import { Component, ViewChild, OnInit, ChangeDetectorRef, AfterViewInit } from '@angular/core';
22
import {
33
IgxRowIslandComponent,
44
IgxHierarchicalGridComponent,
@@ -18,7 +18,7 @@ const API_ENDPOINT = 'https://data-northwind.indigo.design';
1818
styleUrls: ['hierarchical-grid-remote.sample.scss'],
1919
imports: [IGX_HIERARCHICAL_GRID_DIRECTIVES]
2020
})
21-
export class HierarchicalGridRemoteSampleComponent implements OnInit {
21+
export class HierarchicalGridRemoteSampleComponent implements OnInit, AfterViewInit {
2222
@ViewChild('hGrid', { static: true })
2323
private hGrid: IgxHierarchicalGridComponent;
2424

@@ -71,15 +71,13 @@ export class HierarchicalGridRemoteSampleComponent implements OnInit {
7171
ordersTree.filteringOperands.push({
7272
fieldName: 'shipVia',
7373
ignoreCase: false,
74-
condition: IgxStringFilteringOperand.instance().condition('equals'),
7574
conditionName: IgxStringFilteringOperand.instance().condition('equals').name,
7675
searchVal: 'AirCargo'
7776
});
7877

7978
const customersTree = new FilteringExpressionsTree(0, undefined, 'Customers', ['customerId', 'companyName', 'contactName', 'contactTitle']);
8079
customersTree.filteringOperands.push({
8180
fieldName: 'customerId',
82-
condition: IgxStringFilteringOperand.instance().condition('notInQuery'),
8381
conditionName: IgxStringFilteringOperand.instance().condition('notInQuery').name,
8482
ignoreCase: false,
8583
searchTree: ordersTree

0 commit comments

Comments
 (0)