Client - display pagination on workouts list
This commit is contained in:
@ -7,6 +7,7 @@ import {
|
||||
getNumberQueryValue,
|
||||
getStringQueryValue,
|
||||
getQuery,
|
||||
rangePagination,
|
||||
} from '@/utils/api'
|
||||
|
||||
const orderByList = ['admin', 'created_at', 'username', 'workouts_count']
|
||||
@ -236,3 +237,140 @@ describe('getQuery w/ default values and input pagination payload', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('rangePagination', () => {
|
||||
const testsParams = [
|
||||
{
|
||||
description: 'returns empty array if pages total equals 0',
|
||||
input: {
|
||||
currentPage: 1,
|
||||
pages: 0,
|
||||
},
|
||||
expectedPagination: [],
|
||||
},
|
||||
{
|
||||
description: 'returns empty array if pages total is a negative value',
|
||||
input: {
|
||||
currentPage: 1,
|
||||
pages: -1,
|
||||
},
|
||||
expectedPagination: [],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 1 and pages total equals 1',
|
||||
input: {
|
||||
currentPage: 1,
|
||||
pages: 1,
|
||||
},
|
||||
expectedPagination: [1],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 1 and pages total equals 4',
|
||||
input: {
|
||||
currentPage: 1,
|
||||
pages: 4,
|
||||
},
|
||||
expectedPagination: [1, 2, 3, 4],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 4 and pages total equals 8',
|
||||
input: {
|
||||
currentPage: 4,
|
||||
pages: 8,
|
||||
},
|
||||
expectedPagination: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
},
|
||||
{
|
||||
description: 'returns pagination if current page is 1 and total pages 10',
|
||||
input: {
|
||||
currentPage: 1,
|
||||
pages: 10,
|
||||
},
|
||||
expectedPagination: [1, 2, 3, 4, 5, '...', 9, 10],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 4 and pages total equals 10',
|
||||
input: {
|
||||
currentPage: 4,
|
||||
pages: 10,
|
||||
},
|
||||
expectedPagination: [1, 2, 3, 4, 5, 6, '...', 9, 10],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 7 and pages total equals 10',
|
||||
input: {
|
||||
currentPage: 7,
|
||||
pages: 10,
|
||||
},
|
||||
expectedPagination: [1, 2, '...', 5, 6, 7, 8, 9, 10],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 20 and pages total equals 30',
|
||||
input: {
|
||||
currentPage: 20,
|
||||
pages: 30,
|
||||
},
|
||||
expectedPagination: [1, 2, '...', 18, 19, 20, 21, 22, '...', 29, 30],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 1 and total pages 100',
|
||||
input: {
|
||||
currentPage: 1,
|
||||
pages: 100,
|
||||
},
|
||||
expectedPagination: [1, 2, 3, 4, 5, '...', 99, 100],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 5 and total pages 100',
|
||||
input: {
|
||||
currentPage: 5,
|
||||
pages: 100,
|
||||
},
|
||||
expectedPagination: [1, 2, 3, 4, 5, 6, 7, '...', 99, 100],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 50 and total pages 100',
|
||||
input: {
|
||||
currentPage: 50,
|
||||
pages: 100,
|
||||
},
|
||||
expectedPagination: [1, 2, '...', 48, 49, 50, 51, 52, '...', 99, 100],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 97 and total pages 100',
|
||||
input: {
|
||||
currentPage: 97,
|
||||
pages: 100,
|
||||
},
|
||||
expectedPagination: [1, 2, '...', 95, 96, 97, 98, 99, 100],
|
||||
},
|
||||
{
|
||||
description:
|
||||
'returns pagination if current page is 100 and total pages 100',
|
||||
input: {
|
||||
currentPage: 100,
|
||||
pages: 100,
|
||||
},
|
||||
expectedPagination: [1, 2, '...', 95, 96, 97, 98, 99, 100],
|
||||
},
|
||||
]
|
||||
|
||||
testsParams.map((testParams) => {
|
||||
it(testParams.description, () => {
|
||||
assert.deepEqual(
|
||||
rangePagination(testParams.input.pages, testParams.input.currentPage),
|
||||
testParams.expectedPagination
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user