Files
kits/packages/sitekit/test/document.test.js
CatoandClaude Opus 5.5 e81bea6dba feat(sitekit): theme as data (AA-checked), settings, SiteDocument, and a form section (#2)
* feat(sitekit): a theme as data, AA-checked, and the SiteDocument page frame

siteThemeSchema / siteThemeCss turn a site's look into a value a server can
render without a stylesheet per site: one colour per semantic class (plus an
optional dark palette), faces from a closed self-hosted list, tracking,
radius and width, emitted as both the section tokens and the chrome's
--sk-* tokens. Text tokens below WCAG AA on either surface, and a button
label below AA on the accent, are refused with the measured ratio.

SiteDocument is the page frame consumers wrote by hand (camille's catch-all
route, class for class), so an engine-served page and an exported repository
render the same component.

Step 2 of loki ADR-0001 (the sites platform).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sitekit): siteSettingsSchema — lang and a one-line banner, read the same by engine and export

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sitekit): a form section — the first block with a server half

Closed fields (name, email, phone, message), a required privacy note and
anchor; refuses a field asked twice and a form nobody could answer. Renders a
plain HTML POST to the host's endpoint (SiteSections / SiteDocument `forms`
prop) with a honeypot and a live-region notice after the redirect back;
without a host it renders words, never a dead form. Settings gain `formTo`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sitekit): a gallery section — sized, lazy, never stretched or cropped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sitekit): booking requests (date, time, people) and a map section on OpenStreetMap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(sitekit): card actions — a shop links each product to where it is sold

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sitekit): the map's show control reads as a control (+ like the FAQ)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 14:18:09 +01:00

79 lines
2.7 KiB
JavaScript

/**
* SiteDocument is the frame every engine-served page and every exported
* repository render. It must reproduce the frame consumers wrote by hand
* (camille-boulangerie's catch-all route) and keep the masthead/footer seams.
*/
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createElement as h } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { sitePageAt } from '@bitbaum/sitekit';
import { SiteDocument } from '@bitbaum/sitekit/react';
const SPEC = {
chrome: { name: 'Muster', tagline: 'Brot', footerNote: 'Ein Beispiel.' },
pages: [
{
path: '',
navLabel: 'Start',
title: 'Willkommen',
sections: [{ kind: 'hero', statement: 'Frisches Brot', lead: ['Ab sechs.'] }],
},
{
path: 'angebot',
navLabel: 'Angebot',
title: 'Angebot',
intro: 'Was es gibt.',
sections: [{ kind: 'prose', paragraphs: ['Brot und Gipfeli.'] }],
},
],
};
const render = (path, extra = {}) =>
renderToStaticMarkup(
h(SiteDocument, {
spec: SPEC,
page: sitePageAt(SPEC.pages, path),
currentPath: path,
...extra,
}),
);
test('a page without a hero gets the page header with its title and intro', () => {
const html = render('angebot');
assert.match(html, /<header class="mb-14 border-b border-subtle pb-10"><h1[^>]*>Angebot<\/h1>/);
assert.match(html, /Was es gibt\./);
assert.match(html, /Brot und Gipfeli\./);
});
test('a page that opens with a hero renders no second header', () => {
const html = render('');
assert.ok(!html.includes('mb-14 border-b'), 'hero page must not get the page header');
assert.match(html, /Frisches Brot/);
});
test('the frame is the hand-written one: shell, main, masthead, footer', () => {
const html = render('angebot');
assert.match(html, /^<div class="flex min-h-screen flex-col bg-surface-page">/);
assert.match(
html,
/<main class="flex-1"><div class="mx-auto max-w-shell px-4 py-14 sm:px-6 sm:py-20 lg:px-8">/,
);
assert.match(html, /Muster/);
assert.match(html, /Ein Beispiel\./);
assert.match(html, /aria-current="page"[^>]*>Angebot|>Angebot<[^]*aria-current/);
});
test('banner renders first, mainId wires main and the skip link', () => {
const html = render('angebot', { banner: h('p', { id: 'demo' }, 'Demo'), mainId: 'inhalt' });
assert.ok(html.startsWith('<p id="demo">Demo</p>'));
assert.match(html, /<main id="inhalt" class="flex-1">/);
});
test('the Link seam is used for nav links', () => {
const Link = ({ href, children, ...rest }) =>
h('a', { ...rest, href, 'data-seam': '1' }, children);
assert.match(render('angebot', { Link }), /data-seam="1"/);
});