33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|||
|
|
import { createPaginationItems, normalizePage, normalizePageSizes } from './DataTable.vue'
|
||
|
|
|
||
|
|
describe('DataTable pagination helpers', () => {
|
||
|
|
it('normalizes page-size options', () => {
|
||
|
|
expect(normalizePageSizes([20, 10, 20, 0, -1, 0.8, 10.8])).toEqual([20, 10])
|
||
|
|
expect(normalizePageSizes([])).toEqual([10])
|
||
|
|
})
|
||
|
|
|
||
|
|
it('keeps the page inside the available range', () => {
|
||
|
|
expect(normalizePage(0, 8)).toBe(1)
|
||
|
|
expect(normalizePage(12, 8)).toBe(8)
|
||
|
|
expect(normalizePage(3.8, 8)).toBe(3)
|
||
|
|
expect(normalizePage(Number.NaN, 8)).toBe(1)
|
||
|
|
expect(normalizePage(4, 0)).toBe(1)
|
||
|
|
expect(normalizePage(4, Number.NaN)).toBe(1)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('does not create page buttons for an empty result', () => {
|
||
|
|
expect(createPaginationItems(1, 0)).toEqual([])
|
||
|
|
})
|
||
|
|
|
||
|
|
it('shows all pages for a short result set', () => {
|
||
|
|
expect(createPaginationItems(3, 5)).toEqual([1, 2, 3, 4, 5])
|
||
|
|
})
|
||
|
|
|
||
|
|
it('keeps first and last pages visible for long result sets', () => {
|
||
|
|
expect(createPaginationItems(1, 30)).toEqual([1, 2, 3, 4, 5, 'ellipsis-end', 30])
|
||
|
|
expect(createPaginationItems(15, 30)).toEqual([1, 'ellipsis-start', 14, 15, 16, 'ellipsis-end', 30])
|
||
|
|
expect(createPaginationItems(30, 30)).toEqual([1, 'ellipsis-start', 26, 27, 28, 29, 30])
|
||
|
|
})
|
||
|
|
})
|