Files
crosscode-platform/apps/website/backend/tests/starter.test.ts
T
joshuaandClaude Opus 5.5 79e1450df6 Website 1.2.0: starter pages on a new install, and a site icon
A new install had no pages, so the home page and its live preview showed
only the header and footer (found on cross-demo2). The backend now adds the
fixed pages with starter text at startup. Settings -> Site icon sets the
favicon, with a default from the church's colour and initial. The Latest
message's Card layout has its name; the media picker's placeholder has
enough contrast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:18:47 +02:00

43 lines
2.5 KiB
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { previewContent } from '../src/site/content.js';
import { ensureStarterPages, STARTER_PAGES } from '../src/site/starter.js';
import { harness } from './support/harness.js';
describe('a new install\'s starter pages', () => {
it('adds the fixed pages to a site with none, and the preview shows every homepage section', async () => {
const { ctx, db } = await harness({ linked: false });
assert.deepEqual(await ensureStarterPages(ctx), STARTER_PAGES.map((p) => p.kind));
const c = await previewContent(ctx);
assert.equal(c.mode, 'published');
if (c.mode !== 'published') return;
const home = c.snapshot.pages.find((p) => p.kind === 'home')!;
assert.deepEqual(home.sections.map((s) => s.type).sort(), ['events', 'hero', 'invitation', 'latestMessage', 'ministries', 'serviceTimes', 'team', 'welcome']);
// Every starter block fits its schema (a broken one would be left out of the site).
for (const p of STARTER_PAGES) assert.equal(c.snapshot.pages.find((x) => x.kind === p.kind)!.sections.length, p.sections.length, p.kind);
// Terms and Safeguarding are footer links, not menu items.
assert.equal(c.snapshot.pages.filter((p) => p.inNav).some((p) => p.kind === 'terms' || p.kind === 'safeguarding'), false);
// Only once.
assert.deepEqual(await ensureStarterPages(ctx), []);
assert.equal(await db.page.count(), STARTER_PAGES.length);
});
it('keeps the church\'s own pages, after the fixed ones, and skips an address they already use', async () => {
const { ctx, db } = await harness({ linked: false });
await db.page.create({ data: { kind: 'custom', slug: 'test', title: 'Test', position: 1 } });
await db.page.create({ data: { kind: 'custom', slug: 'give', title: 'Giving', position: 2 } });
const kinds = await ensureStarterPages(ctx);
assert.ok(kinds.includes('home') && !kinds.includes('give'));
const pages = await db.page.findMany({ orderBy: { position: 'asc' } });
assert.equal(pages[0]!.kind, 'home');
assert.deepEqual(pages.slice(-2).map((p) => p.slug), ['test', 'give']);
});
it('adds only a missing home page to a site that has its other fixed pages', async () => {
const { ctx, db } = await harness({ linked: false });
await db.page.create({ data: { kind: 'about', slug: 'about', title: 'About', archivedAt: new Date() } });
assert.deepEqual(await ensureStarterPages(ctx), ['home']);
assert.deepEqual(await ensureStarterPages(ctx), []);
});
});