@@ -17,12 +17,23 @@ test('default pagination', () => {
1717test ( 'should reset the currentPageIndex to 1 when out of range' , ( ) => {
1818 const items = generateItems ( 25 ) ;
1919
20- // Page number is below the minimum
20+ // Page number is above the maximum
2121 let {
2222 items : processed ,
2323 pagesCount,
2424 actualPageIndex,
25- } = processItems ( items , { currentPageIndex : 0 } , { pagination : { } } ) ;
25+ } = processItems ( items , { currentPageIndex : 4 } , { pagination : { } } ) ;
26+ expect ( actualPageIndex ) . toEqual ( 1 ) ;
27+ expect ( pagesCount ) . toEqual ( 3 ) ;
28+ expect ( processed ) . toHaveLength ( 10 ) ;
29+ expect ( processed [ 0 ] ) . toEqual ( items [ 0 ] ) ;
30+
31+ // Page number is below the minimum
32+ ( {
33+ items : processed ,
34+ pagesCount,
35+ actualPageIndex,
36+ } = processItems ( items , { currentPageIndex : 0 } , { pagination : { } } ) ) ;
2637 expect ( actualPageIndex ) . toEqual ( 1 ) ;
2738 expect ( pagesCount ) . toEqual ( 3 ) ;
2839 expect ( processed ) . toHaveLength ( 10 ) ;
@@ -40,6 +51,19 @@ test('should reset the currentPageIndex to 1 when out of range', () => {
4051 expect ( processed [ 0 ] ) . toEqual ( items [ 0 ] ) ;
4152} ) ;
4253
54+ test ( 'should not reset the currentPageIndex if `allowPageOutOfRange=true`' , ( ) => {
55+ const items = generateItems ( 25 ) ;
56+
57+ const {
58+ items : processed ,
59+ pagesCount,
60+ actualPageIndex,
61+ } = processItems ( items , { currentPageIndex : 4 } , { pagination : { allowPageOutOfRange : true } } ) ;
62+ expect ( actualPageIndex ) . toEqual ( 4 ) ;
63+ expect ( pagesCount ) . toEqual ( 3 ) ;
64+ expect ( processed ) . toHaveLength ( 0 ) ;
65+ } ) ;
66+
4367test ( 'displays all items of it is less than the page size' , ( ) => {
4468 const items = generateItems ( 7 ) ;
4569 const { items : processed , pagesCount } = processItems ( items , { } , { pagination : { } } ) ;
@@ -87,18 +111,6 @@ test('displays the last page when the number of items is divisible by page size'
87111 expect ( processed [ 9 ] ) . toEqual ( items [ 19 ] ) ;
88112} ) ;
89113
90- test ( 'displays an out of range page' , ( ) => {
91- const items = generateItems ( 20 ) ;
92- const {
93- items : processed ,
94- pagesCount,
95- actualPageIndex,
96- } = processItems ( items , { currentPageIndex : 3 } , { pagination : { } } ) ;
97- expect ( actualPageIndex ) . toEqual ( 3 ) ;
98- expect ( pagesCount ) . toEqual ( 2 ) ;
99- expect ( processed ) . toHaveLength ( 0 ) ;
100- } ) ;
101-
102114test ( 'supports custom page size' , ( ) => {
103115 const items = generateItems ( 35 ) ;
104116 const { items : processed , pagesCount } = processItems (
0 commit comments