feat(training): rich-text lessons with inline images and 25 MB manuals
CI / build (push) Has been cancelled
CI / build (push) Has been cancelled
Admins were authoring plain-text lessons, which made illustrated tutorials and reordering images impossible. Lesson bodies are now sanitized HTML from a Tiptap editor with alignment, sizing, drag-reorder and alt text, and inline images reuse the training_resources table so no migration is needed. Attachments grow to 25 MB, PDFs stream inline, and SVG is rejected because it can execute as a document. Legacy plain-text bodies are normalized on read. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -9,6 +9,8 @@ import { signInAs, resetDb, BASE } from "./dev";
|
||||
let lessonTitle: string;
|
||||
let lessonId: string;
|
||||
|
||||
test.describe.configure({ mode: "serial" });
|
||||
|
||||
test.describe("training", () => {
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
const context = await browser.newContext();
|
||||
@@ -59,6 +61,57 @@ test.describe("training", () => {
|
||||
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();
|
||||
await page.getByRole("button", { name: "Save lesson" }).click();
|
||||
|
||||
await expect(
|
||||
lesson.locator('img[data-align="right"][width="50%"]'),
|
||||
).toBeVisible();
|
||||
|
||||
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,
|
||||
}) => {
|
||||
@@ -73,5 +126,9 @@ test.describe("training", () => {
|
||||
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.getByRole("link", { name: "audio-manual.pdf" }),
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user