|
| 1 | +/** |
| 2 | + * The content outlet is, by definition, the hole the current entry's body |
| 3 | + * flows into. That must hold for ANY `base.outlet` on an entry-route template — |
| 4 | + * including one a user drags onto a custom template by hand, which carries no |
| 5 | + * persisted `dynamicBindings` overlay. The publisher applies the entry-body |
| 6 | + * binding implicitly (see `effectiveNodeBindings`), so the body renders without |
| 7 | + * the node needing to remember a binding it never had a UI to set. |
| 8 | + */ |
| 9 | + |
| 10 | +import { describe, expect, it } from 'bun:test' |
| 11 | +import { makeModule, makePage, makeRegistry, makeSite } from './helpers' |
| 12 | +import { publishPage } from '@core/publisher' |
| 13 | +import type { LoopItem } from '@core/loops/types' |
| 14 | + |
| 15 | +const bodyModule = makeModule('base.body', { |
| 16 | + canHaveChildren: true, |
| 17 | + render: (_props, children) => ({ html: `<main>${children.join('')}</main>` }), |
| 18 | +}) |
| 19 | + |
| 20 | +// Mirrors the real base.outlet render: a hidden richtext `html` prop (so |
| 21 | +// `escapeProps` sanitises rather than HTML-escapes it) emitted inside the |
| 22 | +// content-region marker. |
| 23 | +const outletModule = makeModule('base.outlet', { |
| 24 | + schema: { html: { type: 'richtext', label: 'Content', hidden: true } }, |
| 25 | + render: (props) => ({ |
| 26 | + html: `<section data-instatic-content-region>${String((props as { html?: string }).html ?? '')}</section>`, |
| 27 | + }), |
| 28 | +}) |
| 29 | + |
| 30 | +const registry = makeRegistry({ 'base.body': bodyModule, 'base.outlet': outletModule }) |
| 31 | + |
| 32 | +function entry(body: string): LoopItem { |
| 33 | + return { id: 'p1', fields: { id: 'p1', title: 'Untitled', body } } |
| 34 | +} |
| 35 | + |
| 36 | +describe('entry outlet body binding', () => { |
| 37 | + it('renders the current entry body into an outlet that carries no persisted binding', () => { |
| 38 | + // A hand-dropped outlet: NO dynamicBindings on the node. |
| 39 | + const page = makePage({ |
| 40 | + root: { moduleId: 'base.body', children: ['outlet'] }, |
| 41 | + outlet: { moduleId: 'base.outlet' }, |
| 42 | + }) |
| 43 | + |
| 44 | + const { html } = publishPage(page, makeSite(), registry, { |
| 45 | + templateContext: { entryStack: [entry('## Heading\n\nHello world')] }, |
| 46 | + }) |
| 47 | + |
| 48 | + expect(html).toContain('data-instatic-content-region') |
| 49 | + expect(html).toContain('<h2>Heading</h2>') |
| 50 | + expect(html).toContain('Hello world') |
| 51 | + }) |
| 52 | + |
| 53 | + it('leaves the outlet empty on a non-entry render (no current entry in scope)', () => { |
| 54 | + const page = makePage({ |
| 55 | + root: { moduleId: 'base.body', children: ['outlet'] }, |
| 56 | + outlet: { moduleId: 'base.outlet' }, |
| 57 | + }) |
| 58 | + |
| 59 | + // No entryStack → currentEntry.body resolves to nothing; the outlet renders |
| 60 | + // its marker but no body (an `everywhere` layout previewing a page relies on |
| 61 | + // this so the implicit binding stays inert outside entry routes). |
| 62 | + const { html } = publishPage(page, makeSite(), registry, { |
| 63 | + templateContext: { entryStack: [] }, |
| 64 | + }) |
| 65 | + |
| 66 | + expect(html).toContain('data-instatic-content-region') |
| 67 | + expect(html).not.toContain('Hello world') |
| 68 | + }) |
| 69 | +}) |
0 commit comments