Import instead of code: panel forms (steps, choice lists, dates), layout, page route, GEO routes, links, section fields

- Forms: step and checkboxGroup field types (radio, date on), server validation for them,
  useBuilderForm (logic) + BuilderForm (unstyled default) + RenderForm (/rsc: rich text,
  bound action, public part of the form only — the Emails tab never reaches the browser)
- Notifications: next / back / stepOf texts
- createContentHelpers: getSiteShell, getFormTexts, getLinkOptions, resolveLink, resolveNav,
  resolvePageRedirect, one-line route handlers (llms, llms-full, md, mcp, health, indexnow, manifest)
- /rsc: SiteProviders, createPageRoute, createNotFoundPage
- resolveLink / resolveNav / homeSlugFrom, buildSectionHeaderField / buildSectionSettingsField
- Dev sandbox frontend built on these imports; tests (unit + real Payload)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-16 11:32:46 +02:00
co-authored by Claude Opus 5.5
parent 0cfd846dd1
commit 412bf953a8
44 changed files with 2015 additions and 20 deletions
+81
View File
@@ -16,6 +16,7 @@ import { buildConsentLogEndpoint } from '../src/modules/consent/consentLog.js'
import { getCookieTable } from '../src/modules/consent/getConsentTexts.js'
import { submitForm } from '../src/modules/forms/submitForm.js'
import { createContentHelpers } from '../src/modules/frontend/createContentHelpers.js'
import { createPageRoute } from '../src/modules/frontend/pageRoute.js'
import { ipalKit } from '../src/plugin.js'
vi.mock('server-only', () => ({}))
@@ -117,6 +118,41 @@ describe('forms against a real Payload', () => {
expect(await send({ name: 'Ala', consent: true, role: 'admin' })).toMatchObject({ kind: 'unknown_fields' })
})
test('step-by-step form with a checkbox group, radio and date: built in the panel, stored readable', async () => {
const multi = await payload.create({
collection: 'forms' as never,
data: {
confirmationType: 'redirect',
fields: [
{ name: 'name', blockType: 'text', label: 'Imię', required: true },
{ blockType: 'step', title: 'Szczegóły' },
{ name: 'services', blockType: 'checkboxGroup', label: 'Usługi', options: [{ label: 'Strona', value: 'www' }, { label: 'SEO', value: 'seo' }], required: true },
{ name: 'size', blockType: 'radio', label: 'Wielkość', options: [{ label: 'Mała', value: 's' }, { label: 'Duża', value: 'l' }] },
{ name: 'deadline', blockType: 'date', label: 'Termin' },
],
redirect: { url: '/dziekujemy' },
title: 'Wycena',
} as never,
})
const result = await submitForm({
data: { name: 'Ala', deadline: '2026-12-01', services: ['www', 'seo'], size: 'l' },
formId: String(multi.id),
ip: '10.7.0.9',
payload,
})
expect(result).toMatchObject({ success: true })
if (!result.success) {return}
const stored = (await payload.findByID({ id: result.submissionId, collection: 'form-submissions' as never, depth: 0 })) as unknown as {
submissionData: { field: string; value: string }[]
}
expect(stored.submissionData.map(({ field, value }) => [field, value])).toEqual([
['name', 'Ala'],
['services', 'www, seo'],
['size', 'l'],
['deadline', '2026-12-01'],
])
})
test('REST/anonymous creation of submissions is closed (only submitForm writes)', async () => {
await expect(
payload.create({
@@ -178,6 +214,51 @@ describe('getPageJsonLd', () => {
})
})
describe('one-call helpers — layout, page, GEO routes', () => {
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] } as const
const h = () => createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n, mcp: { serverName: 'acme-site' } })
test('getSiteShell: consent, analytics, Turnstile, form texts and site JSON-LD in one call', async () => {
await payload.updateGlobal({ slug: 'site-settings' as never, data: { siteName: 'Acme' } as never })
const shell = await h().getSiteShell('pl')
expect(shell.turnstileSiteKey).toBeNull()
expect(shell.consent.buttons.acceptAll).toEqual(expect.any(String))
expect(shell.formTexts).toMatchObject({ next: 'Next', stepOf: 'Step {current} of {total}' })
expect(shell.jsonLd.map((n) => n['@type'])).toEqual(['WebSite', 'Organization'])
expect(shell.jsonLd.every((n) => !('@context' in n))).toBe(true)
const custom = createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n, siteJsonLd: false })
expect((await custom.getSiteShell('pl')).jsonLd).toEqual([])
})
test('createPageRoute: renders a page with its JSON-LD, 404s an unknown slug', async () => {
await payload.create({ collection: 'pages' as never, data: { slug: 'uslugi', title: 'Usługi' } as never })
const notFound = vi.fn(() => {
throw new Error('NEXT_NOT_FOUND')
}) as unknown as () => never
const permanentRedirect = vi.fn() as unknown as (url: string) => never
const route = createPageRoute(h(), { blocks: {}, notFound, permanentRedirect })
const el = (await route.Page({ params: Promise.resolve({ slug: ['uslugi'] }) })) as { props: { children: unknown[] } }
expect(JSON.stringify(el.props.children[0])).toContain('Usługi')
await expect(route.Page({ params: Promise.resolve({ slug: ['nie-ma'] }) })).rejects.toThrow('NEXT_NOT_FOUND')
expect((await route.generateMetadata({ params: Promise.resolve({ slug: ['uslugi'] }) })).alternates?.canonical).toBe('https://acme.pl/uslugi')
})
test('route handlers answer without per-file configuration', async () => {
const helpers = h()
const llms = await helpers.llmsRoute()
expect(llms.status).toBe(200)
expect(await llms.text()).toContain('https://acme.pl/uslugi')
expect((await helpers.healthRoute()).status).toBe(200)
expect((await helpers.indexNowKeyRoute()).status).toBe(404) // no key configured
const mcp = await helpers.mcpPOST(
new Request('https://acme.pl/api/mcp', { body: JSON.stringify({ id: 1, jsonrpc: '2.0', method: 'initialize' }), headers: { 'content-type': 'application/json' }, method: 'POST' }),
)
expect(JSON.stringify(await mcp.json())).toContain('acme-site')
const md = await helpers.markdownRoute(new Request('https://acme.pl/md/uslugi'), { params: Promise.resolve({ slug: ['uslugi'], locale: 'pl' }) })
expect(md.status).toBe(200)
})
})
describe('consent log', () => {
const post = (body: unknown, ip = '10.6.0.1') =>
buildConsentLogEndpoint().handler({