Skip to content

Commit d2f00a2

Browse files
committed
Sync transaction and validation services when transactions are all cleared with clear API. Add a test. Update the failing one.
1 parent 6185482 commit d2f00a2

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
15581558
* ```
15591559
*/
15601560
public set sortDescendingHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1561-
this._sortDescendingHeaderIconTemplate = template;
1561+
this._sortDescendingHeaderIconTemplate = template;
15621562
}
15631563

15641564
/**
@@ -4445,12 +4445,12 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
44454445
*/
44464446
public recalculateAutoSizes() {
44474447
// reset auto-size and calculate it again.
4448-
this._columns.forEach( x => x.autoSize = undefined);
4449-
this.resetCaches();
4450-
this.zone.onStable.pipe(first()).subscribe(() => {
4451-
this.cdr.detectChanges();
4452-
this.autoSizeColumnsInView();
4453-
});
4448+
this._columns.forEach(x => x.autoSize = undefined);
4449+
this.resetCaches();
4450+
this.zone.onStable.pipe(first()).subscribe(() => {
4451+
this.cdr.detectChanges();
4452+
this.autoSizeColumnsInView();
4453+
});
44544454
}
44554455

44564456
/**
@@ -6515,7 +6515,10 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
65156515
}
65166516

65176517
});
6518+
} else if (event.origin === TransactionEventOrigin.CLEAR) {
6519+
this.validation.clear();
65186520
}
6521+
65196522
this.selectionService.clearHeaderCBState();
65206523
this.summaryService.clearSummaryCache();
65216524
this.pipeTrigger++;
@@ -7062,8 +7065,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
70627065
this.tbody.nativeElement.style.display = 'none';
70637066
const parentElement = this.nativeElement.parentElement || (this.nativeElement.getRootNode() as any).host;
70647067
let res = !parentElement ||
7065-
parentElement.clientHeight === 0 ||
7066-
parentElement.clientHeight === renderedHeight;
7068+
parentElement.clientHeight === 0 ||
7069+
parentElement.clientHeight === renderedHeight;
70677070
if ((!this.platform.isChromium && !this.platform.isFirefox) || this._autoSize) {
70687071
// If grid causes the parent container to extend (for example when container is flex)
70697072
// we should always auto-size since the actual size of the container will continuously change as the grid renders elements.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,11 +1715,13 @@ describe('IgxGrid - Row Editing #grid', () => {
17151715
// On button click
17161716
const doneButtonElement = GridFunctions.getRowEditingDoneButton(fix);
17171717
doneButtonElement.click();
1718+
fix.detectChanges();
17181719

17191720
const rowData = Object.assign({}, cell.row.data, { ProductName: 'New Name' });
17201721
expect(!!grid.gridAPI.crudService.rowInEditMode).toEqual(true);
17211722
expect(grid.gridAPI.crudService.cellInEditMode).toEqual(false);
1722-
expect(cell.row.data).not.toEqual(rowData);
1723+
expect(cell.row.data.ProductName).toEqual('New Name');
1724+
expect(grid.dataView[0]).not.toEqual(rowData);
17231725
});
17241726

17251727
it(`Should properly emit 'rowEdit' event - Button Click`, () => {

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe('IgxGrid - Validation #grid', () => {
247247
fixture.detectChanges();
248248

249249
GridFunctions.verifyCellValid(cell, false);
250-
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid});
250+
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid });
251251

252252
UIInteractions.simulateDoubleClickAndSelectEvent(cell.element);
253253
cell.editMode = true;
@@ -259,7 +259,7 @@ describe('IgxGrid - Validation #grid', () => {
259259
fixture.detectChanges();
260260

261261
GridFunctions.verifyCellValid(cell, true);
262-
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid});
262+
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid });
263263
});
264264

265265
it('should return invalid transaction using the transaction service API', () => {
@@ -407,7 +407,7 @@ describe('IgxGrid - Validation #grid', () => {
407407
const grid = fixture.componentInstance.grid as IgxGridComponent;
408408
let cell = grid.gridAPI.get_cell_by_visible_index(1, 1);
409409

410-
grid.updateCell('IG', 2,'ProductName');
410+
grid.updateCell('IG', 2, 'ProductName');
411411
grid.validation.markAsTouched(2);
412412
fixture.detectChanges();
413413

@@ -525,6 +525,44 @@ describe('IgxGrid - Validation #grid', () => {
525525
expect((grid.validation as any).getValidity().length).toEqual(0);
526526
});
527527

528+
it('should update validity when all transactions are cleared', () => {
529+
const grid = fixture.componentInstance.grid as IgxGridComponent;
530+
let cell = grid.gridAPI.get_cell_by_visible_index(1, 1);
531+
let secondCell = grid.gridAPI.get_cell_by_visible_index(2, 1);
532+
533+
// update first cell
534+
UIInteractions.simulateDoubleClickAndSelectEvent(cell.element);
535+
cell.editMode = true;
536+
cell.update('IG');
537+
fixture.detectChanges();
538+
539+
grid.gridAPI.crudService.endEdit(true);
540+
fixture.detectChanges();
541+
542+
GridFunctions.verifyCellValid(cell, false);
543+
544+
//update second cell
545+
UIInteractions.simulateDoubleClickAndSelectEvent(secondCell.element);
546+
secondCell.editMode = true;
547+
secondCell.update('bob');
548+
fixture.detectChanges();
549+
550+
grid.gridAPI.crudService.endEdit(true);
551+
fixture.detectChanges();
552+
GridFunctions.verifyCellValid(cell, false);
553+
expect(grid.validation.getInvalid().length).toBe(2);
554+
555+
556+
// clear transactions
557+
grid.transactions.clear();
558+
fixture.detectChanges();
559+
expect(grid.validation.getInvalid().length).toBe(0);
560+
561+
562+
grid.validation.clear();
563+
fixture.detectChanges();
564+
});
565+
528566
it('should not show errors when the row is deleted', () => {
529567
const grid = fixture.componentInstance.grid as IgxGridComponent;
530568
let cell = grid.gridAPI.get_cell_by_visible_index(1, 1);

0 commit comments

Comments
 (0)