Files
sitekit/test/react.test.js
T
Mao NakamotoandClaude Opus 5 1b3a6b4a93 feat: sitekit v0.1.0 — a website as data
Extracted from substrata's hosted-site model, per orangecat ADR-0003 (the
Site Factory). Three things ship:

- The closed section union (hero, prose, stats, meter, cards, definitions,
  index, table) with Zod as the SSOT — every TS type is inferred, and
  validateSite() returns path-addressed errors a generator can act on.
  Structural rules are in the schema: hero only first, no duplicate paths,
  no index entry pointing at a missing anchor.
- One set of React renderers emitting semantic utility classes only; no
  colours, faces or radii ship. The single framework seam is an injectable
  Link component defaulting to a plain anchor, so static sites and Next
  apps consume the same package.
- Provenance: a sidecar keyed by JSON path (scraped/operator/inferred/
  not-found). assertDeliverable() throws on any inferred field, which turns
  'we fabricate no facts' from a promise into a check, and not-found makes
  unknown distinct from empty.

Tests import the package by name so a broken exports map fails in CI.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZCNYHwjEeqxNpYCUk6Yna
2026-08-28 09:13:38 +02:00

71 lines
3.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Renderer smoke tests: every section kind renders to markup containing its
* content, and the Link seam actually injects — the two things a consumer
* discovers first if they break.
*/
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createElement as h } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { SiteSections, SiteMasthead, SiteFooter } from 'sitekit/react';
const SECTIONS = [
{ kind: 'hero', eyebrow: 'Zürich', statement: 'Coffee, done properly.', lead: ['Since 2011.'] },
{ kind: 'prose', heading: 'About', paragraphs: ['A neighbourhood café.'] },
{ kind: 'stats', heading: 'In numbers', stats: [{ label: 'Seats', value: '24', note: 'inside' }] },
{ kind: 'meter', label: 'Sourced', value: 3, of: 12, caption: 'so far' },
{ kind: 'cards', heading: 'Offers', columns: 3, cards: [{ title: 'Espresso', body: 'The house shot.', meta: 'CHF 4.50' }] },
{ kind: 'definitions', heading: 'Terms', items: [{ term: 'Cortado', detail: 'Espresso cut with milk.' }] },
{ kind: 'index', heading: 'Contents', entries: [{ label: 'Opening hours', anchor: 'hours', meta: '7d' }] },
{
kind: 'table', anchor: 'hours', heading: 'Hours', columns: ['Day', 'Hours', 'Status'],
rows: [['Mon–Fri', '07–18', 'done']], monoColumns: [1], statusColumn: 2, note: 'Holidays differ.',
},
];
test('every section kind renders its content', () => {
const html = renderToStaticMarkup(h(SiteSections, { sections: SECTIONS }));
for (const needle of [
'Coffee, done properly.', 'A neighbourhood café.', 'Seats', '25%', 'Espresso',
'CHF 4.50', 'Cortado', '#hours', 'id="hours"', 'Mon–Fri', 'Holidays differ.',
]) {
assert.ok(html.includes(needle), `expected rendered html to contain ${JSON.stringify(needle)}`);
}
});
test('numbering counts only headed sections, hero and table take none', () => {
const html = renderToStaticMarkup(h(SiteSections, { sections: SECTIONS }));
// Headed sections number 01–05: prose, stats, cards, definitions, index.
// Hero and table never number; the meter here has no heading so it skips too.
assert.ok(html.includes('>01<'));
assert.ok(html.includes('>05<'));
assert.ok(!html.includes('>06<'), 'only headed, numberable sections take a number');
});
const CHROME = { name: 'Café Beispiel', tagline: 'Kaffee', footerNote: 'Run by its owners.', host: 'beispiel.ch' };
const NAV = [{ path: '', label: 'Home' }, { path: 'menu', label: 'Menu' }];
test('masthead defaults to plain anchors', () => {
const html = renderToStaticMarkup(h(SiteMasthead, { chrome: CHROME, navItems: NAV, currentPath: 'menu' }));
assert.ok(html.includes('<a href="/menu"'));
assert.ok(html.includes('aria-current="page"'));
});
test('the Link seam injects a framework component', () => {
const FakeLink = props => h('a', { ...props, 'data-framework': 'yes' });
const html = renderToStaticMarkup(
h(SiteMasthead, { chrome: CHROME, navItems: NAV, currentPath: '', Link: FakeLink }),
);
assert.ok(html.includes('data-framework="yes"'));
});
test('footer shows host only when given', () => {
const withHost = renderToStaticMarkup(h(SiteFooter, { chrome: CHROME }));
assert.ok(withHost.includes('beispiel.ch'));
const rest = { ...CHROME };
delete rest.host;
const withoutHost = renderToStaticMarkup(h(SiteFooter, { chrome: rest }));
assert.ok(!withoutHost.includes('beispiel.ch'));
});