Website 1.7.1: move and zoom for ministries', leaders' and events' photos

1.7.0 had Move and zoom in page sections only. Ministries, Leadership
and Events now have it on their photo, in the frame the site uses for
the current template and layouts. Saved with the row as `framing`
({ x, y, zoom }, null for centred; cleared when the photo changes).
Ministries and leaders are drafts until Publish (snapshot, Discard and
Restore carry it); an event's shows once the event is published.
Versions published before this compare unchanged.

One migration: a nullable JSONB `framing` column on Ministry, Leader
and SimpleEvent.

Also: the 1.7.0 e2e test waits for the media library to load before
counting it (it could count an empty list).

Checked: Website backend tests (136) and typecheck, frontend typecheck
and lint, production build, admin e2e suite in Chromium (12).
Lighthouse not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 00:27:54 +02:00
co-authored by Claude Opus 5.5
parent 4897489fb1
commit 0c521ff614
23 changed files with 212 additions and 40 deletions
+36
View File
@@ -226,3 +226,39 @@ describe('uploads and storage (§10, decision 12)', () => {
assert.equal((await as.get('/media')).body.storage.full, true);
});
});
describe('move and zoom for ministries, leaders and events', () => {
it('saves framing with the row, publishes it onto the photo, drops it with the photo, and leaves old versions unchanged', async () => {
const { as, app } = await signedIn('editor');
// Published before framing existed: nothing shows as changed.
assert.deepEqual((await as.get('/changes')).body, []);
const focus = { x: 20, y: 70, zoom: 1.6 };
const m = ((await as.get('/ministries')).body as { id: string; name: string; imageId: string; updatedAt: string }[])[0]!;
assert.ok(m.imageId);
assert.equal((await as.put(`/ministries/${m.id}`, { name: m.name, imageId: m.imageId, framing: focus })).status, 200);
assert.equal((await as.put(`/ministries/${m.id}`, { name: m.name, imageId: m.imageId, framing: { x: 200, y: 0, zoom: 1 } })).status, 400);
const l = ((await as.get('/leaders')).body as { id: string; name: string; photoId: string }[])[0]!;
assert.equal((await as.put(`/leaders/${l.id}`, { name: l.name, photoId: l.photoId, framing: focus })).status, 200);
assert.deepEqual(((await as.get('/leaders')).body as { id: string; framing: unknown }[]).find((x) => x.id === l.id)!.framing, focus);
assert.deepEqual((await as.get('/changes')).body.map((c: { what: string }) => c.what).sort(), ['leader', 'ministry']);
assert.equal((await as.post('/publish')).status, 200);
const site = (await request(app).get('/api/v1/site/content')).body;
assert.deepEqual(site.snapshot.ministries.find((x: { name: string }) => x.name === m.name).image.focus, focus);
assert.deepEqual(site.snapshot.leaders.find((x: { name: string }) => x.name === l.name).photo.focus, focus);
// Discard puts the published framing back; a photo removed takes its framing with it.
await as.put(`/leaders/${l.id}`, { name: l.name, photoId: null, framing: focus });
assert.equal(((await as.get('/leaders')).body as { id: string; framing: unknown }[]).find((x) => x.id === l.id)!.framing, null);
assert.equal((await as.post('/discard', { key: `leader:${l.id}` })).status, 200);
assert.deepEqual(((await as.get('/leaders')).body as { id: string; framing: unknown }[]).find((x) => x.id === l.id)!.framing, focus);
// Events: saved with the event, shown on the live site straight away once published.
const e = ((await as.get('/events')).body as { id: string; title: string; startsAt: string; endsAt: string | null; imageId: string | null }[]).find((x) => x.imageId)!;
assert.equal((await as.put(`/events/${e.id}`, { title: e.title, startsAt: e.startsAt, endsAt: e.endsAt, imageId: e.imageId, framing: focus })).status, 200);
assert.deepEqual(((await as.get('/events')).body as { id: string; framing: unknown }[]).find((x) => x.id === e.id)!.framing, focus);
const live = (await request(app).get('/api/v1/site/content')).body;
assert.deepEqual(live.events.find((x: { title: string }) => x.title === e.title).image.focus, focus);
});
});
@@ -9,13 +9,13 @@ import crypto from 'node:crypto';
type Row = Record<string, unknown>;
const DEFAULTS: Record<string, () => Row> = {
ministry: () => ({ summary: null, body: null, imageId: null, position: 0, archivedAt: null, updatedBy: null }),
leader: () => ({ role: null, bio: null, photoId: null, position: 0, archivedAt: null, updatedBy: null }),
ministry: () => ({ summary: null, body: null, imageId: null, framing: null, position: 0, archivedAt: null, updatedBy: null }),
leader: () => ({ role: null, bio: null, photoId: null, framing: null, position: 0, archivedAt: null, updatedBy: null }),
messageSeries: () => ({ summary: null, imageId: null }),
page: () => ({ seoTitle: null, description: null, navLabel: null, inNav: true, position: 0, imageId: null, archivedAt: null, updatedBy: null }),
section: () => ({ variant: null, position: 0, hidden: false, updatedBy: null }),
message: () => ({ externalId: null, thumbnailUrl: null, speaker: null, passage: null, notes: null, seriesId: null, hidden: false, publishedAt: null, updatedBy: null }),
simpleEvent: () => ({ endsAt: null, allDay: false, timezone: 'Africa/Johannesburg', location: null, description: null, imageId: null, link: null, cancelled: false, publishedAt: null, updatedBy: null }),
simpleEvent: () => ({ endsAt: null, allDay: false, timezone: 'Africa/Johannesburg', location: null, description: null, imageId: null, framing: null, link: null, cancelled: false, publishedAt: null, updatedBy: null }),
mediaAsset: () => ({ width: null, height: null, alt: '', sizes: null, uploadedBy: null }),
siteVersion: () => ({ note: null }),
websiteUser: () => ({ ministryId: null, lastSignInAt: null }),
@@ -66,7 +66,9 @@ export function matches(row: Row, where: Row = {}): boolean {
});
}
const clone = <T>(x: T): T => structuredClone(x);
/** Prisma.DbNull / JsonNull (a nullable Json field set to null) are stored as null, as Postgres does. */
const nulls = (x: unknown) => (x && typeof x === 'object' && /^(Db|Json)Null$/.test(x.constructor?.name ?? '') ? null : x);
const clone = <T>(x: T): T => structuredClone(x && typeof x === 'object' && !Array.isArray(x) && !(x instanceof Date) ? Object.fromEntries(Object.entries(x).map(([k, y]) => [k, nulls(y)])) as T : x);
const pick = (row: Row, select?: Row) => (select ? Object.fromEntries(Object.keys(select).filter((k) => select[k]).map((k) => [k, row[k]])) : row);
function order(rows: Row[], orderBy?: Row | Row[]) {