Backend (Express + Prisma, ES modules, as Accounts): /api/health and /api/v1/site/status (Coming soon until the first publish), the content model and its first migration, and the confirmed section variants per template (WEBSITE-1.0-PLAN §3, decision 16) with the template switch rules, with tests. Frontend (Next.js 16): Coming soon page, admin placeholder, robots.txt. env.template.json, PM2 example, CHANGELOG and WHATS-NEW. Root workspaces and lint updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
4.7 KiB
TypeScript
104 lines
4.7 KiB
TypeScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { WEBSITE_TEMPLATES } from '@crosscode/contracts';
|
|
import {
|
|
SECTION_TYPES, SECTION_VARIANTS, TEMPLATE_HEADERS, TEMPLATE_HOME_ORDER, TEMPLATE_STYLE, TEMPLATE_VARIANTS,
|
|
defaultDesign, defaultVariant, headerIsTransparent, isRecommended, isVariant, switchTemplate,
|
|
} from '../src/site/variants.js';
|
|
|
|
describe('section variants (WEBSITE-1.0-PLAN §3, decision 16)', () => {
|
|
it('has the 26 confirmed variant ids', () => {
|
|
assert.equal(Object.values(SECTION_VARIANTS).flat().length, 26);
|
|
assert.deepEqual(SECTION_VARIANTS.hero, ['photo', 'video', 'collage', 'split', 'text']);
|
|
});
|
|
|
|
it('every template recommends only real variants, without repeats, with a default for every section', () => {
|
|
for (const t of WEBSITE_TEMPLATES) {
|
|
for (const s of SECTION_TYPES) {
|
|
const rec = TEMPLATE_VARIANTS[t][s] as readonly string[];
|
|
assert.ok(rec.length >= 2, `${t}.${s}`);
|
|
assert.equal(new Set(rec).size, rec.length, `${t}.${s} repeats`);
|
|
for (const v of rec) assert.ok(isVariant(s, v), `${t}.${s}: ${v}`);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('has the confirmed defaults', () => {
|
|
assert.equal(defaultVariant('heritage', 'hero'), 'photo');
|
|
assert.equal(defaultVariant('bold', 'hero'), 'video');
|
|
assert.equal(defaultVariant('community', 'hero'), 'collage');
|
|
assert.equal(defaultVariant('clean', 'hero'), 'text');
|
|
assert.equal(defaultVariant('clean', 'latestMessage'), 'compact');
|
|
assert.ok(isRecommended('heritage', 'team', 'faces'));
|
|
assert.ok(!isRecommended('heritage', 'team', 'list'));
|
|
});
|
|
|
|
it('lists every section once in each homepage order; Bold hides Team, Clean hides Ministries and Team', () => {
|
|
for (const t of WEBSITE_TEMPLATES) {
|
|
assert.deepEqual([...TEMPLATE_HOME_ORDER[t].map((e) => e.section)].sort(), [...SECTION_TYPES].sort(), t);
|
|
}
|
|
const hidden = (t: keyof typeof TEMPLATE_HOME_ORDER) => TEMPLATE_HOME_ORDER[t].filter((e) => e.hidden).map((e) => e.section);
|
|
assert.deepEqual(hidden('heritage'), []);
|
|
assert.deepEqual(hidden('bold'), ['team']);
|
|
assert.deepEqual(hidden('community'), []);
|
|
assert.deepEqual(hidden('clean'), ['ministries', 'team']);
|
|
});
|
|
|
|
it("each template's default header is the first of its options", () => {
|
|
for (const t of WEBSITE_TEMPLATES) assert.equal(TEMPLATE_STYLE[t].header, TEMPLATE_HEADERS[t][0]);
|
|
});
|
|
|
|
it('suggests the confirmed corners', () => {
|
|
assert.deepEqual(WEBSITE_TEMPLATES.map((t) => TEMPLATE_STYLE[t].suggestedCorners), ['sharp', 'sharp', 'round', 'soft']);
|
|
});
|
|
|
|
it('only makes the header transparent over a photo, video or collage hero', () => {
|
|
assert.ok(headerIsTransparent('bold', 'transparent', 'video'));
|
|
assert.ok(!headerIsTransparent('bold', 'transparent', 'text'));
|
|
assert.ok(!headerIsTransparent('bold', 'transparent', 'split'));
|
|
assert.ok(!headerIsTransparent('bold', 'solid', 'photo'));
|
|
assert.ok(!headerIsTransparent('bold', 'transparent', null));
|
|
});
|
|
});
|
|
|
|
describe('switching template', () => {
|
|
it('moves an untouched site to every default of the new template', () => {
|
|
const { design, changes } = switchTemplate(defaultDesign('community'), 'clean');
|
|
assert.deepEqual(design, defaultDesign('clean'));
|
|
assert.ok(changes.some((c) => c.what === 'hero.variant' && c.from === 'collage' && c.to === 'text'));
|
|
assert.ok(changes.some((c) => c.what === 'home'));
|
|
assert.equal(changes[0]!.what, 'template');
|
|
});
|
|
|
|
it("keeps the church's own choices", () => {
|
|
const start = defaultDesign('heritage');
|
|
start.variants.hero = 'video';
|
|
start.style.buttons = 'pill';
|
|
start.home = [...start.home].reverse();
|
|
const { design, changes } = switchTemplate(start, 'clean');
|
|
assert.equal(design.template, 'clean');
|
|
assert.equal(design.variants.hero, 'video');
|
|
assert.equal(design.style.buttons, 'pill');
|
|
assert.deepEqual(design.home, start.home);
|
|
assert.equal(design.variants.team, 'list', 'an untouched section still moves');
|
|
assert.ok(!changes.some((c) => c.what === 'hero.variant' || c.what === 'home' || c.what === 'style.buttons'));
|
|
});
|
|
|
|
it("moves a header the new template doesn't have", () => {
|
|
const start = defaultDesign('bold');
|
|
start.style.header = 'solid';
|
|
const { design } = switchTemplate(start, 'heritage');
|
|
assert.equal(design.style.header, 'centred');
|
|
});
|
|
|
|
it('changes nothing when the template stays', () => {
|
|
const d = defaultDesign('bold');
|
|
assert.deepEqual(switchTemplate(d, 'bold'), { design: d, changes: [] });
|
|
});
|
|
|
|
it('round-trips an untouched site', () => {
|
|
const there = switchTemplate(defaultDesign('heritage'), 'bold').design;
|
|
assert.deepEqual(switchTemplate(there, 'heritage').design, defaultDesign('heritage'));
|
|
});
|
|
});
|