Page-filled form fields, links to entries, entry JSON-LD, R2-optional dev
Forms: `values` on RenderForm / BuilderForm / useBuilderForm fills fields the
page knows (chosen product variant, category) — read-only <output>, in the
SSR HTML, sent and validated like any field. prepareBuilderForm (/rsc) is the
server half of RenderForm for client components whose values change in the
browser; publicForm is exported so projects stop copying it.
Links: buildLinkField({ relationTo: ['pages', 'categories', …] }) — a
polymorphic relation; resolveLinkHref builds /{locale}/{archive}/{entry} from
`archives`, which getLinkOptions in createContentHelpers fills from Site
Settings.
SEO: pageJsonLd.entries — the main JSON-LD node per content collection
instead of BlogPosting; buildProductJsonLd emits an Offer only for a real
price from the panel.
Pages: createPageRoute / createNotFoundPage pass isFirst to blocks, so the
first section carries the page's only h1.
Fixes: ipalEnvRules({ storage: true }) requires R2_* in production only
(development: optional, all or none); buildImagesConfig allows the app's own
media on localhost outside production.
Docs, CHANGELOG, PROGRAMISTA §6 (34–37), ipal-form and ipal-upgrade skills.
Tests: builderForm, links, drafts (entries + archives), seo, media, env.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
46d30d4ecd
commit
f809526f1d
@@ -6,7 +6,7 @@ import type { BuilderField, BuilderFormDoc } from '../src/modules/forms/builderT
|
||||
|
||||
import { BuilderForm } from '../src/modules/forms/BuilderForm.js'
|
||||
import { autoCompleteFor, initialBuilderValues, splitSteps, stepOfField, validateBuilderFields } from '../src/modules/forms/builderLogic.js'
|
||||
import { RenderForm } from '../src/modules/forms/RenderForm.js'
|
||||
import { prepareBuilderForm, publicForm, RenderForm } from '../src/modules/forms/RenderForm.js'
|
||||
|
||||
vi.mock('server-only', () => ({}))
|
||||
|
||||
@@ -131,3 +131,51 @@ describe('RenderForm', () => {
|
||||
expect(RenderForm({ action: async () => ({ message: '', success: true }), form: 5, locale: 'pl', texts })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('page values (values prop) and prepareBuilderForm', () => {
|
||||
const withSubject: BuilderFormDoc = {
|
||||
id: 9,
|
||||
fields: [
|
||||
{ name: 'subject', blockType: 'text', label: 'Dotyczy' },
|
||||
{ name: 'email', blockType: 'email', label: 'E-mail', required: true },
|
||||
],
|
||||
submitButtonLabel: 'Wyślij',
|
||||
}
|
||||
|
||||
test('a field filled by the page is read-only output in the first HTML, others stay inputs', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
createElement(BuilderForm, {
|
||||
action: async () => ({ message: 'ok', success: true }),
|
||||
classNames: { fixed: 'fx' },
|
||||
form: withSubject,
|
||||
texts,
|
||||
values: { subject: 'Pierścionek · białe złoto', unknown: 'x' },
|
||||
}),
|
||||
)
|
||||
expect(html).toContain('<output')
|
||||
expect(html).toContain('class="fx"')
|
||||
expect(html).toContain('Pierścionek · białe złoto')
|
||||
expect(html).not.toMatch(/<input[^>]*name="subject"/)
|
||||
expect(html).toMatch(/<input[^>]*name="email"/)
|
||||
expect(html).not.toContain('unknown')
|
||||
})
|
||||
|
||||
test('RenderForm passes values through', () => {
|
||||
const action = async () => ({ message: 'ok', success: true })
|
||||
const html = renderToStaticMarkup(
|
||||
createElement(RenderForm, { action, form: withSubject, locale: 'pl', texts, values: { subject: 'Broszki' } }),
|
||||
)
|
||||
expect(html).toContain('Broszki')
|
||||
})
|
||||
|
||||
test('prepareBuilderForm: public part only, bound action, null for an id', () => {
|
||||
const doc = { ...withSubject, emails: [{ emailTo: '[email protected]' }] } as BuilderFormDoc
|
||||
const action = vi.fn(async () => ({ message: 'ok', success: true }))
|
||||
const prepared = prepareBuilderForm({ action, form: doc, locale: 'pl' })
|
||||
expect(JSON.stringify(prepared?.form)).not.toContain('[email protected]')
|
||||
expect(prepared?.form).toEqual(publicForm(doc))
|
||||
void prepared?.action({ email: '[email protected]' })
|
||||
expect(action).toHaveBeenCalledWith('9', 'pl', { email: '[email protected]' })
|
||||
expect(prepareBuilderForm({ action, form: '9', locale: 'pl' })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user