website 1.11.0: layouts and backgrounds for the blocks; a video for the top of the page
- 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>
This commit is contained in:
@@ -274,7 +274,6 @@ test("on the home page: each section's layout, background, place and showing, an
|
||||
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");
|
||||
await page.screenshot({ path: "e2e/test-results/home-sections.png", fullPage: true });
|
||||
|
||||
// Hide it, show it, and move it.
|
||||
await page.getByRole("button", { name: "Hide Welcome" }).click();
|
||||
@@ -293,3 +292,76 @@ test("on the home page: each section's layout, background, place and showing, an
|
||||
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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user