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:
@@ -4,6 +4,7 @@ import request from 'supertest';
|
||||
import { hashToken } from '../src/lib/crypto.js';
|
||||
import { previewContent, siteContent } from '../src/site/content.js';
|
||||
import { publish } from '../src/site/snapshot.js';
|
||||
import { changes, discard } from '../src/site/workingCopy.js';
|
||||
import { harness, SITE } from './support/harness.js';
|
||||
|
||||
async function site() {
|
||||
@@ -85,3 +86,42 @@ describe('an address that changed (§6)', () => {
|
||||
assert.deepEqual(after.mode === 'published' && after.snapshot.redirects, { 'youth-camp': '/summer-camp' });
|
||||
});
|
||||
});
|
||||
|
||||
describe("a block's layout and background", () => {
|
||||
it('saves one of its own layouts and a background from the church\'s colours, previews them, and discards them', async () => {
|
||||
const { ctx, db, as } = await site();
|
||||
const page = await db.page.create({ data: { kind: 'custom', slug: 'join', title: 'Join us' } });
|
||||
const block = await db.section.create({ data: { pageId: page.id, type: 'cta', data: { heading: 'Come along', text: null, button: null } } });
|
||||
await db.section.create({ data: { pageId: page.id, type: 'text', variant: 'something-old', data: { heading: null, body: 'Hi' } } });
|
||||
await publish(ctx, { id: 'x', role: 'system' });
|
||||
|
||||
// Drawn with its type's default until it has a layout; an id it doesn't know is drawn so too.
|
||||
const shown = async () => {
|
||||
const c = await previewContent(ctx);
|
||||
assert.ok(c.mode === 'published');
|
||||
return c.snapshot.pages.find((p) => p.slug === 'join')!.sections.map((s) => ({ type: s.type, variant: s.variant, background: s.background }));
|
||||
};
|
||||
assert.deepEqual(await shown(), [{ type: 'cta', variant: 'centred', background: undefined }, { type: 'text', variant: 'standard', background: undefined }]);
|
||||
|
||||
const put = (b: object) => as('ann')('put', `/pages/${page.id}/blocks/${block.id}`, b);
|
||||
assert.equal((await put({ variant: 'banner' })).status, 200);
|
||||
assert.equal((await put({ background: 'dark' })).status, 200);
|
||||
const wrong = await put({ variant: 'image-left' });
|
||||
assert.equal(wrong.status, 400);
|
||||
assert.match(wrong.body.error.message, /isn't a layout of this block/);
|
||||
assert.equal((await put({ background: 'pink' })).status, 400);
|
||||
assert.deepEqual((await shown())[0], { type: 'cta', variant: 'banner', background: 'dark' });
|
||||
|
||||
// A change like any other: listed, and discarded back to what's published.
|
||||
const pending = (await changes(ctx)).find((c) => c.key === `page:${page.id}`);
|
||||
assert.ok(pending);
|
||||
await discard(ctx, `page:${page.id}`, { id: 'x', role: 'editor' });
|
||||
const back = await db.section.findUnique({ where: { id: block.id } });
|
||||
assert.equal(back?.background, null);
|
||||
assert.equal(back?.variant, null);
|
||||
// Back to null follows the style again.
|
||||
assert.equal((await put({ background: 'tint' })).status, 200);
|
||||
assert.equal((await put({ background: null })).status, 200);
|
||||
assert.equal((await shown())[0]!.background, undefined);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user