Blog and category archives now show a numbered page list (first, last, current +/-1, collapsing gaps into an ellipsis) instead of only previous/next — see shared/utils/pagination.ts's paginationRange(). Renders page links via NuxtLink's custom/v-slot API rather than letting it render its own <a>: RouterLink's built-in active-class/aria-current detection compares only the route's path, not its query string, so every ?page=N link was incorrectly marked as the current page. The language switch now shows both "Italiano / English" at all times, with the current one as plain non-interactive text and the other as a link, moved to the header's top-right corner instead of stacked under the logo.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { paginationRange } from '../../frontend/shared/utils/pagination'
|
|
|
|
describe('paginationRange', () => {
|
|
it('returns an empty array for zero or negative totals', () => {
|
|
expect(paginationRange(1, 0)).toEqual([])
|
|
})
|
|
|
|
it('returns every page when the total fits within the visible window', () => {
|
|
expect(paginationRange(1, 5)).toEqual([1, 2, 3, 4, 5])
|
|
expect(paginationRange(3, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
|
|
})
|
|
|
|
it('collapses the right side when near the start', () => {
|
|
expect(paginationRange(1, 20)).toEqual([1, 2, 3, 4, 5, 'ellipsis', 20])
|
|
expect(paginationRange(2, 20)).toEqual([1, 2, 3, 4, 5, 'ellipsis', 20])
|
|
})
|
|
|
|
it('collapses the left side when near the end', () => {
|
|
expect(paginationRange(20, 20)).toEqual([1, 'ellipsis', 16, 17, 18, 19, 20])
|
|
expect(paginationRange(19, 20)).toEqual([1, 'ellipsis', 16, 17, 18, 19, 20])
|
|
})
|
|
|
|
it('collapses both sides when in the middle', () => {
|
|
expect(paginationRange(10, 20)).toEqual([1, 'ellipsis', 9, 10, 11, 'ellipsis', 20])
|
|
})
|
|
|
|
it('always includes the current page', () => {
|
|
for (let current = 1; current <= 27; current++) {
|
|
expect(paginationRange(current, 27)).toContain(current)
|
|
}
|
|
})
|
|
})
|