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)
46 lines (39 loc) • 1.43 kB
text/typescript
import calculationStartPageAndEndPage from '../../src/utils/calculationStartPageAndEndPage'
describe('CalculationStartPageAndEndPage', () => {
it('should calculate the start and end page when all pages fit in the window', () => {
expect(calculationStartPageAndEndPage(10, 10, 5)).toStrictEqual({
endPage: 10,
startPage: 1,
})
})
it('should show all pages when total pages is less than maxPages', () => {
expect(calculationStartPageAndEndPage(3, 10, 2)).toStrictEqual({
startPage: 1,
endPage: 3,
})
})
it('should keep the window at the beginning when currentPage is near the first page', () => {
expect(calculationStartPageAndEndPage(20, 10, 2)).toStrictEqual({
startPage: 1,
endPage: 10,
})
})
it('should keep the window at the end when currentPage is near the last page', () => {
expect(calculationStartPageAndEndPage(20, 10, 19)).toStrictEqual({
startPage: 11,
endPage: 20,
})
})
it('should center the window when currentPage is in the middle', () => {
expect(calculationStartPageAndEndPage(20, 10, 10)).toStrictEqual({
startPage: 5,
endPage: 14,
})
})
it('should return the same start and end page when there is only one page', () => {
expect(calculationStartPageAndEndPage(1, 10, 1)).toStrictEqual({
startPage: 1,
endPage: 1,
})
})
})