- buildRevalidateHook skips outside Next (no NEXT_RUNTIME) and with context.disableRevalidate - BuilderForm focuses only on a real step change (no scroll to the form on remount) - mediaImageProps: placeholder colour only for JPEG (placeholderColor); hook stores no colour for transparent images - buildLinkField: interface name per shape (CmsLink, CmsLinkPlain, CmsLinkNoLabel) + interfaceName option - Cookie Settings: buttons.save -> buttons.savePreferences (Mongoose reserved name) - ThemeScript, ThemeSwitcher, useTheme; Site Settings defaultTheme 'system' + themeToggleLabel; Turnstile follows page theme - extractHeadings, RenderRichText headingIds, TableOfContents, buildTableOfContentsField - createPageRoute onMissing: 'redirectHome' - Form builder: localized placeholder on text/email/textarea/number, new time field - ipal-audit: no false positive for object keys between JSX elements; /md route not reported as dynamic Co-Authored-By: Claude Opus 5.5 <[email protected]>
73 lines
3.3 KiB
TypeScript
73 lines
3.3 KiB
TypeScript
import { createElement as h } from 'react'
|
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { describe, expect, test } from 'vitest'
|
|
|
|
import { buildTableOfContentsField, extractHeadings } from '../src/modules/richtext/headings.js'
|
|
import { RenderRichText } from '../src/modules/richtext/RenderRichText.js'
|
|
import { TableOfContents } from '../src/modules/richtext/TableOfContents.js'
|
|
|
|
const text = (t: string, format = 0) => ({ type: 'text', detail: 0, format, mode: 'normal', style: '', text: t, version: 1 })
|
|
const heading = (tag: string, ...children: object[]) => ({ type: 'heading', children, direction: 'ltr', format: '', indent: 0, tag, version: 1 })
|
|
const paragraph = (t: string) => ({ type: 'paragraph', children: [text(t)], direction: 'ltr', format: '', indent: 0, textFormat: 0, version: 1 })
|
|
|
|
const doc = {
|
|
root: {
|
|
type: 'root',
|
|
children: [
|
|
heading('h2', text('Administrator '), text('danych', 1)),
|
|
paragraph('Treść'),
|
|
heading('h3', text('Szczegóły')),
|
|
heading('h2', text('Pliki cookies')),
|
|
heading('h2', text('Pliki cookies')),
|
|
heading('h2'),
|
|
],
|
|
direction: 'ltr',
|
|
format: '',
|
|
indent: 0,
|
|
version: 1,
|
|
},
|
|
} as never
|
|
|
|
describe('table of contents', () => {
|
|
test('extractHeadings: h2 in order, slug ids, repeats numbered, empty skipped', () => {
|
|
expect(extractHeadings(doc)).toEqual([
|
|
{ id: 'administrator-danych', level: 'h2', text: 'Administrator danych' },
|
|
{ id: 'pliki-cookies', level: 'h2', text: 'Pliki cookies' },
|
|
{ id: 'pliki-cookies-2', level: 'h2', text: 'Pliki cookies' },
|
|
])
|
|
expect(extractHeadings(doc, { levels: ['h2', 'h3'] }).map((h) => h.id)).toContain('szczegoly')
|
|
expect(extractHeadings(null)).toEqual([])
|
|
})
|
|
|
|
test('RenderRichText headingIds: the same ids on the headings, project converter kept', () => {
|
|
const html = renderToStaticMarkup(
|
|
h(RenderRichText, {
|
|
converters: ({ defaultConverters }) => ({
|
|
...defaultConverters,
|
|
heading: ({ node, nodesToJSX }) => h(node.tag, { className: 'title' }, ...nodesToJSX({ nodes: node.children })),
|
|
}),
|
|
data: doc,
|
|
headingIds: { className: 'scroll-mt-24' },
|
|
}),
|
|
)
|
|
expect(html).toContain('<h2 class="title scroll-mt-24" id="administrator-danych">')
|
|
expect(html).toContain('id="pliki-cookies-2"')
|
|
expect(html).toMatch(/<h3 class="title">Szczegóły<\/h3>/)
|
|
expect(renderToStaticMarkup(h(RenderRichText, { data: doc, headingIds: true }))).toContain('<h2 id="pliki-cookies">')
|
|
})
|
|
|
|
test('TableOfContents: links to the ids, first section current before JS', () => {
|
|
const html = renderToStaticMarkup(h(TableOfContents, { classNames: { linkActive: 'on' }, items: extractHeadings(doc), label: 'Spis treści' }))
|
|
expect(html).toContain('aria-label="Spis treści"')
|
|
expect(html).toContain('<a aria-current="location" class="on" href="#administrator-danych">')
|
|
expect(html).toContain('href="#pliki-cookies-2"')
|
|
expect(renderToStaticMarkup(h(TableOfContents, { items: [] }))).toBe('')
|
|
})
|
|
|
|
test('panel field: show + localized label', () => {
|
|
const field = buildTableOfContentsField()
|
|
expect(field).toMatchObject({ name: 'tableOfContents', interfaceName: 'TableOfContentsSettings' })
|
|
expect(field.fields.map((f) => ('name' in f ? f.name : ''))).toEqual(['show', 'label'])
|
|
})
|
|
})
|