mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add paginate test
This commit is contained in:
parent
c0581c633b
commit
fef9002c8f
1 changed files with 45 additions and 0 deletions
|
|
@ -9,6 +9,9 @@ import {
|
|||
fuzzyMatchesWholeWord,
|
||||
eitherMatches
|
||||
} from '~/helpers/matching.js'
|
||||
import {
|
||||
PaginatedList
|
||||
} from '~/helpers/api/pagination.js'
|
||||
|
||||
|
||||
require('dotenv').config()
|
||||
|
|
@ -178,3 +181,45 @@ test('Can match names with pluses', (t) => {
|
|||
})
|
||||
|
||||
|
||||
test('Can paginate', async (t) => {
|
||||
const cases = [
|
||||
{
|
||||
from: {
|
||||
list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
perPage: 2,
|
||||
},
|
||||
expect: {
|
||||
pageCount: 5,
|
||||
pages: [
|
||||
{
|
||||
number: 1,
|
||||
items: [1, 2],
|
||||
json: '[1,2]'
|
||||
},
|
||||
{
|
||||
number: 2,
|
||||
items: [3, 4],
|
||||
json: '[3,4]'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
for ( const { from, expect } of cases ) {
|
||||
|
||||
const paginatedList = new PaginatedList( from )
|
||||
|
||||
// Assert that page count is correct
|
||||
t.is( paginatedList.pageCount, expect.pageCount, 'pageCount is incorrect' )
|
||||
|
||||
// Assert that the pages we're expecting are there
|
||||
for ( const expectedPage of expect.pages ) {
|
||||
// Get respective output page
|
||||
const outputPage = paginatedList.pages[ expectedPage.number - 1 ]
|
||||
|
||||
t.deepEqual( outputPage, expectedPage, `Page ${ expectedPage.number } is an unexpected structure` )
|
||||
}
|
||||
}
|
||||
|
||||
} )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue