Skip to content

Commit 6c9a423

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Add some tests for snackbar navigation in grid.
1 parent 047ac66 commit 6c9a423

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { By } from '@angular/platform-browser';
1212
import { IgxActionStripComponent } from '../../action-strip/action-strip.component';
1313
import { IgxActionStripModule } from '../../action-strip/action-strip.module';
14-
import { UIInteractions } from '../../test-utils/ui-interactions.spec';
14+
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
1515

1616
describe('IgxGrid - Row Adding #grid', () => {
1717
let fixture;
@@ -111,5 +111,69 @@ describe('IgxGrid - Row Adding #grid', () => {
111111
expect(grid.getRowByIndex(1).addRow).toBeFalse();
112112
});
113113

114+
it('should navigate to added row on snackbar button click.', async() => {
115+
const rows = grid.rowList.toArray();
116+
const dataCount = grid.data.length;
117+
rows[0].beginAddRow();
118+
fixture.detectChanges();
119+
120+
grid.endEdit(true);
121+
fixture.detectChanges();
122+
123+
// check row is in data
124+
expect(grid.data.length).toBe(dataCount + 1);
125+
126+
const addedRec = grid.data[grid.data.length - 1];
127+
128+
grid.addRowSnackbar.triggerAction();
129+
fixture.detectChanges();
130+
131+
await wait(100);
132+
fixture.detectChanges();
133+
134+
// check added row is rendered and is in view
135+
const row = grid.getRowByKey(addedRec[grid.primaryKey]);
136+
expect(row).not.toBeNull();
137+
const gridOffsets = grid.tbody.nativeElement.getBoundingClientRect();
138+
const rowOffsets = row.nativeElement.getBoundingClientRect();
139+
expect(rowOffsets.top >= gridOffsets.top && rowOffsets.bottom <= gridOffsets.bottom).toBeTruthy();
140+
});
141+
142+
it('should navigate to added row on snackbar button click when row is not in current view.', async() => {
143+
grid.paging = true;
144+
grid.perPage = 5;
145+
fixture.detectChanges();
146+
147+
const rows = grid.rowList.toArray();
148+
const dataCount = grid.data.length;
149+
150+
rows[0].beginAddRow();
151+
fixture.detectChanges();
152+
153+
grid.endEdit(true);
154+
fixture.detectChanges();
155+
156+
// check row is in data
157+
expect(grid.data.length).toBe(dataCount + 1);
158+
159+
const addedRec = grid.data[grid.data.length - 1];
160+
161+
grid.addRowSnackbar.triggerAction();
162+
fixture.detectChanges();
163+
164+
await wait(100);
165+
fixture.detectChanges();
166+
167+
// check page is correct
168+
expect(grid.page).toBe(5);
169+
170+
// check added row is rendered and is in view
171+
const row = grid.getRowByKey(addedRec[grid.primaryKey]);
172+
expect(row).not.toBeNull();
173+
const gridOffsets = grid.tbody.nativeElement.getBoundingClientRect();
174+
const rowOffsets = row.nativeElement.getBoundingClientRect();
175+
expect(rowOffsets.top >= gridOffsets.top && rowOffsets.bottom <= gridOffsets.bottom).toBeTruthy();
176+
});
177+
114178
});
115179
});

0 commit comments

Comments
 (0)