File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,14 @@ export class Pager {
55
55
}
56
56
57
57
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
+
58
66
this . totalPages = Math . ceil ( this . totalItems / this . itemsPerPage ) ;
59
67
60
68
// Ensure the current page falls within our range of total pages.
Original file line number Diff line number Diff line change @@ -137,4 +137,18 @@ describe('Pager', () => {
137
137
} ) ;
138
138
} ) ;
139
139
} ) ;
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
+ } ) ;
140
154
} ) ;
You can’t perform that action at this time.
0 commit comments