Skip to content

Commit c27c307

Browse files
committed
test(grid): Add test for the bug #5763
1 parent 998fef6 commit c27c307

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,7 +3690,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
36903690
}
36913691
this.gridAPI.escape_editMode();
36923692
}
3693-
this.cdr.markForCheck();
3693+
this.cdr.detectChanges();
36943694
}
36953695
}
36963696
}
@@ -3716,7 +3716,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
37163716
}
37173717
const row = new IgxRow(rowSelector, -1, this.gridAPI.getRowData(rowSelector));
37183718
this.gridAPI.update_row(row, value);
3719-
this.cdr.markForCheck();
3719+
this.cdr.detectChanges();
37203720
}
37213721
}
37223722

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,46 @@ describe('IgxGrid - Cell Editing #grid', () => {
647647
expect(cell.editMode).toBe(true);
648648
});
649649

650+
it(`Should be able to update other cell in 'onCellEdit' event`, () => {
651+
grid.primaryKey = 'personNumber';
652+
fixture.detectChanges();
653+
654+
spyOn(grid.onCellEdit, 'emit').and.callThrough();
655+
grid.onCellEdit.subscribe((e: IGridEditEventArgs) => {
656+
if (e.cellID.columnID === 0) {
657+
grid.updateCell(1, e.rowID, 'age' );
658+
}
659+
});
660+
661+
let cell = grid.getCellByColumn(0, 'fullName');
662+
663+
UIInteractions.simulateClickAndSelectCellEvent(cell);
664+
fixture.detectChanges();
665+
666+
cell.nativeElement.dispatchEvent(new MouseEvent('dblclick'));
667+
fixture.detectChanges();
668+
669+
expect(cell.editMode).toBe(true);
670+
let editTemplate = fixture.debugElement.query(By.css('input'));
671+
UIInteractions.sendInput(editTemplate, 'New Name');
672+
fixture.detectChanges();
673+
674+
// press tab on edited cell
675+
UIInteractions.triggerKeyDownWithBlur('tab', cell.nativeElement, true);
676+
fixture.detectChanges();
677+
678+
expect(grid.onCellEdit.emit).toHaveBeenCalledTimes(2);
679+
cell = grid.getCellByColumn(0, 'age');
680+
expect(cell.editMode).toBe(true);
681+
expect(cell.value).toEqual(1);
682+
expect(cell.editValue).toEqual(1);
683+
editTemplate = fixture.debugElement.query(By.css('input'));
684+
expect(editTemplate.nativeElement.value).toEqual('1');
685+
686+
cell = grid.getCellByColumn(0, 'fullName');
687+
expect(cell.value).toEqual('New Name');
688+
});
689+
650690
it(`Should properly emit 'onCellEditCancel' event`, () => {
651691
spyOn(grid.onCellEditCancel, 'emit').and.callThrough();
652692
const cell = grid.getCellByColumn(0, 'fullName');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,12 +1240,12 @@ describe('IgxGrid - Row Selection #grid', () => {
12401240
});
12411241

12421242
it('Should be able to update row through primaryKey', () => {
1243-
spyOn(grid.cdr, 'markForCheck').and.callThrough();
1243+
spyOn(grid.onRowEdit, 'emit').and.callThrough();
12441244
expect(grid.primaryKey).toBeTruthy();
12451245
expect(grid.rowList.length).toEqual(10, 'All 10 rows should initialized');
12461246
expect(grid.getRowByKey(2).rowData['JobTitle']).toMatch('Director');
12471247
grid.updateRow({ ID: 2, Name: 'Gilberto Todd', JobTitle: 'Vice President' }, 2);
1248-
expect(grid.cdr.markForCheck).toHaveBeenCalledTimes(1);
1248+
expect(grid.onRowEdit.emit).toHaveBeenCalledTimes(1);
12491249
fix.detectChanges();
12501250
expect(grid.getRowByIndex(1).rowData['JobTitle']).toMatch('Vice President');
12511251
expect(grid.getRowByKey(2).rowData['JobTitle']).toMatch('Vice President');

0 commit comments

Comments
 (0)