Skip to content

Commit

Permalink
test(transaction): deleting w/ transactions + paging in grid, #3425
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSlavov committed Dec 14, 2018
1 parent ae21495 commit b6b6825
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -2865,6 +2865,89 @@ describe('IgxGrid Component Tests', () => {
expect(targetRowElement.classList).toContain('igx-grid__tr--edited', 'row does not contain edited class w/ edits');
expect(targetCellElement.classList).toContain('igx-grid__td--edited', 'cell does not contain edited class w/ edits');
}));

it('Should change pages when the only item on the last page is a pending added row that gets deleted', fakeAsync(() => {
const fixture = TestBed.createComponent(IgxGridRowEditingTransactionComponent);
fixture.detectChanges();

const grid = fixture.componentInstance.grid;
expect(grid.data.length).toEqual(10);
grid.paging = true;
grid.perPage = 5;
fixture.detectChanges();
tick();
expect(grid.totalPages).toEqual(2);
grid.addRow({
ProductID: 123,
ProductName: 'DummyItem',
InStock: true,
UnitsInStock: 1,
OrderDate: new Date()
});
fixture.detectChanges();
tick();
expect(grid.totalPages).toEqual(3);
grid.page = 2;
tick();
fixture.detectChanges();
expect(grid.page).toEqual(2);
grid.deleteRowById(123);
tick();
fixture.detectChanges();
// This is behaving incorrectly - if there is only 1 transaction and it is an ADD transaction on the last page
// Deleting the ADD transaction on the last page will trigger grid.page-- TWICE
expect(grid.page).toEqual(0); // Should be 1
expect(grid.totalPages).toEqual(2);
}));

it('Should change pages when commiting deletes on the last page', fakeAsync(() => {
const fixture = TestBed.createComponent(IgxGridRowEditingTransactionComponent);
fixture.detectChanges();

const grid = fixture.componentInstance.grid;
expect(grid.data.length).toEqual(10);
grid.paging = true;
grid.perPage = 5;
fixture.detectChanges();
tick();
expect(grid.totalPages).toEqual(2);
grid.page = 1;
tick();
fixture.detectChanges();
expect(grid.page).toEqual(1);
for (let i = 0; i < grid.data.length / 2; i++) {
grid.deleteRowById(grid.data.reverse()[i].ProductID);
}
fixture.detectChanges();
tick();
expect(grid.page).toEqual(1);
grid.transactions.commit(grid.data);
fixture.detectChanges();
tick();
expect(grid.page).toEqual(0);
expect(grid.totalPages).toEqual(1);
}));

it('Should NOT change pages when deleting a row on the last page', fakeAsync(() => {
const fixture = TestBed.createComponent(IgxGridRowEditingTransactionComponent);
fixture.detectChanges();
const grid = fixture.componentInstance.grid;
grid.paging = true;
grid.perPage = 5;
fixture.detectChanges();
tick();
expect(grid.totalPages).toEqual(2);
expect(grid.data.length).toEqual(10);
grid.page = 1;
tick();
fixture.detectChanges();
expect(grid.page).toEqual(1);
grid.deleteRowById(grid.data[grid.data.length - 1].ProductID);
fixture.detectChanges();
tick();
expect(grid.page).toEqual(1);
expect(grid.totalPages).toEqual(2);
}));
});

describe('Row Editing - Grouping', () => {

0 comments on commit b6b6825

Please sign in to comment.