refac: missing mutation tests, spa specs, checks shown to pass, touch targets, catalogue entry, production code

This commit is contained in:
Florian Sylvain committed 2026-11-04 03:04:35 +01:00
1 parent 7c15206170
commit 3e02e14da4
48 files changed
+2173 -83

No files matched your search

+4 -4
View File
@@ -65,9 +65,9 @@ describe('index', () => {
])
})
it('holds 91 endpoints: 45 documented, 40 session only and 6 public auth', () => {
expect(index.endpoints).toHaveLength(91)
expect(index.endpoints.filter((entry) => entry.cardId !== null)).toHaveLength(45)
it('holds 92 endpoints: 46 documented, 40 session only and 6 public auth', () => {
expect(index.endpoints).toHaveLength(92)
expect(index.endpoints.filter((entry) => entry.cardId !== null)).toHaveLength(46)
expect(index.endpoints.filter((entry) => entry.session)).toHaveLength(40)
expect(index.endpoints.filter((entry) => entry.key.startsWith('public:'))).toHaveLength(6)
})
@@ -202,7 +202,7 @@ describe('matching', () => {
describe('custom content types', () => {
it.each([
['media', 16, 1],
['404', 26, 1],
['404', 27, 1],
['login', 1, 1],
['entry', 7, 1],
['capacity', 2, 0],
+197
View File
@@ -0,0 +1,197 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { initializeLocale, setLocale } from '@/i18n'
import type { ResolvedSeo } from '@/lib/seoTypes'
import {
altHelp,
breadcrumbOf,
canonicalNote,
descriptionBadge,
descriptionHelp,
disabledNote,
pageLanguage,
socialLocaleLine,
socialLocaleNote,
titleHelp,
type LocalizedSeoContext,
} from '../localizedSeo'
const PATTERN = 'https://journal.example.com/{lang}/{slug}'
function resolved(
fallbacks: Partial<ResolvedSeo['fallbacks']> = {},
locale = 'fr_FR',
): ResolvedSeo {
return {
title: 'Couts de renovation | Journal',
description: '',
canonical_url: 'https://journal.example.com/fr/couts',
robots: 'index, follow',
og: {
type: 'article',
title: '',
description: '',
image: '',
image_alt: '',
url: '',
site_name: 'Journal',
locale,
},
twitter: { card: 'summary', title: '', description: '', image: '', image_alt: '' },
image: { url: '', alt: '', source: 'none' },
authors: [],
published_at: null,
modified_at: '2026-09-26T11:02:00Z',
fallbacks: {
title: 'title',
description: 'none',
image: 'none',
canonical: 'pattern',
...fallbacks,
},
json_ld: {},
}
}
function context(overrides: Partial<LocalizedSeoContext> = {}): LocalizedSeoContext {
return {
lang: 'fr',
siteName: 'Journal',
siteKey: 'journal',
pattern: PATTERN,
defaultLang: 'en',
disabledLangs: [],
published: true,
socialState: 'derived',
resolved: resolved(),
...overrides,
}
}
beforeEach(() => {
localStorage.clear()
initializeLocale()
})
afterEach(() => {
localStorage.clear()
initializeLocale()
})
describe('Page language and breadcrumb', () => {
it('names the version language in the interface language', () => {
expect(pageLanguage(context())).toBe('French')
setLocale('fr')
expect(pageLanguage(context())).toBe('Français')
})
it('turns a URL into host › segments and keeps anything else as is', () => {
expect(breadcrumbOf('https://journal.example.com/fr/couts')).toBe(
'journal.example.com › fr › couts',
)
expect(breadcrumbOf('not a url')).toBe('not a url')
})
})
describe('Canonical note', () => {
it('says the canonical is built from the Public URL pattern', () => {
expect(canonicalNote(context())).toBe(
`Built from the Public URL pattern ${PATTERN}. Each language points to itself unless you set a canonical override.`,
)
})
it('says a canonical override was set by hand', () => {
expect(canonicalNote(context({ resolved: resolved({ canonical: 'canonical_url' }) }))).toBe(
'Set by hand as a canonical override on this version.',
)
})
})
describe('Disabled languages note', () => {
it('leaves out drafts only when no language is disabled', () => {
expect(disabledNote(context())).toBe('Drafts are left out.')
})
it('names one disabled language', () => {
expect(disabledNote(context({ disabledLangs: ['es'] }))).toBe(
'Drafts and the disabled Spanish language are left out.',
)
})
it('lists several disabled languages', () => {
expect(disabledNote(context({ disabledLangs: ['es', 'de'] }))).toBe(
'Drafts and the disabled languages Spanish, German are left out.',
)
})
})
describe('Social locale', () => {
it('reads Derived for a locale taken from the language code', () => {
const derived = context()
expect(socialLocaleLine(derived)).toBe('Derived: fr_FR')
expect(socialLocaleNote(derived)).toBe(
'Taken from the region of the language code or of the site locale. An owner can set another in Journal languages.',
)
})
it('reads Set for a locale an owner chose', () => {
const set = context({ socialState: 'set' })
expect(socialLocaleLine(set)).toBe('Set: fr_FR')
expect(socialLocaleNote(set)).toBe(
'Set by an owner for French in Journal languages. A region is never guessed from the language.',
)
})
it('reads Social locale not set when nothing resolves', () => {
const unset = context({ resolved: resolved({}, '') })
expect(socialLocaleLine(unset)).toBe('Social locale not set')
expect(socialLocaleNote(unset)).toBe(
'French has no region in its code and no social locale is set for it, so og:locale and og:locale:alternate are left out. An owner can set one in Journal languages.',
)
expect(socialLocaleLine(context({ resolved: null }))).toBe('Social locale not set')
})
})
describe('Field help follows the fallbacks of the API', () => {
it('names the title fallback only when the title is used', () => {
expect(titleHelp(context())).toBe('Fallback: French title')
expect(titleHelp(context({ resolved: resolved({ title: 'seo_title' }) }))).toBe('')
expect(titleHelp(context({ resolved: null }))).toBe('')
})
it('names each description fallback', () => {
const help = (description: string, siteTextSkipped = false) =>
descriptionHelp(
context({
resolved: resolved({ description, site_text_skipped: siteTextSkipped }),
}),
)
expect(help('excerpt')).toBe('Fallback: French excerpt')
expect(help('body')).toBe('Fallback: French body')
expect(help('site')).toBe('Fallback: French site description')
expect(help('none')).toBe('No fallback')
expect(help('none', true)).toBe(
'No fallback. Empty. English site default not used. The tag is left out.',
)
expect(help('seo_description')).toBe('')
expect(descriptionHelp(context({ resolved: null }))).toBe('')
})
it('badges the site text and the withheld tag', () => {
expect(descriptionBadge(context({ resolved: resolved({ description: 'site' }) }))).toBe(
'Uses site text',
)
expect(
descriptionBadge(
context({ resolved: resolved({ description: 'none', site_text_skipped: true }) }),
),
).toBe('Tag left out')
expect(descriptionBadge(context({ resolved: resolved({ description: 'excerpt' }) }))).toBe(
'',
)
expect(descriptionBadge(context({ resolved: null }))).toBe('')
})
it('says the image alt is written per language', () => {
expect(altHelp()).toBe('Written per language.')
})
})