The demo church (and the eight demo profiles) used one generated "hills and sun" SVG for every picture. Now 104 Unsplash stock photos (models; free under the Unsplash License, credited in backend/demo-photos/CREDITS.md): a set per profile, a portrait for every leader (before: only the pastor), a picture for each event, and a photo for each message instead of the stand-in video's thumbnail. Demo photos go through processImage like an upload, made once per machine and copied; without demo-photos/ the illustration still stands in. A message's thumbnailUrl that is one of the site's own uploads now comes before the YouTube thumbnail; admins and the YouTube feed store YouTube's address there, so a church's own messages are unchanged. Faster on phones: the Community collage hero, the collage row, the team's portraits and the ministry cards give the browser their real width (sizes), so a phone no longer fetches the full-width photo for a small frame. Checked: backend tests (131), Website e2e (130, baselines retaken; Lighthouse mobile 90-98 performance, 100 accessibility and SEO), typecheck, lint and both builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
7.0 KiB
TypeScript
126 lines
7.0 KiB
TypeScript
/**
|
|
* 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("the messages ask nothing of YouTube until play is clicked; their thumbnails come from the site", async ({ page }) => {
|
|
await useTemplate(page, "heritage");
|
|
const outside: string[] = [];
|
|
page.on("request", (r) => { if (/youtube|ytimg|spotify/.test(new URL(r.url()).hostname)) outside.push(r.url()); });
|
|
await page.goto("/messages");
|
|
const thumb = page.locator("main img").first();
|
|
// The demo's messages have photos of their own (uploads); a church's show their YouTube video's
|
|
// thumbnail, served from /api/thumbnails/ (backend tests). Either way, from the site.
|
|
await expect(thumb).toHaveAttribute("src", /^\/api\/(thumbnails\/[\w-]+\.jpg|uploads\/demo\/[\w-]+\.webp)$/);
|
|
await expect.poll(() => thumb.evaluate((i: HTMLImageElement) => i.naturalWidth)).toBeGreaterThan(0);
|
|
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
|
await page.waitForLoadState("networkidle");
|
|
expect(outside).toEqual([]);
|
|
});
|
|
|
|
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");
|
|
});
|
|
|
|
test("structured data on event and other pages, a made share image, the verification codes, a moved page", async ({ page }) => {
|
|
const backend = "http://127.0.0.1:5310";
|
|
await page.request.post(`${backend}/test/demo?template=heritage`);
|
|
await page.goto("/events");
|
|
const ld = (await page.locator('script[type="application/ld+json"]').allTextContents()).map((t) => JSON.parse(t));
|
|
expect(ld.some((x) => x["@type"] === "BreadcrumbList")).toBeTruthy();
|
|
await page.getByRole("link", { name: "Family picnic" }).first().click();
|
|
await expect(page.getByRole("heading", { level: 1, name: "Family picnic" })).toBeVisible();
|
|
const eventLd = (await page.locator('script[type="application/ld+json"]').allTextContents()).map((t) => JSON.parse(t));
|
|
const ev = eventLd.find((x) => x["@type"] === "Event");
|
|
expect(ev.name).toBe("Family picnic");
|
|
expect(ev.location["@type"]).toBe("Place");
|
|
|
|
// Pages without their own photo share a made image.
|
|
await page.goto("/visit");
|
|
const og = await page.locator('meta[property="og:image"]').getAttribute("content");
|
|
expect(og).toContain("/share-image?t=");
|
|
const img = await page.request.get(new URL(og!).pathname + new URL(og!).search);
|
|
expect(img.status()).toBe(200);
|
|
expect(img.headers()["content-type"]).toBe("image/png");
|
|
|
|
// An admin sets the codes and moves a page; the old address goes on to the new one.
|
|
const { cookie } = await (await page.request.post(`${backend}/test/session?role=editor`)).json();
|
|
const headers = { Cookie: `ccw_session=${cookie.value}`, Origin: "http://localhost:3310", "Content-Type": "application/json" };
|
|
await page.request.put("/api/v1/admin/settings", { headers, data: { googleVerification: "googleCode123", bingVerification: "bingCode456" } });
|
|
const pages = await (await page.request.get("/api/v1/admin/pages", { headers })).json();
|
|
const visit = pages.find((p: { kind: string }) => p.kind === "visit");
|
|
expect((await page.request.put(`/api/v1/admin/pages/${visit.id}`, { headers, data: { slug: "first-visit" } })).ok()).toBeTruthy();
|
|
expect((await page.request.post("/api/v1/admin/publish", { headers, data: {} })).ok()).toBeTruthy();
|
|
const moved = await page.request.get("/visit", { maxRedirects: 0 });
|
|
expect([301, 308]).toContain(moved.status());
|
|
expect(moved.headers().location).toContain("/first-visit");
|
|
await page.goto("/");
|
|
expect(await page.locator('meta[name="google-site-verification"]').getAttribute("content")).toBe("googleCode123");
|
|
expect(await page.locator('meta[name="msvalidate.01"]').getAttribute("content")).toBe("bingCode456");
|
|
});
|