1- import { calculatePagination } from '../index'
1+ import { calculatePagination , IndexType } from '../index'
22
33it ( 'should return no pagination if not enough items are given' , ( ) => {
44 const page = 0
55 const size = 5
66 const total = 2
7- const pagination = calculatePagination ( page , size , total , { firstPage : 0 } )
7+ const pagination = calculatePagination ( page , size , total , {
8+ indexType : IndexType . ZERO_BASED ,
9+ } )
810
911 expect ( pagination ) . toBeNull ( )
1012} )
1113it ( 'should return only a few pages' , ( ) => {
1214 const page = 1
1315 const size = 5
1416 const total = 15
15- const pagination = calculatePagination ( page , size , total , { firstPage : 0 } )
17+ const pagination = calculatePagination ( page , size , total , {
18+ indexType : IndexType . ZERO_BASED ,
19+ } )
1620
1721 expect ( pagination ) . not . toBeNull ( )
1822 expect ( pagination ?. pages ) . toHaveLength ( 3 )
1923
20- expect ( pagination ?. pages [ 0 ] . number ) . toBe ( 0 )
24+ expect ( pagination ?. pages [ 0 ] . indexNumber ) . toBe ( 0 )
25+ expect ( pagination ?. pages [ 0 ] . displayNumber ) . toBe ( 1 )
2126 expect ( pagination ?. pages [ 0 ] . isCurrent ) . toBeFalsy ( )
22- expect ( pagination ?. pages [ 1 ] . number ) . toBe ( 1 )
27+ expect ( pagination ?. pages [ 1 ] . indexNumber ) . toBe ( 1 )
28+ expect ( pagination ?. pages [ 1 ] . displayNumber ) . toBe ( 2 )
2329 expect ( pagination ?. pages [ 1 ] . isCurrent ) . toBeTruthy ( )
24- expect ( pagination ?. pages [ 2 ] . number ) . toBe ( 2 )
30+ expect ( pagination ?. pages [ 2 ] . indexNumber ) . toBe ( 2 )
31+ expect ( pagination ?. pages [ 2 ] . displayNumber ) . toBe ( 3 )
2532 expect ( pagination ?. pages [ 2 ] . isCurrent ) . toBeFalsy ( )
2633} )
2734it ( 'should return the maximum number of pages' , ( ) => {
@@ -30,36 +37,43 @@ it('should return the maximum number of pages', () => {
3037 const total = 50
3138 const maxPages = 5
3239 const pagination = calculatePagination ( page , size , total , {
33- firstPage : 0 ,
40+ indexType : IndexType . ZERO_BASED ,
3441 maxPages : maxPages ,
3542 } )
3643
3744 expect ( pagination ) . not . toBeNull ( )
3845 expect ( pagination ?. pages ) . toHaveLength ( 5 )
3946
40- expect ( pagination ?. pages [ 0 ] . number ) . toBe ( 2 )
47+ expect ( pagination ?. pages [ 0 ] . indexNumber ) . toBe ( 2 )
48+ expect ( pagination ?. pages [ 0 ] . displayNumber ) . toBe ( 3 )
4149 expect ( pagination ?. pages [ 0 ] . isCurrent ) . toBeFalsy ( )
42- expect ( pagination ?. pages [ 1 ] . number ) . toBe ( 3 )
50+ expect ( pagination ?. pages [ 1 ] . indexNumber ) . toBe ( 3 )
51+ expect ( pagination ?. pages [ 1 ] . displayNumber ) . toBe ( 4 )
4352 expect ( pagination ?. pages [ 1 ] . isCurrent ) . toBeFalsy ( )
44- expect ( pagination ?. pages [ 2 ] . number ) . toBe ( 4 )
53+ expect ( pagination ?. pages [ 2 ] . indexNumber ) . toBe ( 4 )
54+ expect ( pagination ?. pages [ 2 ] . displayNumber ) . toBe ( 5 )
4555 expect ( pagination ?. pages [ 2 ] . isCurrent ) . toBeTruthy ( )
46- expect ( pagination ?. pages [ 3 ] . number ) . toBe ( 5 )
56+ expect ( pagination ?. pages [ 3 ] . indexNumber ) . toBe ( 5 )
57+ expect ( pagination ?. pages [ 3 ] . displayNumber ) . toBe ( 6 )
4758 expect ( pagination ?. pages [ 3 ] . isCurrent ) . toBeFalsy ( )
48- expect ( pagination ?. pages [ 4 ] . number ) . toBe ( 6 )
59+ expect ( pagination ?. pages [ 4 ] . indexNumber ) . toBe ( 6 )
60+ expect ( pagination ?. pages [ 4 ] . displayNumber ) . toBe ( 7 )
4961 expect ( pagination ?. pages [ 4 ] . isCurrent ) . toBeFalsy ( )
5062} )
5163it ( 'should disable the previous link' , ( ) => {
5264 const page = 0
5365 const size = 5
5466 const total = 10
55- const pagination = calculatePagination ( page , size , total , { firstPage : 0 } )
67+ const pagination = calculatePagination ( page , size , total , {
68+ indexType : IndexType . ZERO_BASED ,
69+ } )
5670
5771 expect ( pagination ) . not . toBeNull ( )
5872
59- expect ( pagination ?. previous . number ) . toBe ( 0 )
73+ expect ( pagination ?. previous . indexNumber ) . toBe ( 0 )
6074 expect ( pagination ?. previous . isDisabled ) . toBeTruthy ( )
6175
62- expect ( pagination ?. next . number ) . toBe ( 1 )
76+ expect ( pagination ?. next . indexNumber ) . toBe ( 1 )
6377 expect ( pagination ?. next . isDisabled ) . toBeFalsy ( )
6478
6579 expect ( pagination ?. pages [ 0 ] . isCurrent ) . toBeTruthy ( )
@@ -69,14 +83,16 @@ it('should disable the next link', () => {
6983 const page = 1
7084 const size = 5
7185 const total = 10
72- const pagination = calculatePagination ( page , size , total , { firstPage : 0 } )
86+ const pagination = calculatePagination ( page , size , total , {
87+ indexType : IndexType . ZERO_BASED ,
88+ } )
7389
7490 expect ( pagination ) . not . toBeNull ( )
7591
76- expect ( pagination ?. previous . number ) . toBe ( 0 )
92+ expect ( pagination ?. previous . indexNumber ) . toBe ( 0 )
7793 expect ( pagination ?. previous . isDisabled ) . toBeFalsy ( )
7894
79- expect ( pagination ?. next . number ) . toBe ( 1 )
95+ expect ( pagination ?. next . indexNumber ) . toBe ( 1 )
8096 expect ( pagination ?. next . isDisabled ) . toBeTruthy ( )
8197
8298 expect ( pagination ?. pages [ 0 ] . isCurrent ) . toBeFalsy ( )
0 commit comments