Skip to content

Commit 2cdea7f

Browse files
committed
test(hgrid): add test for onRowSelectionChange event #5693
1 parent 818ee7f commit 2cdea7f

File tree

4 files changed

+87
-9
lines changed

4 files changed

+87
-9
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ describe('IgxGrid - Keyboard navigation #grid', () => {
136136
displayContainer.dispatchEvent(event);
137137
await wait(300);
138138

139-
expect(firstCell.isSelected).toBeFalsy();
140139
expect(firstCell.selected).toBeFalsy();
141140
expect(firstCell.focused).toBeFalsy();
142141
}));
@@ -163,15 +162,15 @@ describe('IgxGrid - Keyboard navigation #grid', () => {
163162
fix.detectChanges();
164163

165164
expect(cell.selected).toBeTruthy();
166-
expect(secondRow.isSelected).toBeTruthy();
165+
expect(secondRow.selected).toBeTruthy();
167166
expect(secondRowCheckbox.classList.contains('igx-checkbox--checked')).toBeTruthy();
168167

169168
UIInteractions.triggerKeyDownEvtUponElem('space', cell.nativeElement, true);
170169
await wait(DEBOUNCETIME);
171170
fix.detectChanges();
172171

173172
expect(cell.selected).toBeTruthy();
174-
expect(secondRow.isSelected).toBeFalsy();
173+
expect(secondRow.selected).toBeFalsy();
175174
expect(secondRowCheckbox.classList.contains('igx-checkbox--checked')).toBeFalsy();
176175

177176
cell = grid.getCellByColumn(1, 'ID');
@@ -189,15 +188,15 @@ describe('IgxGrid - Keyboard navigation #grid', () => {
189188
await wait(DEBOUNCETIME);
190189
fix.detectChanges();
191190

192-
expect(firstRow.isSelected).toBeTruthy();
191+
expect(firstRow.selected).toBeTruthy();
193192
expect(firstRowCheckbox.classList.contains('igx-checkbox--checked')).toBeTruthy();
194193

195194
UIInteractions.triggerKeyDownEvtUponElem('space', cell.nativeElement, true);
196195
await wait(DEBOUNCETIME);
197196
fix.detectChanges();
198197

199198
expect(cell.selected).toBeTruthy();
200-
expect(firstRow.isSelected).toBeFalsy();
199+
expect(firstRow.selected).toBeFalsy();
201200
expect(firstRowCheckbox.classList.contains('igx-checkbox--checked')).toBeFalsy();
202201

203202
UIInteractions.triggerKeyDownWithBlur('tab', cell.nativeElement, true);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ describe('IgxGrid - Row Selection #grid', () => {
646646
grid = fix.componentInstance.grid;
647647
}));
648648

649-
it('Change RowSelection to multiple ', () => {
649+
it('Change RowSelection to multiple ', () => {
650650
HelperUtils.verifyHeaderRowHasCheckbox(fix, false, false);
651651
HelperUtils.verifyRowHasCheckbox(grid.getRowByIndex(0).nativeElement, false, false);
652652

projects/igniteui-angular/src/lib/grids/grid/row-drag.directive.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
593593
const dragIndicatorElement = dragIndicatorElements[2].nativeElement;
594594
const row = dragGridRows[1];
595595
const rowDragDirective = dragRows[1].injector.get(IgxRowDragDirective);
596-
expect(row.isSelected).toBeTruthy();
596+
expect(row.selected).toBeTruthy();
597597

598598
const startPoint: Point = UIInteractions.getPointFromElement(dragIndicatorElement);
599599
const movePoint: Point = UIInteractions.getPointFromElement(dragGridRows[4].nativeElement);
@@ -614,7 +614,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
614614
expect(row.grid.rowDragging).toBeFalsy();
615615
verifyRowDragEndEvent(dragGrid, row, rowDragDirective, false);
616616
expect(dropGrid.rowList.length).toEqual(1);
617-
expect(row.isSelected).toBeTruthy();
617+
expect(row.selected).toBeTruthy();
618618
}));
619619
it('should not apply selection class to ghost element when dragging selected grid row', (async () => {
620620
dragGrid.rowSelection = GridSelectionMode.multiple;
@@ -624,7 +624,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
624624

625625
const dragIndicatorElement = dragIndicatorElements[2].nativeElement;
626626
const row = dragGridRows[1];
627-
expect(row.isSelected).toBeTruthy();
627+
expect(row.selected).toBeTruthy();
628628

629629
const startPoint: Point = UIInteractions.getPointFromElement(dragIndicatorElement);
630630
const movePoint: Point = UIInteractions.getPointFromElement(dragGridRows[4].nativeElement);

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,85 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
207207
}
208208
});
209209

210+
it('should have fire event onRowSelectionChange', () => {
211+
hierarchicalGrid.expandChildren = true;
212+
fix.detectChanges();
213+
const childGrid = hierarchicalGrid.hgridAPI.getChildGrids(false)[0];
214+
const secondChildGrid = hierarchicalGrid.hgridAPI.getChildGrids(false)[1];
215+
const parentSpy = spyOn<any>(hierarchicalGrid.onRowSelectionChange, 'emit').and.callThrough();
216+
const childSpy = spyOn<any>(childGrid.onRowSelectionChange, 'emit').and.callThrough();
217+
const secondChildSpy = spyOn<any>(secondChildGrid.onRowSelectionChange, 'emit').and.callThrough();
218+
const mockEvent = new MouseEvent('click');
219+
220+
// Click on a row in child grid
221+
let row = childGrid.dataRowList.toArray()[0];
222+
row.nativeElement.dispatchEvent(mockEvent);
223+
fix.detectChanges();
224+
225+
expect(secondChildSpy).toHaveBeenCalledTimes(0);
226+
expect(parentSpy).toHaveBeenCalledTimes(0);
227+
expect(childSpy).toHaveBeenCalledTimes(1);
228+
expect(childSpy).toHaveBeenCalledWith({
229+
added: ['00'],
230+
cancel: false,
231+
event: mockEvent,
232+
newSelection: ['00'],
233+
oldSelection: [],
234+
removed: [],
235+
owner: childGrid
236+
});
237+
238+
// Click on checkbox on second row
239+
HelperUtils.getRowCheckboxDiv(childGrid.dataRowList.toArray()[1].nativeElement).dispatchEvent(mockEvent);
240+
fix.detectChanges();
241+
242+
expect(secondChildSpy).toHaveBeenCalledTimes(0);
243+
expect(parentSpy).toHaveBeenCalledTimes(0);
244+
expect(childSpy).toHaveBeenCalledTimes(2);
245+
expect(childSpy).toHaveBeenCalledWith({
246+
added: ['01'],
247+
cancel: false,
248+
event: mockEvent,
249+
newSelection: ['01'],
250+
oldSelection: ['00'],
251+
removed: ['00'],
252+
owner: childGrid
253+
});
254+
255+
// Click on a row in parent grid
256+
row = hierarchicalGrid.dataRowList.toArray()[1];
257+
row.nativeElement.dispatchEvent(mockEvent);
258+
fix.detectChanges();
259+
260+
expect(secondChildSpy).toHaveBeenCalledTimes(0);
261+
expect(childSpy).toHaveBeenCalledTimes(2);
262+
expect(parentSpy).toHaveBeenCalledTimes(1);
263+
expect(parentSpy).toHaveBeenCalledWith({
264+
added: ['1'],
265+
cancel: false,
266+
event: mockEvent,
267+
newSelection: ['1'],
268+
oldSelection: [],
269+
removed: []
270+
});
271+
272+
// Click on a header checkbox in parent grid
273+
HelperUtils.getRowCheckboxDiv(HelperUtils.getHeaderRow(hierarchicalGrid)).dispatchEvent(mockEvent);
274+
fix.detectChanges();
275+
276+
expect(secondChildSpy).toHaveBeenCalledTimes(0);
277+
expect(childSpy).toHaveBeenCalledTimes(2);
278+
expect(parentSpy).toHaveBeenCalledTimes(2);
279+
expect(parentSpy).toHaveBeenCalledWith({
280+
added: ['0', '2', '3', '4'],
281+
cancel: false,
282+
event: mockEvent,
283+
newSelection: ['1', '0', '2', '3', '4'],
284+
oldSelection: ['1'],
285+
removed: []
286+
});
287+
});
288+
210289
it('should able to select multiple rows with Shift and click', () => {
211290
// Expand first row
212291
const firstRow = hierarchicalGrid.dataRowList.toArray()[0];

0 commit comments

Comments
 (0)