Skip to content

Commit

Permalink
Fix bug with Pager service when there are no items.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Dec 21, 2017
1 parent bd05694 commit 50a771e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/services/paging/pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export class Pager {
}

update = () => {
if (this.totalItems <= 0) {
this.totalPages = 0;
this.currentPageIndex = 0;
this.firstItemIndex = 0;
this.lastItemIndex = 0;
return;
}

this.totalPages = Math.ceil(this.totalItems / this.itemsPerPage);

// Ensure the current page falls within our range of total pages.
Expand Down
14 changes: 14 additions & 0 deletions src/services/paging/pager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,18 @@ describe('Pager', () => {
});
});
});

describe('behavior', () => {
describe('when there are no items', () => {
test('getFirstItemIndex defaults to 0', () => {
const pager = new Pager(0, 20);
expect(pager.getFirstItemIndex()).toBe(0);
});

test('getLastItemIndex defaults to 0', () => {
const pager = new Pager(0, 20);
expect(pager.getLastItemIndex()).toBe(0);
});
});
});
});

0 comments on commit 50a771e

Please sign in to comment.