Skip to content

Commit 50a771e

Browse files
committed
Fix bug with Pager service when there are no items.
1 parent bd05694 commit 50a771e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/services/paging/pager.js

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ export class Pager {
5555
}
5656

5757
update = () => {
58+
if (this.totalItems <= 0) {
59+
this.totalPages = 0;
60+
this.currentPageIndex = 0;
61+
this.firstItemIndex = 0;
62+
this.lastItemIndex = 0;
63+
return;
64+
}
65+
5866
this.totalPages = Math.ceil(this.totalItems / this.itemsPerPage);
5967

6068
// Ensure the current page falls within our range of total pages.

src/services/paging/pager.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,18 @@ describe('Pager', () => {
137137
});
138138
});
139139
});
140+
141+
describe('behavior', () => {
142+
describe('when there are no items', () => {
143+
test('getFirstItemIndex defaults to 0', () => {
144+
const pager = new Pager(0, 20);
145+
expect(pager.getFirstItemIndex()).toBe(0);
146+
});
147+
148+
test('getLastItemIndex defaults to 0', () => {
149+
const pager = new Pager(0, 20);
150+
expect(pager.getLastItemIndex()).toBe(0);
151+
});
152+
});
153+
});
140154
});

0 commit comments

Comments
 (0)