test: the post title element for every postTitleTag and H1 setting
auto follows content_h1_to_h2 (p only when it is false, h1 when the key is absent), h1 and p force the element, any other option value is auto.
This commit is contained in:
38
tests/postTitle.test.ts
Normal file
38
tests/postTitle.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// The post title's element (UI-SPEC L6, D-50): journal.postTitleTag x the
|
||||
// Journal H1 setting (content_h1_to_h2 on the post answer), so a post page
|
||||
// keeps exactly one H1. 'auto' (and any other value, as the module reads
|
||||
// the option) follows the setting: h1 while body H1s become H2s or when
|
||||
// the answer does not carry the key (a backend before the setting), p
|
||||
// while the body keeps its own H1; 'h1' and 'p' force the element.
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { journalPostTitleTag } from '../app/utils/seo.ts'
|
||||
import type { JournalPost } from '../app/utils/types.ts'
|
||||
|
||||
const settings = [true, false, undefined, null] as const
|
||||
|
||||
test('auto follows content_h1_to_h2: p only when it is false', () => {
|
||||
const want = { true: 'h1', false: 'p', undefined: 'h1', null: 'h1' } as const
|
||||
for (const s of settings) assert.equal(journalPostTitleTag('auto', s), want[String(s) as keyof typeof want], `auto x ${s}`)
|
||||
})
|
||||
|
||||
test('h1 and p force the element whatever the setting', () => {
|
||||
for (const s of settings) {
|
||||
assert.equal(journalPostTitleTag('h1', s), 'h1', `h1 x ${s}`)
|
||||
assert.equal(journalPostTitleTag('p', s), 'p', `p x ${s}`)
|
||||
}
|
||||
})
|
||||
|
||||
test('any other option value is auto', () => {
|
||||
for (const option of [undefined, null, '', 'H1', 'h2', 'span', 1, true, {}]) {
|
||||
assert.equal(journalPostTitleTag(option, true), 'h1', `${JSON.stringify(option)} x true`)
|
||||
assert.equal(journalPostTitleTag(option, false), 'p', `${JSON.stringify(option)} x false`)
|
||||
}
|
||||
})
|
||||
|
||||
test('an answer without the key renders the title as the H1', () => {
|
||||
const post = { title: 'Chaga', slug: 'chaga' } as Partial<JournalPost>
|
||||
assert.equal(journalPostTitleTag('auto', (post as { content_h1_to_h2?: boolean }).content_h1_to_h2), 'h1')
|
||||
const off = { ...post, content_h1_to_h2: false } as Partial<JournalPost>
|
||||
assert.equal(journalPostTitleTag('auto', (off as { content_h1_to_h2?: boolean }).content_h1_to_h2), 'p')
|
||||
})
|
||||
Reference in New Issue
Block a user