- <SeoBreadcrumbs> (UI-SPEC L1): the resolve answer's trail as nav > ol with server-rendered links and the last item as aria-current text; nothing with fewer than two items, with page meta seo.breadcrumbs false or with the option seo.breadcrumbs false; props items, label, hideCurrent, locale - one trail per page: the first rendered instance claims it (seoClaimBreadcrumbs, kept per path) - seoSitePath: same-origin CMS URLs become paths, non-http(s) URLs are never links; useSeoLabels takes an optional locale - L1 default styles with CSS-generated separators
34 lines
1.7 KiB
TypeScript
34 lines
1.7 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { seoClaimBreadcrumbs, seoReleaseBreadcrumbs } from '../app/utils/breadcrumbClaim.ts'
|
|
import { seoSitePath } from '../app/utils/sitePath.ts'
|
|
|
|
test('seoClaimBreadcrumbs: the first instance of a path owns the trail (layout plus page: one trail)', () => {
|
|
const layout = seoClaimBreadcrumbs(null, '/blog/x', 'layout')
|
|
assert.equal(layout.owns, true)
|
|
const page = seoClaimBreadcrumbs(layout.state, '/blog/x', 'page')
|
|
assert.equal(page.owns, false)
|
|
assert.deepEqual(page.state, { path: '/blog/x', id: 'layout' })
|
|
assert.equal(seoClaimBreadcrumbs(page.state, '/blog/x', 'layout').owns, true, 'a re-render keeps the claim')
|
|
})
|
|
|
|
test('seoClaimBreadcrumbs: a new path hands the claim out again', () => {
|
|
const first = seoClaimBreadcrumbs({ path: '/a', id: 'page-a' }, '/b', 'layout')
|
|
assert.equal(first.owns, true)
|
|
assert.deepEqual(first.state, { path: '/b', id: 'layout' })
|
|
})
|
|
|
|
test('seoReleaseBreadcrumbs: only the owner releases', () => {
|
|
assert.equal(seoReleaseBreadcrumbs({ path: '/a', id: 'x' }, 'x'), null)
|
|
assert.deepEqual(seoReleaseBreadcrumbs({ path: '/a', id: 'x' }, 'y'), { path: '/a', id: 'x' })
|
|
})
|
|
|
|
test('seoSitePath: same-origin URLs become paths', () => {
|
|
assert.equal(seoSitePath('https://example.test/blog/x?a=1', 'https://example.test'), '/blog/x?a=1')
|
|
assert.equal(seoSitePath('https://example.test/', 'https://example.test/'), '/')
|
|
assert.equal(seoSitePath('https://other.test/x', 'https://example.test'), 'https://other.test/x')
|
|
assert.equal(seoSitePath('/x', undefined), '/x')
|
|
assert.equal(seoSitePath('javascript:alert(1)', 'https://example.test'), '')
|
|
assert.equal(seoSitePath('not a url', 'https://example.test'), '')
|
|
})
|