Skip to content

Commit 8cdf9ea

Browse files
Ivan KitanovIvan Kitanov
authored andcommitted
chore(grid): Unifying test sample and updating test
1 parent 282111c commit 8cdf9ea

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
SelectionWithTransactionsComponent,
77
CellSelectionNoneComponent,
88
CellSelectionSingleComponent,
9-
IgxGridCellTemplateForRangeSelectionComponent
9+
IgxGridRowEditingWithoutEditableColumnsComponent
1010
} from '../../test-utils/grid-samples.spec';
1111
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
1212
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
@@ -28,7 +28,7 @@ describe('IgxGrid - Cell selection #grid', () => {
2828
SelectionWithTransactionsComponent,
2929
CellSelectionNoneComponent,
3030
CellSelectionSingleComponent,
31-
IgxGridCellTemplateForRangeSelectionComponent
31+
IgxGridRowEditingWithoutEditableColumnsComponent
3232
]
3333
}).compileComponents();
3434
}));
@@ -259,18 +259,30 @@ describe('IgxGrid - Cell selection #grid', () => {
259259
});
260260

261261
it('Should not trigger range selection when CellTemplate is used and the user clicks on element inside it',()=>{
262-
fix = TestBed.createComponent(IgxGridCellTemplateForRangeSelectionComponent);
262+
fix = TestBed.createComponent(IgxGridRowEditingWithoutEditableColumnsComponent);
263263
fix.detectChanges();
264+
265+
const component = fix.componentInstance;
264266
grid = fix.componentInstance.grid;
265-
detect = () => grid.cdr.detectChanges();
267+
268+
expect(component.customCell).toBeDefined();
269+
270+
const column = grid.getColumnByName('ProductID');
271+
column.bodyTemplate = component.customCell;
272+
fix.detectChanges();
266273

267274
const selectionChangeSpy = spyOn<any>(grid.rangeSelected, 'emit').and.callThrough();
268275
const cell = grid.gridAPI.get_cell_by_index(1, 'ProductID');
269276
const cellElement = cell.nativeElement;
270277
const span = cellElement.querySelector('span');
271278

272279
expect(span).not.toBeNull();
273-
span.click();
280+
281+
282+
const pointerDown = new PointerEvent('pointerdown', { bubbles: true });
283+
const pointerUp = new PointerEvent('pointerup', { bubbles: true });
284+
span.dispatchEvent(pointerDown);
285+
span.dispatchEvent(pointerUp);
274286
fix.detectChanges();
275287
expect(selectionChangeSpy).not.toHaveBeenCalled();
276288
});

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,31 +1407,18 @@ export class IgxGridRowEditingComponent extends BasicGridComponent {
14071407
<igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" [editable]="true" width="100px"></igx-column>
14081408
<igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="150px"></igx-column>
14091409
<igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="150px" [editable]="false"></igx-column>
1410+
<ng-template #customCell igxCell let-cell="cell" let-val>
1411+
<span style="background-color: red;">val</span>
1412+
<br>
1413+
{{val}}
1414+
</ng-template>
14101415
</igx-grid>`,
14111416
imports: [IgxGridComponent, IgxColumnComponent, IgxCellTemplateDirective]
14121417
})
14131418
export class IgxGridRowEditingWithoutEditableColumnsComponent extends BasicGridComponent {
14141419
public override data = SampleTestData.foodProductData();
1415-
}
1416-
1417-
@Component({
1418-
template: `
1419-
<igx-grid #grid [data]="data" [primaryKey]="'ProductID'" width="700px" height="400px" [cellSelection]="'multiple'">
1420-
<igx-column field="ProductID" header="Product ID">
1421-
<ng-template igxCell let-cell="cell" let-val>
1422-
<span style="background-color: red;">val</span>
1423-
<br>
1424-
{{val}}
1425-
</ng-template>
1426-
</igx-column>
1427-
<igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" [editable]="true" width="100px"></igx-column>
1428-
<igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="150px"></igx-column>
1429-
<igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="150px" [editable]="false"></igx-column>
1430-
</igx-grid>`,
1431-
imports: [IgxGridComponent, IgxColumnComponent, IgxCellTemplateDirective]
1432-
})
1433-
export class IgxGridCellTemplateForRangeSelectionComponent extends BasicGridComponent {
1434-
public override data = SampleTestData.foodProductData();
1420+
@ViewChild('customCell', { static: true })
1421+
public customCell!: TemplateRef<any>;
14351422
}
14361423

14371424
@Component({

0 commit comments

Comments
 (0)