Skip to content

Commit 3061ab2

Browse files
moeyang13mportuga
moeyang13
authored andcommitted
fix: 🐛 added unit testing for lastRowCol in cellNav and loadData
1 parent 5200747 commit 3061ab2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

packages/infinite-scroll/test/infiniteScroll.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,45 @@
345345
expect(grid.api.infiniteScroll.raise.needLoadMoreData).not.toHaveBeenCalled();
346346
});
347347
});
348+
describe('cellNav and loadData', function() {
349+
var arrayOf50 = [];
350+
var VisibleRowCount = 50;
351+
var lastRowIndex = 49;
352+
beforeEach(function() {
353+
grid.infiniteScroll = undefined;
354+
uiGridInfiniteScrollService.initializeGrid(grid, $scope);
355+
spyOn(grid, 'getVisibleRowCount').and.returnValue(VisibleRowCount);
356+
spyOn(grid.api.infiniteScroll.raise, 'needLoadMoreData');
357+
spyOn(grid.api.infiniteScroll.raise, 'needLoadMoreDataTop');
358+
for ( var i = 0; i < VisibleRowCount; i++ ) {
359+
arrayOf50.push(i);
360+
}
361+
grid.cellNav = {
362+
lastRowCol: {
363+
row: {
364+
index: 0
365+
}
366+
}
367+
};
368+
grid.renderContainers = { body: { visibleRowCache: arrayOf50}};
369+
});
370+
afterEach(function() {
371+
grid.api.infiniteScroll.raise.needLoadMoreData.calls.reset();
372+
grid.api.infiniteScroll.raise.needLoadMoreDataTop.calls.reset();
373+
});
374+
it('scroll down and last row is currently selected', function() {
375+
grid.scrollDirection = uiGridConstants.scrollDirection.DOWN;
376+
grid.infiniteScroll.scrollDown = true;
377+
grid.cellNav.lastRowCol.row.index = lastRowIndex;
378+
379+
uiGridInfiniteScrollService.loadData(grid);
380+
381+
expect(grid.infiniteScroll.previousVisibleRows).toEqual(grid.getVisibleRowCount());
382+
expect(grid.api.infiniteScroll.raise.needLoadMoreData).not.toHaveBeenCalled();
383+
expect(grid.infiniteScroll.direction).toEqual(uiGridConstants.scrollDirection.DOWN);
384+
});
385+
});
386+
348387
describe('handleScroll', function() {
349388
describe('when the source is the even "ui.grid.adjustInfiniteScrollPosition"', function() {
350389
beforeEach(function() {

0 commit comments

Comments
 (0)