- AGENT.md: §7 full capability catalog (need → import), §0b/§3/§6 on RenderForm, SiteProviders, createPageRoute, re-exported routes, plugin section fields, resolveLink/resolveNav - PROGRAMISTA §2.4, §2.7–2.8 rewritten; §6 items 28–33 (28: FormRenderer leaked the Emails tab) - forms, links, blocks, pages, consent, turnstile, notifications, seo, mcp, i18n, deployment docs - ipal-form: RenderForm block, formClasses, CustomForm example (FormRenderer template removed), seed template handles steps and option labels per language - ipal-nav, ipal-block, ipal-setup, ipal-upgrade, ipal-seo-check, ipal-consent-check, vibe.md - ipal-audit: re-export routes and SiteProviders satisfy the mandatory set; flags form-engine copies, project section fields / navigation, server entries in client components - test/docsConsistency: docs imports exist in code; every public export is documented - CHANGELOG 1.9.2 Co-Authored-By: Claude Opus 5.5 <[email protected]>
79 lines
3.8 KiB
TypeScript
79 lines
3.8 KiB
TypeScript
import { describe, expect, test } from 'vitest'
|
|
|
|
import { buildSectionHeaderField, buildSectionSettingsField } from '../src/modules/blocks/sectionFields.js'
|
|
import { homeSlugFrom, resolveLink, resolveNav } from '../src/modules/links/resolveNav.js'
|
|
|
|
const config = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'PL' }, { code: 'en', label: 'EN' }] } as const
|
|
const opts = { config, homeSlug: 'start', locale: 'pl' }
|
|
const page = (slug: string) => ({ type: 'internal' as const, label: slug, page: { slug } })
|
|
|
|
describe('resolveLink', () => {
|
|
test('internal page → next/link, no target', () => {
|
|
expect(resolveLink(page('kontakt'), opts)).toEqual({ href: '/pl/kontakt', internal: true, label: 'kontakt', newTab: false, targetProps: {} })
|
|
})
|
|
|
|
test('files always open in a new tab with rel; appearance is passed through', () => {
|
|
expect(resolveLink({ type: 'file', appearance: 'primary', file: { url: '/media/cennik.pdf' }, label: 'Cennik' }, opts)).toMatchObject({
|
|
appearance: 'primary',
|
|
href: '/media/cennik.pdf',
|
|
internal: false,
|
|
targetProps: { rel: 'noopener noreferrer', target: '_blank' },
|
|
})
|
|
})
|
|
|
|
test('nowhere → null: unsafe URL, missing page, empty link', () => {
|
|
expect(resolveLink({ type: 'external', url: 'javascript:alert(1)' }, opts)).toBeNull()
|
|
expect(resolveLink({ type: 'internal', page: 5 }, opts)).toBeNull()
|
|
expect(resolveLink(null, opts)).toBeNull()
|
|
})
|
|
|
|
test('the homepage collapses to the locale root', () => {
|
|
expect(resolveLink(page('start'), opts)?.href).toBe('/pl')
|
|
})
|
|
})
|
|
|
|
describe('resolveNav', () => {
|
|
test('nested items resolved; dead or unlabeled items dropped', () => {
|
|
const items = [
|
|
{ link: page('oferta'), subItems: [{ link: page('www') }, { link: { type: 'internal', label: 'x', page: null } }] },
|
|
{ link: { type: 'external', url: 'https://x.pl' } }, // no label
|
|
{ link: page('kontakt') },
|
|
]
|
|
const nav = resolveNav(items, opts)
|
|
expect(nav.map((i) => [i.href, i.children.map((c) => c.href)])).toEqual([
|
|
['/pl/oferta', ['/pl/www']],
|
|
['/pl/kontakt', []],
|
|
])
|
|
})
|
|
|
|
test('custom item shape and junk input', () => {
|
|
expect(resolveNav([{ children: [{ to: page('a') }], to: page('b') }], { ...opts, childrenField: 'children', linkField: 'to' })[0].children[0].href).toBe('/pl/a')
|
|
expect(resolveNav(null, opts)).toEqual([])
|
|
expect(resolveNav('x', opts)).toEqual([])
|
|
})
|
|
|
|
test('homeSlugFrom reads a populated homepage only', () => {
|
|
expect(homeSlugFrom({ homepage: { slug: 'start' } })).toBe('start')
|
|
expect(homeSlugFrom({ homepage: 3 })).toBeUndefined()
|
|
expect(homeSlugFrom(null)).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('section fields', () => {
|
|
test('defaults match the documented shape (types SectionHeaderData / SectionSettings)', () => {
|
|
const header = buildSectionHeaderField()
|
|
expect(header).toMatchObject({ name: 'header', interfaceName: 'SectionHeaderData' })
|
|
expect(header.fields.map((f) => ('name' in f ? f.name : ''))).toEqual(['eyebrow', 'heading', 'intro'])
|
|
const settings = buildSectionSettingsField()
|
|
expect(settings).toMatchObject({ name: 'settings', admin: { position: 'sidebar' }, interfaceName: 'SectionSettings' })
|
|
expect(settings.fields.map((f) => ('name' in f ? f.name : ''))).toEqual(['anchor', 'background'])
|
|
})
|
|
|
|
test('the project decides: own backgrounds, no anchor, extra fields', () => {
|
|
const s = buildSectionSettingsField({ anchor: false, backgrounds: [{ label: 'Brand', value: 'brand' }], fields: [{ name: 'spacing', type: 'text' }] })
|
|
expect(s.fields.map((f) => ('name' in f ? f.name : ''))).toEqual(['background', 'spacing'])
|
|
expect(s.fields[0]).toMatchObject({ defaultValue: 'brand' })
|
|
expect(buildSectionSettingsField({ backgrounds: false }).fields.map((f) => ('name' in f ? f.name : ''))).toEqual(['anchor'])
|
|
})
|
|
})
|