Files
glenloch-media/e2e/events.spec.ts
T
bhursey fac9b96cca
CI / build (push) Has been cancelled
feat(events): show every photo on the event page without folders
Folders were an implementation detail leaking into the event workflow: every
upload needed a folder first and photos were split across pages. Uploads now
land in a single implicit "Photos" folder and the event page renders one
gallery with the uploader and an edited-only download.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-21 14:37:57 +00:00

191 lines
7.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect } from "@playwright/test";
import { readFile } from "node:fs/promises";
import { signInAs, resetDb, BASE } from "./dev";
/**
* Event photography (J/K slice): a coordinator creates an event and assigns two
* photographers; the first uploads a JPEG and a RAW original straight onto the
* event page; the second — not the uploader — downloads the untouched bytes.
* An unassigned volunteer cannot open the event at all.
*/
// A real 32×24 JPEG, so the editor path sees a normal browser image.
const PHOTO = Buffer.from(
"/9j/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAAYACADASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAcICf/EABgQAQADAQAAAAAAAAAAAAAAAAAXZaTi/8QAFQEBAQAAAAAAAAAAAAAAAAAACAf/xAAbEQEAAQUBAAAAAAAAAAAAAAAAAQMEFFKh0f/aAAwDAQACEQMRAD8AuYAvrq5kinQtc5eyFrnL2XmDca9j0ccyhtyW6ABDI5mQA6BNf//Z",
"base64",
);
const PHOTO_NAME = "photo.jpg";
const RAW = Buffer.from("II*\u0000fake-cr3-bytes-for-download-verification");
let eventUrl = "";
test.describe("event photo sharing", () => {
test.beforeAll(async ({ browser }) => {
const context = await browser.newContext();
const page = await context.newPage();
await resetDb(page);
await context.close();
});
test("a coordinator creates an event and assigns two photographers", async ({
page,
}) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "admin@glenloch.local");
await page.goto(`${BASE}/events`);
await page.getByLabel("Title").fill("E2E photo day");
await page.getByLabel("Location").fill("Main campus");
await page.getByRole("button", { name: "Create event" }).click();
await expect(page).toHaveURL(/\/events\/[^/]+$/);
eventUrl = page.url().replace(/\/$/, "");
await expect(
page.getByRole("heading", { name: "E2E photo day" }),
).toBeVisible();
const teamMember = page.getByLabel("Team member");
await teamMember.selectOption({
label: "Avery Kim (avery@glenloch.local)",
});
await page.getByRole("button", { name: "Assign" }).click();
await expect(page.getByText("Avery Kim").first()).toBeVisible();
await teamMember.selectOption({ label: "Sam Okafor (sam@glenloch.local)" });
await page.getByRole("button", { name: "Assign" }).click();
await expect(page.getByText("Sam Okafor").first()).toBeVisible();
});
test("an assigned photographer uploads files on the event page", async ({
page,
}) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "avery@glenloch.local");
await page.goto(eventUrl);
await page.getByLabel("Choose photos to upload").setInputFiles([
{ name: PHOTO_NAME, mimeType: "image/jpeg", buffer: PHOTO },
{ name: "raw.CR3", mimeType: "application/octet-stream", buffer: RAW },
]);
await page.getByRole("button", { name: "Upload 2" }).click();
await expect(page.getByText("2 uploaded")).toBeVisible({ timeout: 30_000 });
await expect(page.getByText(PHOTO_NAME)).toBeVisible();
await expect(page.getByText("raw.CR3")).toBeVisible();
});
test("another assigned photographer downloads the original bytes", async ({
page,
}) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "sam@glenloch.local");
await page.goto(eventUrl);
const [download] = await Promise.all([
page.waitForEvent("download"),
page.getByRole("link", { name: "Download", exact: true }).first().click(),
]);
const downloadPath = await download.path();
expect(downloadPath).toBeTruthy();
const bytes = await readFile(downloadPath!);
expect(bytes.equals(PHOTO)).toBe(true);
});
test("a photographer downloads every photo as one ZIP", async ({ page }) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "sam@glenloch.local");
await page.goto(eventUrl);
const [download] = await Promise.all([
page.waitForEvent("download"),
page.getByRole("link", { name: /Download all \(2\)/ }).click(),
]);
expect(download.suggestedFilename()).toBe("E2E photo day photos.zip");
const downloadPath = await download.path();
expect(downloadPath).toBeTruthy();
const zip = await readFile(downloadPath!);
expect(zip.subarray(0, 4).toString("binary")).toBe("PK\x03\x04");
// Store-only entries keep the original bytes; uploads share one folder.
expect(zip.includes(PHOTO)).toBe(true);
expect(zip.includes(RAW)).toBe(true);
expect(zip.includes(Buffer.from(`Photos/${PHOTO_NAME}`))).toBe(true);
expect(zip.includes(Buffer.from("Photos/raw.CR3"))).toBe(true);
});
test("a photographer views a photo and saves a full-resolution edited JPEG", async ({
page,
}) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "sam@glenloch.local");
await page.goto(eventUrl);
await page
.getByRole("button", { name: `View and edit ${PHOTO_NAME}` })
.click();
await expect(page.getByRole("dialog")).toBeVisible();
await expect(page.getByRole("heading", { name: "Edit photo" })).toBeVisible();
await page.getByLabel("Exposure").focus();
await page.getByLabel("Exposure").press("ArrowRight");
await page.getByRole("button", { name: "Save edited JPEG" }).click();
await expect(page.getByText("Full-resolution JPEG saved.")).toBeVisible({
timeout: 30_000,
});
const [download] = await Promise.all([
page.waitForEvent("download"),
page.getByRole("link", { name: "Download edited JPEG" }).click(),
]);
expect(download.suggestedFilename()).toBe("photo-edited.jpg");
const edited = await readFile((await download.path())!);
expect(edited.subarray(0, 3).toString("hex")).toBe("ffd8ff");
expect(edited.equals(PHOTO)).toBe(false);
await page.getByRole("button", { name: "Close photo editor" }).click();
await expect(page.getByText("Edited", { exact: true })).toBeVisible();
await expect(page.locator(`img[alt="${PHOTO_NAME}"]`)).toHaveAttribute(
"src",
/variant=edited/,
);
// The event-wide ZIP now carries the generated JPEG beside its original.
await page.goto(eventUrl);
const [zipDownload] = await Promise.all([
page.waitForEvent("download"),
page.getByRole("link", { name: /Download all \(2\)/ }).click(),
]);
const zip = await readFile((await zipDownload.path())!);
expect(zip.includes(edited)).toBe(true);
expect(zip.includes(Buffer.from("Photos/photo-edited.jpg"))).toBe(true);
});
test("an unassigned volunteer cannot open the event", async ({ page }) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "jordan@glenloch.local");
const response = await page.goto(eventUrl);
expect(response?.status()).toBe(404);
});
test("a manager deletes the event and its photos", async ({ page }) => {
await page.setViewportSize({ width: 1200, height: 900 });
await signInAs(page, "admin@glenloch.local");
await page.goto(eventUrl);
const photoHref = await page
.getByRole("link", { name: "Download", exact: true })
.first()
.getAttribute("href");
expect(photoHref).toBeTruthy();
await page.goto(eventUrl);
page.once("dialog", (dialog) => dialog.accept());
await page.getByRole("button", { name: "Delete event" }).click();
await expect(page).toHaveURL(`${BASE}/events`);
const gone = await page.goto(eventUrl);
expect(gone?.status()).toBe(404);
const photoGone = await page.request.get(`${BASE}${photoHref}`);
expect(photoGone.status()).toBe(404);
});
});