pagination-front-end
Version:
pagination-front-end é uma biblioteca voltada para realização de paginação no front end( pagination-front-end is a front-end paging library)
51 lines (43 loc) • 1.39 kB
text/typescript
import indiceCalculation from '../../src/utils/indiceCalculation'
describe('IndiceCalculation', () => {
it('should calculate the indexes', () => {
expect(indiceCalculation(20, 60, 1, 1, 3)).toStrictEqual({
endIndex: 19,
pages: [1, 2, 3],
startIndex: 0,
})
})
it('should calculate indexes for the second page', () => {
expect(indiceCalculation(5, 12, 2, 1, 3)).toStrictEqual({
startIndex: 5,
endIndex: 9,
pages: [1, 2, 3],
})
})
it('should calculate indexes for the last page with fewer items', () => {
expect(indiceCalculation(5, 12, 3, 1, 3)).toStrictEqual({
startIndex: 10,
endIndex: 11,
pages: [1, 2, 3],
})
})
it('should return a single page in the pages array', () => {
expect(indiceCalculation(10, 3, 1, 1, 1)).toStrictEqual({
startIndex: 0,
endIndex: 2,
pages: [1],
})
})
it('should build the pages window when startPage and endPage differ', () => {
expect(indiceCalculation(5, 50, 5, 3, 7)).toStrictEqual({
startIndex: 20,
endIndex: 24,
pages: [3, 4, 5, 6, 7],
})
})
it('should not exceed the last item index on the final page', () => {
const result = indiceCalculation(5, 7, 2, 1, 2)
expect(result.startIndex).toBe(5)
expect(result.endIndex).toBe(6)
})
})