Skip to content

Commit 278901c

Browse files
Ivan KitanovIvan Kitanov
authored andcommitted
chore(grids): Adding tests for tGrid and hGrid
1 parent de5530b commit 278901c

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
IgxHierarchicalGridRowSelectionComponent,
1010
IgxHierarchicalGridRowSelectionTestSelectRowOnClickComponent,
1111
IgxHierarchicalGridCustomSelectorsComponent,
12-
IgxHierarchicalGridRowSelectionNoTransactionsComponent
12+
IgxHierarchicalGridRowSelectionNoTransactionsComponent,
13+
IgxHierGridExternalAdvancedFilteringComponent
1314
} from '../../test-utils/hierarchical-grid-components.spec';
1415
import { GridSelectionFunctions, GridFunctions } from '../../test-utils/grid-functions.spec';
1516
import { GridSelectionMode, Size } from '../common/enums';
@@ -33,7 +34,8 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
3334
IgxHierarchicalGridRowSelectionComponent,
3435
IgxHierarchicalGridRowSelectionTestSelectRowOnClickComponent,
3536
IgxHierarchicalGridCustomSelectorsComponent,
36-
IgxHierarchicalGridRowSelectionNoTransactionsComponent
37+
IgxHierarchicalGridRowSelectionNoTransactionsComponent,
38+
IgxHierGridExternalAdvancedFilteringComponent,
3739
]
3840
}).compileComponents();
3941
}))
@@ -474,6 +476,30 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
474476
GridSelectionFunctions.verifySelectedRange(hierarchicalGrid, 0, 0, 2, 2);
475477
}));
476478

479+
it('Should not trigger range selection when CellTemplate is used and the user clicks on element inside it', () => {
480+
fix = TestBed.createComponent(IgxHierGridExternalAdvancedFilteringComponent);
481+
fix.detectChanges();
482+
483+
const component = fix.componentInstance;
484+
hierarchicalGrid = fix.componentInstance.hgrid;
485+
486+
expect(component.customCell).toBeDefined();
487+
488+
const column = hierarchicalGrid.getColumnByName('ID');
489+
column.bodyTemplate = component.customCell;
490+
fix.detectChanges();
491+
492+
const selectionChangeSpy = spyOn<any>(hierarchicalGrid.rangeSelected, 'emit').and.callThrough();
493+
const cell = hierarchicalGrid.gridAPI.get_cell_by_index(0, 'ID');
494+
const cellElement = cell.nativeElement;
495+
const span = cellElement.querySelector('span');
496+
497+
expect(span).not.toBeNull();
498+
499+
UIInteractions.simulateClickAndSelectEvent(span);
500+
fix.detectChanges();
501+
expect(selectionChangeSpy).not.toHaveBeenCalled();
502+
});
477503
});
478504

479505
describe('Row Selection', () => {

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,27 @@ describe('IgxTreeGrid - Selection #tGrid', () => {
964964
expect(treeGrid.selectedCells[0] instanceof IgxGridCell).toBe(true);
965965
expect(treeGrid.selectedCells[0].value).toBe(19);
966966
});
967+
968+
it('Should not trigger range selection when CellTemplate is used and the user clicks on element inside it', () => {
969+
const component = fix.componentInstance;
970+
971+
expect(component.customCell).toBeDefined();
972+
973+
const column = treeGrid.getColumnByName('ID');
974+
column.bodyTemplate = component.customCell;
975+
fix.detectChanges();
976+
977+
const selectionChangeSpy = spyOn<any>(treeGrid.rangeSelected, 'emit').and.callThrough();
978+
const cell = treeGrid.gridAPI.get_cell_by_index(0, 'ID');
979+
const cellElement = cell.nativeElement;
980+
const span = cellElement.querySelector('span');
981+
982+
expect(span).not.toBeNull();
983+
984+
UIInteractions.simulateClickAndSelectEvent(span);
985+
fix.detectChanges();
986+
expect(selectionChangeSpy).not.toHaveBeenCalled();
987+
});
967988
});
968989

969990
describe('Cell/Row Selection With Row Editing', () => {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, OnInit } from '@angular/core';
1+
import { Component, ViewChild, OnInit, TemplateRef } from '@angular/core';
22
import { SampleTestData } from './sample-test-data.spec';
33
import { ColumnType, IPinningConfig, IgxAdvancedFilteringDialogComponent, IgxColumnComponent, IgxNumberSummaryOperand, IgxSummaryResult } from '../grids/public_api';
44
import { IgxHierarchicalGridComponent } from '../grids/hierarchical-grid/hierarchical-grid.component';
@@ -460,6 +460,11 @@ export class IgxHierarchicalGridActionStripComponent extends IgxHierarchicalGrid
460460
<igx-column field="ProductName"></igx-column>
461461
</igx-row-island>
462462
</igx-row-island>
463+
<ng-template #customCell igxCell let-cell="cell" let-val>
464+
<span style="background-color: red;">val</span>
465+
<br>
466+
{{val}}
467+
</ng-template>
463468
</igx-hierarchical-grid>
464469
<igx-advanced-filtering-dialog [grid]="hierarchicalGrid">
465470
</igx-advanced-filtering-dialog>`,
@@ -468,7 +473,8 @@ export class IgxHierarchicalGridActionStripComponent extends IgxHierarchicalGrid
468473
export class IgxHierGridExternalAdvancedFilteringComponent extends IgxHierarchicalGridTestBaseComponent {
469474
@ViewChild('hierarchicalGrid', { read: IgxHierarchicalGridComponent, static: true })
470475
public override hgrid: IgxHierarchicalGridComponent;
471-
476+
@ViewChild('customCell', { static: true })
477+
public customCell!: TemplateRef<any>;
472478
public override data = SampleTestData.generateHGridData(5, 3);
473479
}
474480

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, OnInit } from '@angular/core';
1+
import { Component, ViewChild, OnInit, TemplateRef } from '@angular/core';
22
import { IgxTreeGridComponent } from '../grids/tree-grid/tree-grid.component';
33
import { SampleTestData } from './sample-test-data.spec';
44
import { IgxSummaryOperand, IgxNumberSummaryOperand, IgxSummaryResult, IPinningConfig, IgxColumnComponent } from '../grids/public_api';
@@ -191,13 +191,20 @@ export class IgxTreeGridExpandingComponent {
191191
<igx-column [field]="'HireDate'" dataType="date"></igx-column>
192192
<igx-column [field]="'Age'" dataType="number"></igx-column>
193193
<igx-paginator [perPage]="10"></igx-paginator>
194+
<ng-template #customCell igxCell let-cell="cell" let-val>
195+
<span style="background-color: red;">val</span>
196+
<br>
197+
{{val}}
198+
</ng-template>
194199
</igx-tree-grid>
195200
`,
196201
imports: [IgxTreeGridComponent, IgxColumnComponent, IgxPaginatorComponent]
197202
})
198203
export class IgxTreeGridCellSelectionComponent {
199204
@ViewChild(IgxTreeGridComponent, { static: true }) public treeGrid: IgxTreeGridComponent;
200205
public data = SampleTestData.employeeTreeData();
206+
@ViewChild('customCell', { static: true })
207+
public customCell!: TemplateRef<any>;
201208
}
202209

203210
@Component({

0 commit comments

Comments
 (0)