8601a6014f
Authors can now attach a caption to an image in the lesson editor; it is sanitized as figure text and follows the image's alignment in the reader. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
141 lines
5.1 KiB
TypeScript
141 lines
5.1 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
||
import { signInAs, resetDb, BASE } from "./dev";
|
||
|
||
/**
|
||
* Training authoring (F2): create a lesson, publish it, upload an attachment,
|
||
* and confirm a volunteer sees the content without authoring controls.
|
||
*/
|
||
|
||
let lessonTitle: string;
|
||
let lessonId: string;
|
||
|
||
test.describe.configure({ mode: "serial" });
|
||
|
||
test.describe("training", () => {
|
||
test.beforeAll(async ({ browser }) => {
|
||
const context = await browser.newContext();
|
||
const page = await context.newPage();
|
||
await resetDb(page);
|
||
await context.close();
|
||
});
|
||
|
||
test("admin authors a lesson and uploads an attachment", async ({ page }) => {
|
||
await page.setViewportSize({ width: 1024, height: 900 });
|
||
await signInAs(page, "admin@glenloch.local");
|
||
await page.goto(`${BASE}/training`);
|
||
|
||
// Seeded starter content is visible.
|
||
await expect(page.getByRole("heading", { name: "Audio team basics" })).toBeVisible();
|
||
|
||
lessonTitle = `E2E lesson ${Date.now()}`;
|
||
await page.getByLabel("Title").fill(lessonTitle);
|
||
await page.getByLabel("Summary").fill("Created from the admin UI");
|
||
await page.getByLabel("Content").fill("Step one\nStep two");
|
||
await page.getByRole("button", { name: "Create lesson" }).click();
|
||
|
||
await expect(
|
||
page.getByRole("heading", { name: lessonTitle }),
|
||
).toBeVisible();
|
||
|
||
const list = (await (
|
||
await page.request.get(`${BASE}/api/dev/training/lessons`)
|
||
).json()) as { lessons: { id: string; title: string }[] };
|
||
lessonId = list.lessons.find((lesson) => lesson.title === lessonTitle)!.id;
|
||
|
||
const upload = await page.request.post(
|
||
`${BASE}/api/dev/training/resources`,
|
||
{
|
||
multipart: {
|
||
lessonId,
|
||
file: {
|
||
name: "guide.txt",
|
||
mimeType: "text/plain",
|
||
buffer: Buffer.from("hello from the upload test"),
|
||
},
|
||
},
|
||
},
|
||
);
|
||
expect(upload.status(), "upload should be accepted").toBe(201);
|
||
|
||
await page.reload();
|
||
await expect(page.getByRole("link", { name: "guide.txt" })).toBeVisible();
|
||
});
|
||
|
||
test("admin adds a rich image and a PDF manual", async ({ page }) => {
|
||
await page.setViewportSize({ width: 1024, height: 900 });
|
||
await signInAs(page, "admin@glenloch.local");
|
||
await page.goto(`${BASE}/training`);
|
||
|
||
const lesson = page
|
||
.locator("li")
|
||
.filter({ has: page.getByRole("heading", { name: lessonTitle }) })
|
||
.first();
|
||
await lesson.getByRole("button", { name: "Edit" }).click();
|
||
|
||
// 1×1 PNG, but the upload route only needs a valid PNG signature here.
|
||
const png = Buffer.from(
|
||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9Z7ZkAAAAASUVORK5CYII=",
|
||
"base64",
|
||
);
|
||
await page
|
||
.getByLabel("Upload an image for the lesson")
|
||
.setInputFiles({ name: "console.png", mimeType: "image/png", buffer: png });
|
||
|
||
const image = page.getByRole("img", { name: "console.png" });
|
||
await expect(image).toBeVisible();
|
||
await image.click();
|
||
await expect(
|
||
page.getByRole("toolbar", { name: "Selected image" }),
|
||
).toBeVisible();
|
||
await page.getByRole("button", { name: "Align image right" }).click();
|
||
await page
|
||
.getByRole("button", { name: "Set image width to 50%" })
|
||
.click();
|
||
page.once("dialog", (dialog) => dialog.accept("Front-of-house console"));
|
||
await page.getByRole("button", { name: "Add image caption" }).click();
|
||
await page.getByRole("button", { name: "Save lesson" }).click();
|
||
|
||
await expect(
|
||
lesson.locator('img[data-align="right"][width="50%"]'),
|
||
).toBeVisible();
|
||
await expect(lesson.locator("figcaption")).toHaveText(
|
||
"Front-of-house console",
|
||
);
|
||
|
||
const pdf = Buffer.from("%PDF-1.7\n% E2E manual\n");
|
||
await lesson
|
||
.getByLabel("Attach a manual or document")
|
||
.setInputFiles({ name: "audio-manual.pdf", mimeType: "application/pdf", buffer: pdf });
|
||
await lesson.getByRole("button", { name: "Attach", exact: true }).click();
|
||
|
||
const manual = lesson.getByRole("link", { name: "audio-manual.pdf" });
|
||
await expect(manual).toBeVisible();
|
||
const href = await manual.getAttribute("href");
|
||
expect(href).toBeTruthy();
|
||
const download = await page.request.get(`${BASE}${href}`);
|
||
expect(download.status()).toBe(200);
|
||
expect(download.headers()["content-disposition"]).toContain("inline");
|
||
});
|
||
|
||
test("volunteer sees published lessons but no authoring controls", async ({
|
||
page,
|
||
}) => {
|
||
await page.setViewportSize({ width: 1024, height: 900 });
|
||
await signInAs(page, "avery@glenloch.local");
|
||
await page.goto(`${BASE}/training`);
|
||
|
||
await expect(
|
||
page.getByRole("heading", { name: lessonTitle }),
|
||
).toBeVisible();
|
||
await expect(
|
||
page.getByRole("button", { name: "Create lesson" }),
|
||
).toHaveCount(0);
|
||
await expect(page.getByRole("link", { name: "guide.txt" })).toBeVisible();
|
||
await expect(page.getByRole("img", { name: "console.png" })).toBeVisible();
|
||
await expect(page.getByText("Front-of-house console")).toBeVisible();
|
||
await expect(
|
||
page.getByRole("link", { name: "audio-manual.pdf" }),
|
||
).toBeVisible();
|
||
});
|
||
});
|