160 lines
8.3 KiB
TypeScript
160 lines
8.3 KiB
TypeScript
import { expect, test, type Browser, type Page } from "@playwright/test";
|
|
import { passkey } from "./hilfen";
|
|
|
|
// Kinderkonten (Paket 5b): Kai legt Ben an und schaltet ein Tablet frei. Auf
|
|
// dem Tablet meldet sich Ben mit Bild und PIN an, sieht nur Heute und Wünschen.
|
|
// Ohne freigeschaltetes Gerät gibt es keine Kinderanmeldung.
|
|
test.describe.configure({ mode: "serial" });
|
|
|
|
let tablet: Page;
|
|
|
|
async function freshPage(browser: Browser): Promise<Page> {
|
|
const context = await browser.newContext({ ...test.info().project.use, storageState: undefined });
|
|
return context.newPage();
|
|
}
|
|
|
|
async function enterPin(page: Page, pin: string) {
|
|
for (const d of pin) await page.getByRole("group", { name: "PIN eingeben" }).getByRole("button", { name: d, exact: true }).click();
|
|
}
|
|
|
|
test("an admin adds a child and unlocks a tablet with a one-time link", async ({ page, browser }) => {
|
|
await page.goto("/mehr");
|
|
await page.fill("#kid-name", "Ben");
|
|
await page.getByRole("radio", { name: "Hund" }).check({ force: true });
|
|
await page.fill("#kid-pin", "1234");
|
|
await page.getByRole("button", { name: "Kind hinzufügen" }).click();
|
|
await expect(page.getByRole("status")).toHaveText("Ben ist dabei.");
|
|
await page.fill("#device-label-kids", "Küchentablet");
|
|
await page.locator("#kindergeraete").getByRole("button", { name: "Link zum Freischalten erstellen" }).click();
|
|
const url = await page.locator("#kindergeraete").getByRole("textbox", { name: "Link" }).inputValue();
|
|
expect(url).toContain("/kindergeraet/");
|
|
|
|
tablet = await freshPage(browser);
|
|
await tablet.goto(url);
|
|
await expect(tablet.getByRole("heading", { level: 1 })).toHaveText("„Küchentablet“ freischalten");
|
|
await tablet.getByRole("button", { name: "Dieses Gerät freischalten" }).click();
|
|
await expect(tablet).toHaveURL(/\/kinder$/);
|
|
await expect(tablet.getByRole("button", { name: "Ben" })).toBeVisible();
|
|
|
|
// Der Link gilt genau einmal.
|
|
const other = await freshPage(browser);
|
|
await other.goto(url);
|
|
await expect(other.getByRole("heading", { level: 1 })).toHaveText("Link abgelaufen");
|
|
});
|
|
|
|
test("a child signs in with picture and PIN and sees only Today and Wish", async () => {
|
|
await tablet.getByRole("button", { name: "Ben" }).click();
|
|
await enterPin(tablet, "0000");
|
|
await expect(tablet.locator("main [role=alert]")).toContainText("PIN stimmt nicht");
|
|
await enterPin(tablet, "1234");
|
|
await expect(tablet.getByRole("heading", { level: 1 })).toHaveText("Hallo Ben");
|
|
const nav = tablet.getByRole("navigation", { name: "Navigation" });
|
|
await expect(nav.getByRole("link")).toHaveText(["Heute", "Wünschen"]);
|
|
await expect(nav.getByRole("button", { name: "Wechseln" })).toBeVisible();
|
|
for (const path of ["/gerichte", "/mehr", "/runde/neu", "/gerichte/neu", "/plan", "/einkauf"]) {
|
|
await tablet.goto(path);
|
|
await expect(tablet).toHaveURL(/\/$/);
|
|
}
|
|
});
|
|
|
|
test("a child wishes, makes a favourite, and has no veto", async () => {
|
|
await tablet.goto("/wuenschen");
|
|
// Vetos der anderen sieht Ben, aber nicht von wem (26.11.30: keine Bühne zum Ärgern).
|
|
await expect(tablet.getByText("1 Veto", { exact: true })).toBeVisible();
|
|
await expect(tablet.getByText("Veto: Kai")).toHaveCount(0);
|
|
await expect(tablet.getByText(/Veto(s)? frei|Veto vergeben/)).toHaveCount(0); // ein eigenes hat Ben nicht
|
|
await tablet.getByRole("button", { name: /^Wünschen: Spaghetti Bolognese/ }).click();
|
|
await expect(tablet.getByRole("button", { name: /^Wunsch zurücknehmen: Spaghetti Bolognese/ })).toContainText("Favorit");
|
|
await tablet.getByRole("button", { name: "Optionen für Linseneintopf" }).click();
|
|
await expect(tablet.getByRole("dialog").getByRole("button", { name: /Veto/ })).toHaveCount(0);
|
|
await tablet.keyboard.press("Escape");
|
|
});
|
|
|
|
test("a child makes a wish their own dish, sure to be in the plan", async () => {
|
|
await tablet.goto("/wuenschen");
|
|
await expect(tablet.getByText("Tipp aufs Herz")).toBeVisible();
|
|
await tablet.getByRole("button", { name: "Spaghetti Bolognese als mein Gericht" }).click();
|
|
await expect(tablet.getByRole("button", { name: "Spaghetti Bolognese nicht mehr mein Gericht" })).toHaveAttribute("aria-pressed", "true");
|
|
await expect(tablet.getByText("Dein Gericht: Spaghetti Bolognese — kommt sicher in den Plan.")).toBeVisible();
|
|
await expect(tablet.getByRole("button", { name: /^Wunsch zurücknehmen: Spaghetti Bolognese/ })).toContainText("Mein Gericht");
|
|
});
|
|
|
|
test("switching leads back to the pictures, and wrong PINs are slowed down", async () => {
|
|
await tablet.getByRole("button", { name: "Wechseln" }).click();
|
|
await expect(tablet).toHaveURL(/\/kinder$/);
|
|
await tablet.getByRole("button", { name: "Ben" }).click();
|
|
for (let i = 0; i < 6; i++) await enterPin(tablet, "9999");
|
|
await expect(tablet.locator("main [role=alert]")).toContainText("Zu viele Versuche");
|
|
});
|
|
|
|
test("without an unlocked device there is no child sign-in", async ({ browser }) => {
|
|
const page = await freshPage(browser);
|
|
await page.goto("/kinder");
|
|
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Kein Kindergerät");
|
|
const res = await page.request.post("/api/auth/kids/login", {
|
|
data: { memberId: "00000000-0000-0000-0000-000000000000", pin: "1234" },
|
|
headers: { origin: new URL(page.url()).origin },
|
|
});
|
|
expect(res.status()).toBe(403);
|
|
});
|
|
|
|
test("removing the device ends it", async ({ page }) => {
|
|
await page.goto("/mehr");
|
|
await page.getByRole("button", { name: "Küchentablet entfernen" }).click();
|
|
await expect(page.getByRole("button", { name: "Küchentablet entfernen" })).toHaveCount(0);
|
|
await tablet.goto("/kinder");
|
|
await expect(tablet.getByRole("heading", { level: 1 })).toHaveText("Kein Kindergerät");
|
|
});
|
|
|
|
test("older children get pictures and initials instead of animals", async ({ page }) => {
|
|
await page.goto("/mehr");
|
|
await page.getByRole("button", { name: "Bild oder PIN von Ben ändern" }).click();
|
|
const ben = page.locator("form").filter({ hasText: "Neue PIN für Ben" });
|
|
await ben.getByRole("radio", { name: "Initialen" }).check({ force: true });
|
|
await ben.getByRole("button", { name: "Speichern" }).click();
|
|
await expect(page.getByRole("status")).toHaveText("Ben ist geändert.");
|
|
await expect(page.locator("li", { hasText: "Ben" }).locator("svg text")).toHaveText("B");
|
|
});
|
|
|
|
test("a teen joins with an own passkey and wishes, but does not plan", async ({ page, browser }) => {
|
|
await page.goto("/mehr");
|
|
await page.fill("#invite-name", "Lena");
|
|
await page.getByRole("radio", { name: /Jugendlich/ }).check();
|
|
await page.getByRole("button", { name: "Link erstellen" }).first().click();
|
|
const link = await page.locator("input[readonly]").inputValue();
|
|
|
|
const context = await browser.newContext({ ...test.info().project.use, storageState: undefined });
|
|
const lena = await context.newPage();
|
|
await passkey(context, lena);
|
|
await lena.goto(link);
|
|
await lena.getByRole("button", { name: "Passkey anlegen" }).click();
|
|
await expect(lena.getByRole("heading", { level: 1 })).toHaveText("Hallo Lena");
|
|
await lena.getByRole("button", { name: "Überspringen" }).click();
|
|
// „Wo stehen wir?“: die Runde ist beim Wünschen, und Lena hat noch Jetons.
|
|
await expect(lena.locator('[aria-current="step"]')).toContainText("Wünschen");
|
|
await expect(lena.getByText("Du hast noch 2 Wünsche.")).toBeVisible();
|
|
const nav = lena.getByRole("navigation", { name: "Navigation" });
|
|
await expect(nav.getByRole("link")).toHaveText(["Heute", "Wünschen", "Einkauf", "Gerichte", "Mehr"]);
|
|
for (const path of ["/plan", "/runde/neu"]) {
|
|
await lena.goto(path);
|
|
await expect(lena).toHaveURL(/\/$/);
|
|
}
|
|
await lena.goto("/gerichte/neu");
|
|
await expect(lena).toHaveURL(/\/gerichte$/);
|
|
|
|
// Jugendliche haben ein Veto (Kinder nicht) — hier nur angeboten, nicht vergeben.
|
|
await lena.goto("/wuenschen");
|
|
await lena.getByRole("button", { name: "Optionen für Linseneintopf" }).click();
|
|
await expect(lena.getByRole("dialog").getByRole("button", { name: /Veto/ })).toBeVisible();
|
|
await lena.keyboard.press("Escape");
|
|
// Gegen Bens Gericht gibt es kein Veto.
|
|
await lena.getByRole("button", { name: "Optionen für Spaghetti Bolognese" }).click();
|
|
await expect(lena.getByRole("dialog")).toContainText("Geschützt");
|
|
await expect(lena.getByRole("dialog").getByRole("button", { name: /Veto/ })).toHaveCount(0);
|
|
await lena.keyboard.press("Escape");
|
|
|
|
await page.goto("/mehr");
|
|
await expect(page.locator("main")).toContainText(/Lena\s*Jugendlich/);
|
|
await context.close();
|
|
});
|