- Blocks get layouts (BLOCK_VARIANTS: text standard/centred; image and text photo left, right or above; quote centred/with a line; call to action centred/banner), stored on Section.variant and checked against the type; an unknown one draws as the default, as every block looked before. The demo's image-text block id is now image-left. - Each block has its own background (Section.background, migration 20261201000000_block_background), in the published source only when set, put back by Discard and Restore, drawn as the homepage's (data-bg). - MP4 uploads up to 20 MB for the hero's Video layout: QuickTime refused, metadata boxes (udta, meta, uuid) blanked into free boxes of the same size so where it was filmed is gone and the frame offsets hold; size read from tkhd. GET /media lists mime. - Admin: a block's Layout and Background when open; the hero's Video field (only videos; photo fields only photos); the media library shows and takes videos. An upload over the limit says so instead of "That request isn't valid." - Tests: backend (152, three new); e2e for block layouts and a video upload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
368 lines
21 KiB
TypeScript
368 lines
21 KiB
TypeScript
/**
|
|
* The admin's flows (WEBSITE-1.0-PLAN §13): edit → preview (click through the site) → publish →
|
|
* the public site changes; discard one change; a shared preview link works signed out and stops
|
|
* after revoking; restore an older version; switch template in preview without losing anything.
|
|
* Runs on the e2e server (e2e/server.ts): the demo church on Heritage, an admin signed in directly.
|
|
*/
|
|
import AxeBuilder from "@axe-core/playwright";
|
|
import { expect, test, type BrowserContext, type Page } from "@playwright/test";
|
|
|
|
const BACKEND = "http://127.0.0.1:5310";
|
|
|
|
async function reset(page: Page) {
|
|
expect((await page.request.post(`${BACKEND}/test/demo?template=heritage`)).ok()).toBeTruthy();
|
|
}
|
|
|
|
async function signIn(context: BrowserContext, role = "editor") {
|
|
const res = await context.request.post(`${BACKEND}/test/session?role=${role}`);
|
|
const { cookie } = await res.json();
|
|
await context.addCookies([{ name: cookie.name, value: cookie.value, url: "http://localhost:3310" }]);
|
|
}
|
|
|
|
async function aboutTitle(page: Page, title: string) {
|
|
await page.goto("/admin/pages");
|
|
await page.getByRole("link", { name: /^About us\b/ }).first().click();
|
|
// The list page has a Title field too (Add a page): wait for the page's own editor.
|
|
await expect(page).toHaveURL(/\/admin\/pages\/[0-9a-f-]+$/);
|
|
await expect(page.getByRole("heading", { level: 1, name: "About us" })).toBeVisible();
|
|
// The editor opens on the page's content; the title is under Page details.
|
|
await page.getByRole("tab", { name: "Page details" }).click();
|
|
await page.getByLabel("Title", { exact: true }).fill(title);
|
|
await page.getByRole("button", { name: "Save details" }).click();
|
|
await expect(page.getByText("Saved as a draft.")).toBeVisible();
|
|
}
|
|
|
|
test.beforeEach(async ({ page }) => reset(page));
|
|
|
|
test("edit, preview the whole site, publish: then visitors see it", async ({ page, context, browser }) => {
|
|
await signIn(context);
|
|
await aboutTitle(page, "Our story");
|
|
await page.goto("/admin");
|
|
await expect(page.getByRole("link", { name: "1 change not published" })).toBeVisible();
|
|
|
|
// Preview: the real addresses, with the bar; click through to the changed page.
|
|
await page.getByRole("link", { name: "Preview", exact: true }).click();
|
|
await expect(page.getByRole("region", { name: "Preview" })).toBeVisible();
|
|
await page.getByRole("navigation", { name: "Main" }).getByRole("link", { name: "Our story" }).click();
|
|
await expect(page.getByRole("heading", { level: 1, name: "Our story" })).toBeVisible();
|
|
|
|
// Someone else still sees the published site.
|
|
const visitor = await browser.newPage();
|
|
await visitor.goto("/about");
|
|
await expect(visitor.getByRole("heading", { level: 1, name: "About us" })).toBeVisible();
|
|
await expect(visitor.getByRole("region", { name: "Preview" })).toHaveCount(0);
|
|
|
|
await page.getByRole("button", { name: "Publish" }).click();
|
|
await expect(page).toHaveURL(/\/admin\/publish/);
|
|
await expect(page.getByText("Nothing waiting to be published")).toBeVisible();
|
|
await visitor.goto("/about");
|
|
await expect(visitor.getByRole("heading", { level: 1, name: "Our story" })).toBeVisible();
|
|
await visitor.close();
|
|
});
|
|
|
|
test("the live preview beside the editor shows the draft; the site itself doesn't", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await aboutTitle(page, "Draft title");
|
|
const frame = page.frameLocator('iframe[title="Live preview of this page"]');
|
|
await expect(frame.getByRole("heading", { level: 1, name: "Draft title" })).toBeVisible();
|
|
// No preview cookie: the same browser, outside the frame, still sees the live site.
|
|
await page.goto("/about");
|
|
await expect(page.getByRole("heading", { level: 1, name: "About us" })).toBeVisible();
|
|
await expect(page.getByRole("region", { name: "Preview" })).toHaveCount(0);
|
|
// Folded away, it stays folded.
|
|
await page.goBack();
|
|
await page.getByRole("button", { name: "Hide the preview" }).click();
|
|
await expect(page.getByRole("button", { name: "Show the live preview" })).toBeVisible();
|
|
await page.reload();
|
|
await expect(page.getByRole("button", { name: "Show the live preview" })).toBeVisible();
|
|
});
|
|
|
|
test("discard one change", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await aboutTitle(page, "Changed my mind");
|
|
await page.goto("/admin/publish");
|
|
await expect(page.getByRole("heading", { name: "1 change not published" })).toBeVisible();
|
|
await page.getByRole("button", { name: "Discard" }).click();
|
|
await expect(page.getByText("Discarded: back to the published version.")).toBeVisible();
|
|
await expect(page.getByText("Nothing waiting to be published")).toBeVisible();
|
|
});
|
|
|
|
test("a shared preview link works signed out, and stops when revoked", async ({ page, context, browser }) => {
|
|
await signIn(context);
|
|
await aboutTitle(page, "For the pastor");
|
|
await page.goto("/admin/publish");
|
|
await page.getByRole("button", { name: "Make a preview link" }).click();
|
|
const url = (await page.locator("code").textContent())!.trim();
|
|
|
|
const pastor = await browser.newContext();
|
|
const p = await pastor.newPage();
|
|
await p.goto(new URL(url).pathname);
|
|
await expect(p.getByRole("region", { name: "Preview" })).toBeVisible();
|
|
await expect(p.getByRole("button", { name: "Publish" })).toHaveCount(0);
|
|
await p.goto("/about");
|
|
await expect(p.getByRole("heading", { level: 1, name: "For the pastor" })).toBeVisible();
|
|
|
|
await page.getByRole("button", { name: "Stop it" }).click();
|
|
await expect(page.getByText("The link stopped working.")).toBeVisible();
|
|
await p.goto("/about");
|
|
await expect(p.getByRole("heading", { level: 1, name: "About us" })).toBeVisible();
|
|
await expect(p.getByRole("region", { name: "Preview" })).toHaveCount(0);
|
|
await pastor.close();
|
|
});
|
|
|
|
test("restore an older version, then publish it", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await aboutTitle(page, "Version two");
|
|
await page.goto("/admin/publish");
|
|
await page.getByRole("button", { name: "Publish all changes" }).click();
|
|
await expect(page.getByText("Published: visitors see it now.")).toBeVisible();
|
|
await page.getByRole("button", { name: "Restore" }).click();
|
|
await expect(page.getByText("Version 1 is back in your drafts")).toBeVisible();
|
|
await page.getByRole("button", { name: "Publish all changes" }).click();
|
|
// Wait for it, as above: on real Postgres the publish takes long enough to race the page load.
|
|
await expect(page.getByText("Published: visitors see it now.")).toBeVisible();
|
|
await page.goto("/about");
|
|
await expect(page.getByRole("heading", { level: 1, name: "About us" })).toBeVisible();
|
|
});
|
|
|
|
test("switch template in the preview, and back, without losing anything", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await page.goto("/admin/template");
|
|
await page.getByRole("button", { name: "Use Bold" }).click();
|
|
await expect(page.getByText("Switched to Bold.")).toBeVisible();
|
|
await page.goto("/preview/start");
|
|
await expect(page.locator("html")).toHaveAttribute("data-template", "bold");
|
|
await expect(page.getByRole("heading", { level: 1, name: "A home for everyone on the hill" })).toBeVisible();
|
|
await page.goto("/admin/template");
|
|
await page.getByRole("button", { name: "Use Heritage" }).click();
|
|
await expect(page.getByText("Switched to Heritage.")).toBeVisible();
|
|
await page.goto("/admin/publish");
|
|
await expect(page.getByText("Nothing waiting to be published")).toBeVisible();
|
|
});
|
|
|
|
test("signed out, the admin sends people to sign in and back to the same page", async ({ page }) => {
|
|
const res = await page.request.get("/admin/pages", { maxRedirects: 0 });
|
|
expect([303, 307, 308]).toContain(res.status());
|
|
expect(res.headers().location).toContain("/api/auth/signin?returnTo=%2Fadmin%2Fpages");
|
|
});
|
|
|
|
test("a Viewer sees the admin but can't publish", async ({ page, context }) => {
|
|
await signIn(context, "viewer");
|
|
await page.goto("/admin/publish");
|
|
await expect(page.getByText("Nothing waiting to be published")).toBeVisible();
|
|
await expect(page.getByRole("button", { name: /Publish/ })).toHaveCount(0);
|
|
});
|
|
|
|
test("an event added and published shows on the site at once (its own Publish)", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await page.goto("/admin/events");
|
|
await page.getByRole("button", { name: "Add an event" }).click();
|
|
await page.getByLabel("Title").fill("Prayer breakfast");
|
|
await page.getByLabel("Date", { exact: true }).fill(new Date(Date.now() + 3 * 864e5).toISOString().slice(0, 10));
|
|
await page.getByLabel("Where", { exact: true }).fill("The hall");
|
|
await page.getByRole("button", { name: "Save" }).click();
|
|
await expect(page.getByText("Not published").first()).toBeVisible();
|
|
await page.getByRole("listitem").filter({ hasText: "Prayer breakfast" }).getByRole("button", { name: "Publish" }).click();
|
|
await expect(page.getByText("On the site now.")).toBeVisible();
|
|
await page.goto("/events");
|
|
await expect(page.getByRole("link", { name: "Prayer breakfast" })).toBeVisible();
|
|
});
|
|
|
|
test("the admin's screens are accessible", async ({ page, context }) => {
|
|
// Fifteen screens, each checked by axe (1.4.0: Backups and Background jobs).
|
|
test.setTimeout(240_000);
|
|
await signIn(context, "owner");
|
|
for (const path of ["/admin", "/admin/template", "/admin/pages", "/admin/ministries", "/admin/leaders", "/admin/messages", "/admin/events", "/admin/linked", "/admin/media", "/admin/publish", "/admin/settings", "/admin/people", "/admin/audit", "/admin/backups", "/admin/jobs"]) {
|
|
await page.goto(path);
|
|
await expect(page.getByRole("heading", { level: 1 })).toBeVisible();
|
|
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([]);
|
|
}
|
|
// And a page's editor, with its live preview beside it.
|
|
await page.goto("/admin/pages");
|
|
await page.getByRole("link", { name: /^Home\b/ }).first().click();
|
|
await expect(page.frameLocator('iframe[title="Live preview of this page"]').getByRole("heading", { level: 1 })).toBeVisible();
|
|
const axe = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa"]).analyze();
|
|
expect(axe.violations.map((v) => `editor: ${v.id} (${v.nodes.length}) ${v.nodes[0]?.target}`)).toEqual([]);
|
|
});
|
|
|
|
test("move and zoom a photo in its frame, then delete a photo nothing uses", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await page.goto("/admin/pages");
|
|
await page.getByRole("link", { name: /^Home\b/ }).first().click();
|
|
await expect(page).toHaveURL(/\/admin\/pages\/[0-9a-f-]+$/);
|
|
await page.getByRole("button", { name: /^Top of the page/ }).click();
|
|
await page.getByRole("button", { name: "Move and zoom" }).first().click();
|
|
const dialog = page.getByRole("dialog", { name: "Move and zoom the photo" });
|
|
await expect(dialog).toBeVisible();
|
|
await dialog.getByRole("slider").fill("2");
|
|
const box = (await dialog.getByLabel(/in its frame/).boundingBox())!;
|
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(box.x + box.width / 2 + 80, box.y + box.height / 2 + 30, { steps: 5 });
|
|
await page.mouse.up();
|
|
await dialog.getByRole("button", { name: "Done" }).click();
|
|
await expect(page.getByText("Moved and zoomed to 200%")).toBeVisible();
|
|
await page.getByRole("button", { name: "Save", exact: true }).click();
|
|
await expect(page.getByText("Saved as a draft.")).toBeVisible();
|
|
// The live preview draws it the same way.
|
|
const frame = page.frameLocator('iframe[title="Live preview of this page"]');
|
|
await expect(frame.locator(".cc-section-hero img").first()).toHaveAttribute("style", /scale\(2\)/);
|
|
await page.screenshot({ path: "e2e/test-results/framing.png" });
|
|
|
|
// Upload one nothing uses, then delete it; one in use says where instead.
|
|
await page.goto("/admin/media");
|
|
// Count once the library has loaded (it can still be empty for a moment).
|
|
await expect(page.locator("main li").first()).toBeVisible();
|
|
const before = await page.locator("main li").count();
|
|
const png = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", "base64");
|
|
await page.locator('input[type="file"]').setInputFiles({ name: "dot.png", mimeType: "image/png", buffer: png });
|
|
await page.getByLabel("What the photo shows").fill("A dot to delete");
|
|
await page.getByRole("button", { name: "Upload" }).click();
|
|
await expect(page.locator("main li")).toHaveCount(before + 1);
|
|
await expect(page.getByText("Used on:").first()).toBeVisible();
|
|
page.once("dialog", (d) => d.accept());
|
|
await page.locator("main li").filter({ has: page.locator('input[value="A dot to delete"]') }).getByRole("button", { name: "Delete" }).click();
|
|
await expect(page.getByText("Deleted.")).toBeVisible();
|
|
await expect(page.locator("main li")).toHaveCount(before);
|
|
});
|
|
|
|
test("move and zoom a ministry's, a leader's and an event's photo", async ({ page, context }) => {
|
|
await signIn(context);
|
|
for (const [path, saved] of [["/admin/ministries", "Saved as a draft."], ["/admin/leaders", "Saved as a draft."], ["/admin/events", null]] as const) {
|
|
await page.goto(path);
|
|
await page.getByRole("button", { name: "Edit", exact: true }).first().click();
|
|
await page.getByRole("button", { name: "Move and zoom" }).first().click();
|
|
const dialog = page.getByRole("dialog", { name: "Move and zoom the photo" });
|
|
await dialog.getByRole("slider").fill("2");
|
|
await dialog.getByRole("button", { name: "Done" }).click();
|
|
await expect(page.getByText("Moved and zoomed to 200%")).toBeVisible();
|
|
await page.getByRole("button", { name: "Save", exact: true }).click();
|
|
if (saved) await expect(page.getByText(saved)).toBeVisible();
|
|
else await expect(page.getByRole("button", { name: "Save", exact: true })).toHaveCount(0);
|
|
// Saved with the row: it's there when the form opens again.
|
|
await page.getByRole("button", { name: "Edit", exact: true }).first().click();
|
|
await expect(page.getByText("Moved and zoomed to 200%")).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test("on the home page: each section's layout, background, place and showing, and only the photos its layout shows", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await page.goto("/admin/pages");
|
|
await page.getByRole("link", { name: /^Home\b/ }).first().click();
|
|
await expect(page).toHaveURL(/\/admin\/pages\/[0-9a-f-]+$/);
|
|
const preview = page.frameLocator('iframe[title="Live preview of this page"]');
|
|
|
|
// The top of the page: a slot for each photo the layout shows (the demo has three photos).
|
|
await page.getByRole("button", { name: /^Top of the page/ }).click();
|
|
const layout = page.getByLabel("Top of the page (hero): layout");
|
|
await layout.selectOption("collage");
|
|
await expect(page.getByText("Photo 3 of 3")).toBeVisible();
|
|
await layout.selectOption("photo");
|
|
await expect(page.getByText("Photo 1 of 3")).toHaveCount(0);
|
|
await expect(page.getByText("2 more photos are kept for a layout that shows more.")).toBeVisible();
|
|
await layout.selectOption("text");
|
|
await expect(page.getByText("This layout shows no photos.")).toBeVisible();
|
|
await expect(preview.locator(".cc-section-hero img")).toHaveCount(0);
|
|
|
|
// The welcome: its photo fields follow its layout, and it takes a background.
|
|
await page.getByRole("button", { name: /^Welcome/ }).click();
|
|
const welcome = page.locator("section").filter({ has: page.getByRole("button", { name: /^Welcome/ }) }).last();
|
|
await page.getByLabel("Welcome: layout").selectOption("text");
|
|
await expect(welcome.getByText("Pastor's photo and quote")).toHaveCount(0);
|
|
await page.getByLabel("Welcome: layout").selectOption("pastor");
|
|
await expect(welcome.getByText("Pastor's photo and quote")).toBeVisible();
|
|
await page.getByLabel("Welcome: background").selectOption("brand");
|
|
await expect(page.getByLabel("Welcome: background")).toHaveValue("brand");
|
|
|
|
// Hide it, show it, and move it.
|
|
await page.getByRole("button", { name: "Hide Welcome" }).click();
|
|
await expect(welcome.getByText("Not shown")).toBeVisible();
|
|
await page.getByRole("button", { name: "Show Welcome" }).click();
|
|
await expect(welcome.getByText("Not shown")).toHaveCount(0);
|
|
const order = async () => page.locator("main section > div > button").evaluateAll((els) => els.map((e) => e.textContent?.split("·")[0]?.trim() ?? ""));
|
|
const before = await order();
|
|
const at = before.findIndex((t) => t.startsWith("Welcome"));
|
|
await page.getByRole("button", { name: "Move Welcome up" }).click();
|
|
await expect.poll(async () => (await order()).findIndex((t) => t.startsWith("Welcome"))).toBe(at - 1);
|
|
|
|
// Template and style shows the same.
|
|
await page.goto("/admin/template");
|
|
await page.getByRole("tab", { name: "Home page layout" }).click();
|
|
await expect(page.getByLabel("Top of the page layout")).toHaveValue("text");
|
|
await expect(page.getByLabel("Welcome background")).toHaveValue("brand");
|
|
});
|
|
|
|
/** A small MP4 (ftyp, moov with one track, mdat): enough to upload; browsers needn't play it. */
|
|
function tinyMp4(): Buffer {
|
|
const box = (type: string, ...parts: Buffer[]) => {
|
|
const body = Buffer.concat(parts);
|
|
const head = Buffer.alloc(8);
|
|
head.writeUInt32BE(8 + body.length, 0);
|
|
head.write(type, 4, "latin1");
|
|
return Buffer.concat([head, body]);
|
|
};
|
|
const tkhd = Buffer.alloc(84);
|
|
tkhd.writeUInt32BE(640 << 16, 76);
|
|
tkhd.writeUInt32BE(360 << 16, 80);
|
|
return Buffer.concat([box("ftyp", Buffer.from("isom\0\0\0\0isommp42", "latin1")), box("moov", box("mvhd", Buffer.alloc(100)), box("trak", box("tkhd", tkhd))), box("mdat", Buffer.from("frames"))]);
|
|
}
|
|
|
|
test("a page's blocks: their layouts and backgrounds", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await page.goto("/admin/pages");
|
|
await page.getByRole("link", { name: /^Plan your visit\b/ }).first().click();
|
|
await expect(page).toHaveURL(/\/admin\/pages\/[0-9a-f-]+$/);
|
|
const preview = page.frameLocator('iframe[title="Live preview of this page"]');
|
|
await expect(preview.locator("section[data-bg]")).toHaveCount(0);
|
|
|
|
await page.getByRole("button", { name: /^Text/ }).first().click();
|
|
await page.getByLabel("Text block 1: background").selectOption("dark");
|
|
await expect(preview.locator('section[data-bg="dark"]')).toHaveCount(1);
|
|
await page.getByLabel("Text block 1: layout").selectOption("centred");
|
|
await expect(preview.locator("section .cc-text.text-center")).toHaveCount(1);
|
|
|
|
await page.getByRole("button", { name: /^Image and text/ }).first().click();
|
|
await page.getByLabel("Image and text block 2: layout").selectOption("image-right");
|
|
await expect(preview.locator('.cc-frame[class*="md:order-2"]')).toHaveCount(1);
|
|
|
|
await page.getByRole("button", { name: /^Call to action/ }).first().click();
|
|
await expect(preview.locator("section.cc-own-bg")).toHaveCount(0);
|
|
await page.getByLabel("Call to action block 3: layout").selectOption("banner");
|
|
await expect(preview.locator("section.cc-own-bg")).toHaveCount(1);
|
|
|
|
// Saved on the blocks: there when the page opens again.
|
|
await page.reload();
|
|
await page.getByRole("button", { name: /^Image and text/ }).first().click();
|
|
await expect(page.getByLabel("Image and text block 2: layout")).toHaveValue("image-right");
|
|
await expect(page.getByRole("button", { name: /^Call to action/ }).first()).toContainText("Banner in your colour");
|
|
});
|
|
|
|
test("upload a video for the top of the page's Video layout", async ({ page, context }) => {
|
|
await signIn(context);
|
|
await page.goto("/admin/pages");
|
|
await page.getByRole("link", { name: /^Home\b/ }).first().click();
|
|
await expect(page).toHaveURL(/\/admin\/pages\/[0-9a-f-]+$/);
|
|
await page.getByRole("button", { name: /^Top of the page/ }).click();
|
|
await page.getByLabel("Top of the page (hero): layout").selectOption("photo");
|
|
await expect(page.getByText("Video (plays muted, on a loop)")).toHaveCount(0);
|
|
await page.getByLabel("Top of the page (hero): layout").selectOption("video");
|
|
await expect(page.getByText("Still photo (shown before the video plays, and on phones)")).toBeVisible();
|
|
|
|
await page.getByRole("button", { name: "Choose", exact: true }).click();
|
|
const dialog = page.getByRole("dialog", { name: "Choose a video" });
|
|
await expect(dialog.getByText("No videos in your library yet")).toBeVisible();
|
|
await dialog.locator('input[type="file"]').setInputFiles({ name: "welcome.mp4", mimeType: "video/mp4", buffer: tinyMp4() });
|
|
await dialog.getByLabel("What the video shows").fill("People arriving on a Sunday");
|
|
await dialog.getByRole("button", { name: "Upload" }).click();
|
|
await expect(dialog).toHaveCount(0);
|
|
await page.getByRole("button", { name: "Save", exact: true }).click();
|
|
await expect(page.getByText("Saved as a draft.")).toBeVisible();
|
|
const preview = page.frameLocator('iframe[title="Live preview of this page"]');
|
|
await expect(preview.locator(".cc-section-hero video")).toHaveAttribute("src", /\.mp4$/);
|
|
|
|
// The library lists it with the photos; photo fields never offer it.
|
|
await page.goto("/admin/media");
|
|
await expect(page.locator("main li video")).toHaveCount(1);
|
|
});
|