- <SeoPagination> (UI-SPEC L2): previous and next (left out at the ends), page 1, the last page and five pages around the current one with gap items; nothing when last <= 1; props current, last, labels, classPrefix, locale - usePagination(): hrefs in the CMS form (resolve answer, then site answer, then seo.pagination), other query parameters kept, page 1 unnumbered, <link rel=prev/next> in the head - the CMS head fills %pages% in the title and description once the listing's page count is known (seoFillPages) - seoPaginationWindow, seoPageHref, seoPageNumber; L2 default styles
20 lines
1.0 KiB
TypeScript
20 lines
1.0 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { seoPaginationWindow } from '../app/utils/paginationWindow.ts'
|
|
|
|
test('seoPaginationWindow: the UI-SPEC L2 examples', () => {
|
|
assert.deepEqual(seoPaginationWindow(5, 14), [1, 'gap', 3, 4, 5, 6, 7, 'gap', 14])
|
|
assert.deepEqual(seoPaginationWindow(1, 3), [1, 2, 3])
|
|
assert.deepEqual(seoPaginationWindow(14, 14), [1, 'gap', 10, 11, 12, 13, 14])
|
|
})
|
|
|
|
test('seoPaginationWindow: near the ends and small listings', () => {
|
|
assert.deepEqual(seoPaginationWindow(1, 14), [1, 2, 3, 4, 5, 'gap', 14])
|
|
assert.deepEqual(seoPaginationWindow(4, 14), [1, 2, 3, 4, 5, 6, 'gap', 14], 'no gap when only page 1 lies outside')
|
|
assert.deepEqual(seoPaginationWindow(11, 14), [1, 'gap', 9, 10, 11, 12, 13, 14])
|
|
assert.deepEqual(seoPaginationWindow(1, 1), [1])
|
|
assert.deepEqual(seoPaginationWindow(3, 6), [1, 2, 3, 4, 5, 6])
|
|
assert.deepEqual(seoPaginationWindow(1, 0), [])
|
|
assert.deepEqual(seoPaginationWindow(99, 3), [1, 2, 3], 'the current page is clamped')
|
|
})
|