Files
glenloch-media/e2e/training.spec.ts
T
2026-11-20 04:07:02 +00:00

78 lines
2.5 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("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("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();
});
});