Skip to content

Commit

Permalink
Merge pull request #3399 from IgniteUI/mvenkov/treegrid-batch-update-…
Browse files Browse the repository at this point in the history
…fixes

Treegrid batch update fixes, #2921
  • Loading branch information
bazal4o authored Dec 12, 2018
2 parents daf2ba0 + 7c2f692 commit eceaa09
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ export class IgxHierarchicalTransactionService<T extends HierarchicalTransaction

// TODO: remove this method. Force cloning to strip child arrays when needed instead
private clearArraysFromObject(obj: {}) {
for (const prop of Object.keys(obj)) {
if (Array.isArray(obj[prop])) {
delete obj[prop];
if (obj) {
for (const prop of Object.keys(obj)) {
if (Array.isArray(obj[prop])) {
delete obj[prop];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ describe('IgxTransaction', () => {
expect(trans.getTransactionLog('100').pop()).toEqual(undefined);
});

it('Should add ADD type transaction - all feasible paths', () => {
it('Should add ADD type transaction - all feasible paths, and correctly fires onStateUpdate', () => {
const trans = new IgxTransactionService();
spyOn(trans.onStateUpdate, 'emit').and.callThrough();
expect(trans).toBeDefined();

// ADD
Expand All @@ -176,18 +177,24 @@ describe('IgxTransaction', () => {
recordRef: undefined,
type: addTransaction.type
});
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(1);

trans.clear();
expect(trans.getState('1')).toBeUndefined();
expect(trans.getAggregatedValue('1', true)).toBeNull();
expect(trans.getTransactionLog()).toEqual([]);
expect(trans.getAggregatedChanges(true)).toEqual([]);
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(2);

// ADD -> Undo
trans.add(addTransaction);
trans.undo();
expect(trans.getTransactionLog()).toEqual([]);
expect(trans.getAggregatedChanges(true)).toEqual([]);
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(4);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(5);

// ADD -> Undo -> Redo
trans.add(addTransaction);
Expand All @@ -199,15 +206,21 @@ describe('IgxTransaction', () => {
recordRef: undefined,
type: addTransaction.type
});
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(8);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(9);

// ADD -> DELETE
trans.add(addTransaction);
const deleteTransaction: Transaction = { id: '1', type: TransactionType.DELETE, newValue: 1 };
trans.add(deleteTransaction);
expect(trans.getTransactionLog()).toEqual([addTransaction, deleteTransaction]);
expect(trans.getAggregatedChanges(true)).toEqual([]);
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(11);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(12);

// ADD -> DELETE -> Undo
trans.add(addTransaction);
Expand All @@ -219,7 +232,10 @@ describe('IgxTransaction', () => {
recordRef: undefined,
type: addTransaction.type
});
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(15);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(16);

// ADD -> DELETE -> Undo -> Redo
trans.add(addTransaction);
Expand All @@ -228,7 +244,10 @@ describe('IgxTransaction', () => {
trans.redo();
expect(trans.getTransactionLog()).toEqual([addTransaction, deleteTransaction]);
expect(trans.getAggregatedChanges(true)).toEqual([]);
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(20);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(21);

// ADD -> DELETE -> Undo -> Undo
trans.add(addTransaction);
Expand All @@ -237,7 +256,10 @@ describe('IgxTransaction', () => {
trans.undo();
expect(trans.getTransactionLog()).toEqual([]);
expect(trans.getAggregatedChanges(true)).toEqual([]);
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(25);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(26);

// ADD -> UPDATE
trans.add(addTransaction);
Expand All @@ -249,7 +271,10 @@ describe('IgxTransaction', () => {
recordRef: undefined,
type: addTransaction.type
});
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(28);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(29);

// ADD -> UPDATE -> Undo
trans.add(addTransaction);
Expand All @@ -261,7 +286,10 @@ describe('IgxTransaction', () => {
recordRef: undefined,
type: addTransaction.type
});
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(32);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(33);

// ADD -> UPDATE -> Undo -> Redo
trans.add(addTransaction);
Expand All @@ -274,7 +302,10 @@ describe('IgxTransaction', () => {
recordRef: undefined,
type: addTransaction.type
});
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(37);

trans.clear();
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(38);
});

it('Should add DELETE type transaction - all feasible paths', () => {
Expand Down Expand Up @@ -540,8 +571,10 @@ describe('IgxTransaction', () => {
expect(originalData[49]).toEqual('Added Row');
});

it('Should add pending transaction and push it to transaction log', () => {
it('Should add pending transaction and push it to transaction log, and correctly fires onStateUpdate', () => {
const trans = new IgxTransactionService();
spyOn(trans.onStateUpdate, 'emit').and.callThrough();

expect(trans).toBeDefined();
const recordRef = { key: 'Key1', value1: 1, value2: 2, value3: 3 };
let newValue: any = { key: 'Key1', value1: 10 };
Expand Down Expand Up @@ -585,10 +618,13 @@ describe('IgxTransaction', () => {
recordRef: recordRef,
type: updateTransaction.type
});
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(1);
});

it('Should not add pending transaction and push it to transaction log', () => {
it('Should not add pending transaction and push it to transaction log, and correctly fires onStateUpdate', () => {
const trans = new IgxTransactionService();
spyOn(trans.onStateUpdate, 'emit').and.callThrough();

expect(trans).toBeDefined();
const recordRef = { key: 'Key1', value1: 1, value2: 2, value3: 3 };
let newValue: any = { key: 'Key1', value1: 10 };
Expand All @@ -611,6 +647,7 @@ describe('IgxTransaction', () => {

expect(trans.getTransactionLog()).toEqual([]);
expect(trans.getAggregatedChanges(true)).toEqual([]);
expect(trans.onStateUpdate.emit).toHaveBeenCalledTimes(0);
});
});

Expand Down Expand Up @@ -682,6 +719,16 @@ describe('IgxTransaction', () => {
expect(transaction.getState(2)).toBeDefined();
expect(transaction.getState(2).type).toBe(TransactionType.DELETE);
});

it('Should correctly call getAggregatedChanges without commit when recordRef is null', () => {
const transaction = new IgxHierarchicalTransactionService();
expect(transaction).toBeDefined();

const deleteTransaction: HierarchicalTransaction = { id: 0, type: TransactionType.DELETE, newValue: null, path: [] };
transaction.add(deleteTransaction, 'Deleted row');

expect(transaction.getAggregatedChanges(false)).toEqual([deleteTransaction]);
});
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class IgxTransactionService<T extends Transaction, S extends State> exten
this._isPending = false;
if (commit) {
const actions: { transaction: T, recordRef: any }[] = [];
// don't use addTransaction due to custom undo handling
for (const transaction of this._pendingTransactions) {
const pendingState = this._pendingStates.get(transaction.id);
this._transactions.push(transaction);
Expand All @@ -125,6 +126,8 @@ export class IgxTransactionService<T extends Transaction, S extends State> exten

this._undoStack.push(actions);
this._redoStack = [];

this.onStateUpdate.emit();
}
super.endPending(commit);
}
Expand Down

0 comments on commit eceaa09

Please sign in to comment.