- post, index, category, tag and author pages render <SeoBreadcrumbs> at the top of their content while journal.breadcrumbs is on (default); false leaves the trail to the site's layout, the BreadcrumbList data is unchanged - JournalPagination renders <SeoPagination class-prefix="journal-pagination"> with the journal's labels: the same class names, plus page 1, the last page, gap items, aria labels and head rel prev/next, with links in the CMS's pagination form - with vue-seo-layer's seo.pagination.form 'path' the module registers <listing>/<segment>/:page routes (journalPagedRoutes), and the listing pages read the page from the :page param or ?page (pageFromRoute) - the category pillar text renders on page 1 only, the description on every page; an h1 in it becomes h2 while the category row's content_h1_to_h2 is on (absent counts as on)
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
// ?page=N parsing, out-of-range detection and the page window.
|
|
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { pageFromRoute, pageOutOfRange, paginationWindow, parsePageParam } from '../app/utils/pagination.ts'
|
|
|
|
test('a missing page is page 1', () => {
|
|
assert.equal(parsePageParam(undefined), 1)
|
|
assert.equal(parsePageParam(null), 1)
|
|
})
|
|
|
|
test('a string of digits above 0 is that page', () => {
|
|
assert.equal(parsePageParam('1'), 1)
|
|
assert.equal(parsePageParam('2'), 2)
|
|
assert.equal(parsePageParam('017'), 17)
|
|
})
|
|
|
|
test('anything else is a 404 (null)', () => {
|
|
for (const raw of ['0', '-1', '1.5', 'abc', '', ' 2', '2 ', '1e3', '0x2', '99999999999999999999']) {
|
|
assert.equal(parsePageParam(raw), null, JSON.stringify(raw))
|
|
}
|
|
assert.equal(parsePageParam(['2']), null)
|
|
assert.equal(parsePageParam(2), null)
|
|
})
|
|
|
|
test('pageOutOfRange: past the last page only, page 1 never', () => {
|
|
assert.equal(pageOutOfRange(3, 2), true)
|
|
assert.equal(pageOutOfRange(2, 2), false)
|
|
assert.equal(pageOutOfRange(1, 0), false)
|
|
assert.equal(pageOutOfRange(1, 1), false)
|
|
assert.equal(pageOutOfRange(2, 0), true)
|
|
})
|
|
|
|
test('paginationWindow centres on the current page', () => {
|
|
assert.deepEqual(paginationWindow(5, 10), [3, 4, 5, 6, 7])
|
|
})
|
|
|
|
test('paginationWindow stays full width near either end', () => {
|
|
assert.deepEqual(paginationWindow(1, 10), [1, 2, 3, 4, 5])
|
|
assert.deepEqual(paginationWindow(10, 10), [6, 7, 8, 9, 10])
|
|
assert.deepEqual(paginationWindow(9, 10, 3), [8, 9, 10])
|
|
})
|
|
|
|
test('paginationWindow clips to the page count and handles empty input', () => {
|
|
assert.deepEqual(paginationWindow(1, 2), [1, 2])
|
|
assert.deepEqual(paginationWindow(1, 0), [])
|
|
assert.deepEqual(paginationWindow(1, 5, 0), [])
|
|
})
|
|
|
|
test('pageFromRoute reads the path-form :page param, else ?page', () => {
|
|
assert.equal(pageFromRoute({ params: { page: '3' }, query: { page: '5' } }), 3)
|
|
assert.equal(pageFromRoute({ params: {}, query: { page: '5' } }), 5)
|
|
assert.equal(pageFromRoute({ params: {}, query: {} }), 1)
|
|
assert.equal(pageFromRoute({ params: { page: '0' } }), null)
|
|
assert.equal(pageFromRoute({ params: { page: 'x' } }), null)
|
|
assert.equal(pageFromRoute({}), 1)
|
|
})
|