feat(website): the four templates and the public site
Heritage, Bold, Community and Clean drawing all 26 section variants with their headers, homepage order and style settings; colours made safe (WCAG AA) by the backend; fonts and corners from the shared brand style. Publishing into numbered versions, the content API with live messages and events and the church profile from Accounts, uploads, every page kind, simple event pages, Coming soon, 404, sitemap, SEO basics and the church's JSON-LD. The demo church (npm run demo) and Playwright e2e: every template's pages pass axe and the SEO checks. website.sh builds packages/seo. Decision 17 (first Owner) recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
test-results/
|
||||
playwright-report/
|
||||
.uploads/
|
||||
screens/
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* The e2e backend (playwright.config.ts): the Website's backend on port 5310 with the in-memory
|
||||
* database from the backend tests (no Postgres needed) and the demo church published. The pages
|
||||
* run with `next dev` on 3310 and send /api here.
|
||||
*
|
||||
* Test helpers: POST /test/demo?template=<id> loads the demo church on that template;
|
||||
* POST /test/design { variants?, style?, home? } changes the design and publishes again.
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import express from 'express';
|
||||
import { websiteTemplateSchema } from '@crosscode/contracts';
|
||||
import { createApp } from '../backend/src/app.js';
|
||||
import { createCtx } from '../backend/src/context.js';
|
||||
import { loadDemo } from '../backend/src/demo/demoChurch.js';
|
||||
import { loadConfig } from '../backend/src/lib/config.js';
|
||||
import { publish } from '../backend/src/site/snapshot.js';
|
||||
import { memoryDb } from '../backend/tests/support/memoryDb.js';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
const uploads = path.join(here, '.uploads');
|
||||
fs.mkdirSync(uploads, { recursive: true });
|
||||
|
||||
const db = memoryDb();
|
||||
const ctx = createCtx(loadConfig({ WEBSITE_URL: 'http://localhost:3310', NODE_ENV: 'test', JOBS_ENABLED: 'false', HUB_URL: 'http://127.0.0.1:1', UPLOAD_DIR: uploads, TRUST_PROXY: 'true' }), db as never);
|
||||
await loadDemo(ctx, websiteTemplateSchema.parse(process.env.DEMO_TEMPLATE ?? 'heritage'), { uploadDir: uploads });
|
||||
|
||||
const app = express();
|
||||
app.post('/test/demo', async (req, res) => {
|
||||
const t = websiteTemplateSchema.safeParse(req.query.template);
|
||||
if (!t.success) return res.status(400).json({ error: 'template' });
|
||||
await loadDemo(ctx, t.data, { uploadDir: uploads });
|
||||
return res.json({ ok: true, template: t.data });
|
||||
});
|
||||
app.post('/test/design', express.json(), async (req, res) => {
|
||||
const d = (await db.siteDesign.findUnique({ where: { id: 1 } })) as { variants: object; style: object; home: unknown };
|
||||
await db.siteDesign.update({ where: { id: 1 }, data: {
|
||||
variants: { ...d.variants, ...(req.body.variants ?? {}) },
|
||||
style: { ...d.style, ...(req.body.style ?? {}) },
|
||||
home: req.body.home ?? d.home,
|
||||
} });
|
||||
const v = await publish(ctx, { id: 'e2e', role: 'system' });
|
||||
res.json({ ok: true, version: v.number });
|
||||
});
|
||||
app.use(createApp(ctx));
|
||||
app.listen(5310, '127.0.0.1', () => console.log('[e2e] Website backend on 5310 with the demo church.'));
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Every template with the demo church (WEBSITE-1.0-PLAN §13): the pages render at phone and desktop
|
||||
* width, axe finds no violations, and the §11 basics are there (title, description, canonical,
|
||||
* one <h1>, JSON-LD that parses). Screenshots go to e2e/screens/ for a look (not compared yet).
|
||||
*/
|
||||
import AxeBuilder from "@axe-core/playwright";
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
const TEMPLATES = ["heritage", "bold", "community", "clean"] as const;
|
||||
const PAGES = ["/", "/visit", "/ministries", "/events", "/messages", "/contact"];
|
||||
|
||||
async function useTemplate(page: Page, template: string) {
|
||||
const res = await page.request.post(`http://127.0.0.1:5310/test/demo?template=${template}`);
|
||||
expect(res.ok()).toBeTruthy();
|
||||
}
|
||||
|
||||
async function seoBasics(page: Page) {
|
||||
await expect(page).toHaveTitle(/.+/);
|
||||
expect(await page.locator('meta[name="description"]').getAttribute("content")).toBeTruthy();
|
||||
expect(await page.locator('link[rel="canonical"]').getAttribute("href")).toBeTruthy();
|
||||
await expect(page.locator("h1")).toHaveCount(1);
|
||||
for (const ld of await page.locator('script[type="application/ld+json"]').allTextContents()) JSON.parse(ld);
|
||||
expect(await page.locator("html").getAttribute("lang")).toBe("en-ZA");
|
||||
}
|
||||
|
||||
for (const template of TEMPLATES) {
|
||||
test.describe(template, () => {
|
||||
test.beforeEach(async ({ page }) => useTemplate(page, template));
|
||||
|
||||
test("its pages: accessible, with the SEO basics", async ({ page }) => {
|
||||
for (const path of PAGES) {
|
||||
const res = await page.goto(path);
|
||||
expect(res?.status(), path).toBe(200);
|
||||
await expect(page.locator("html")).toHaveAttribute("data-template", template);
|
||||
await seoBasics(page);
|
||||
const axe = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa"]).analyze();
|
||||
expect(axe.violations.map((v) => `${path}: ${v.id} (${v.nodes.length}) ${v.nodes[0]?.target}`)).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
test("screenshots at phone and desktop", async ({ page }) => {
|
||||
for (const [name, size] of [["desktop", { width: 1366, height: 900 }], ["phone", { width: 390, height: 844 }]] as const) {
|
||||
await page.setViewportSize(size);
|
||||
await page.goto("/");
|
||||
// Scroll through, so lazy images load before the full-page shot.
|
||||
await page.evaluate(async () => {
|
||||
for (let y = 0; y < document.body.scrollHeight; y += 600) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 60)); }
|
||||
window.scrollTo(0, 0);
|
||||
});
|
||||
// The page's own images (not the map, which loads from OpenStreetMap).
|
||||
await page.waitForFunction(() => Array.from(document.images).every((i) => i.complete), null, { timeout: 30_000 });
|
||||
await page.screenshot({ path: `e2e/screens/${template}-home-${name}.png`, fullPage: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
test("the home page has the church's JSON-LD; unknown pages are a real 404", async ({ page }) => {
|
||||
await useTemplate(page, "heritage");
|
||||
await page.goto("/");
|
||||
const ld = JSON.parse((await page.locator('script[type="application/ld+json"]').first().textContent())!);
|
||||
expect(ld["@type"]).toBe("Church");
|
||||
expect(ld.name).toBe("Acacia Hill Church");
|
||||
expect((await page.goto("/no-such-page"))?.status()).toBe(404);
|
||||
});
|
||||
|
||||
test("robots.txt keeps the admin out; the sitemap lists the pages", async ({ page }) => {
|
||||
const robots = await (await page.request.get("/robots.txt")).text();
|
||||
expect(robots).toContain("Disallow: /admin");
|
||||
const sitemap = await (await page.request.get("/sitemap.xml")).text();
|
||||
expect(sitemap).toContain("/visit</loc>");
|
||||
expect(sitemap).not.toContain("/admin");
|
||||
});
|
||||
Reference in New Issue
Block a user