651 lines
38 KiB
TypeScript
651 lines
38 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
||
import sharp from "sharp";
|
||
|
||
// Gerichte am iPhone: Pool leer, Klassiker übernehmen, Portionen hochrechnen,
|
||
// eigenes Gericht anlegen und ändern, Foto, entfernen mit Rückgängig.
|
||
// Läuft nach dem Ablauf mit Kais Sitzung.
|
||
test.describe.configure({ mode: "serial" });
|
||
|
||
test("an empty pool says what to do and offers the main action", async ({ page }) => {
|
||
await page.goto("/gerichte");
|
||
await expect(page.getByRole("heading", { level: 2, name: "Noch keine Gerichte" })).toBeVisible();
|
||
await page.getByRole("link", { name: "Gericht hinzufügen" }).click();
|
||
await expect(page).toHaveURL(/\/gerichte\/hinzufuegen$/);
|
||
});
|
||
|
||
test("adopting three classics fills the pool", async ({ page }) => {
|
||
await page.goto("/gerichte/vorlagen");
|
||
for (const title of ["Spaghetti Bolognese", "Linseneintopf", "Flammkuchen"]) await page.getByRole("button", { name: new RegExp(title) }).click();
|
||
await page.getByRole("button", { name: "3 Gerichte übernehmen" }).click();
|
||
await expect(page).toHaveURL(/\/gerichte$/);
|
||
await expect(page.getByRole("link", { name: /Spaghetti Bolognese/ })).toBeVisible();
|
||
await expect(page.locator("main li")).toHaveCount(3);
|
||
await page.goto("/gerichte/vorlagen");
|
||
await expect(page.getByRole("button", { name: /Linseneintopf/ })).toBeDisabled();
|
||
// „Los geht's“ zählt mit.
|
||
await page.goto("/");
|
||
await expect(page.getByText("Erste Gerichte · 3 / 5")).toBeVisible();
|
||
});
|
||
|
||
test("a dish scales its ingredients with the portions", async ({ page }) => {
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: /Spaghetti Bolognese/ }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Spaghetti Bolognese");
|
||
const spaghetti = page.locator("li", { hasText: "Spaghetti" }).first();
|
||
await expect(spaghetti).toContainText("250 g");
|
||
// Stück in Einzahl und Mehrzahl, je nach Menge.
|
||
const garlic = page.locator("li", { hasText: "Knoblauch" }).first();
|
||
await expect(page.locator("li", { hasText: "Zwiebel" }).first()).toContainText("½Zwiebel");
|
||
await expect(garlic).toContainText("1Knoblauchzehe");
|
||
await page.getByRole("button", { name: "Eine Portion mehr" }).click();
|
||
await page.getByRole("button", { name: "Eine Portion mehr" }).click();
|
||
await expect(page.locator("output")).toHaveText("4 Portionen");
|
||
await expect(spaghetti).toContainText("500 g");
|
||
await expect(garlic).toContainText("2Knoblauchzehen");
|
||
await expect(page.locator("li", { hasText: "Zwiebel" }).first()).toContainText("1Zwiebel");
|
||
});
|
||
|
||
test("an own dish is created with searched ingredients, then edited", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Gemüsecurry");
|
||
await page.fill("#effort", "35");
|
||
await page.getByRole("button", { name: "vegetarisch" }).click();
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Zwieb");
|
||
await page.getByRole("option", { name: "Zwiebeln", exact: true }).click();
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).first().fill("2");
|
||
await page.getByRole("button", { name: "Zutaten" }).click();
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).nth(1).fill("kokos");
|
||
await page.getByRole("option", { name: "Kokosmilch", exact: true }).click();
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).nth(1).fill("400");
|
||
await page.getByLabel("Schritt 1", { exact: true }).fill("Zwiebeln würfeln und anschwitzen.");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Gemüsecurry");
|
||
await expect(page.locator("main")).toContainText("vegetarisch");
|
||
// 2 Zwiebeln für 4 Portionen → 1 Zwiebel für 2 Portionen (Einzahl).
|
||
await expect(page.locator("ul li", { hasText: "Zwiebel" }).first()).toContainText(/^1\s*Zwiebel$/);
|
||
await expect(page.locator("ul li", { hasText: "Kokosmilch" }).first()).toContainText("200 ml");
|
||
// Einheitliche Form: Abschnitt als Überschrift, die Zutaten des Schritts mit Menge darunter.
|
||
await expect(page.getByRole("heading", { level: 3, name: "Kochen" })).toBeVisible();
|
||
await expect(page.locator("ol li", { hasText: "Zwiebeln würfeln und anschwitzen." })).toContainText("1 Zwiebel");
|
||
|
||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||
await expect(page.locator("#title")).toHaveValue("Gemüsecurry");
|
||
await page.fill("#title", "Gemüsecurry mit Reis");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Gemüsecurry mit Reis");
|
||
});
|
||
|
||
test("a photo from the phone becomes the dish photo", async ({ page }) => {
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: /Gemüsecurry/ }).click();
|
||
const png = await sharp({ create: { width: 1200, height: 900, channels: 3, background: { r: 230, g: 120, b: 90 } } }).png().toBuffer();
|
||
await page.locator("input[type=file]").setInputFiles({ name: "curry.png", mimeType: "image/png", buffer: png });
|
||
const img = page.locator("main img").first();
|
||
await expect(img).toHaveAttribute("src", /\/api\/fotos\//);
|
||
const res = await page.request.get((await img.getAttribute("src"))!);
|
||
expect(res.status()).toBe(200);
|
||
expect(res.headers()["content-type"]).toBe("image/webp");
|
||
});
|
||
|
||
test("up to five photos per dish, one of them the preview", async ({ page }) => {
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: /Gemüsecurry/ }).click();
|
||
const cover = page.locator("main img").first();
|
||
const first = await cover.getAttribute("src");
|
||
const colours = [
|
||
{ r: 40, g: 120, b: 200 },
|
||
{ r: 60, g: 180, b: 90 },
|
||
{ r: 200, g: 200, b: 40 },
|
||
{ r: 120, g: 40, b: 160 },
|
||
];
|
||
for (const [i, c] of colours.entries()) {
|
||
const png = await sharp({ create: { width: 800, height: 600, channels: 3, background: c } }).png().toBuffer();
|
||
await page.locator("input[type=file]").setInputFiles({ name: `bild-${i}.png`, mimeType: "image/png", buffer: png });
|
||
await expect(page.getByRole("heading", { name: `Fotos · ${i + 2} von 5` })).toBeVisible();
|
||
}
|
||
// Das erste bleibt Vorschau; bei fünf ist Schluss.
|
||
await expect(cover).toHaveAttribute("src", first!);
|
||
await expect(page.getByRole("button", { name: "5 Fotos sind das Maximum" })).toBeDisabled();
|
||
|
||
// Ein anderes Foto zur Vorschau machen: Seite und Pool zeigen es.
|
||
await page.getByRole("button", { name: "Foto 3 von Gemüsecurry mit Reis ansehen" }).click();
|
||
await page.getByRole("dialog").getByRole("button", { name: "Als Vorschau" }).click();
|
||
await expect(page.getByRole("button", { name: "Foto 3 von Gemüsecurry mit Reis ansehen (Vorschau)" })).toBeVisible();
|
||
await expect(cover).not.toHaveAttribute("src", first!);
|
||
const chosen = await cover.getAttribute("src");
|
||
|
||
// Die Vorschau entfernen: das erste Foto rückt nach.
|
||
await page.getByRole("button", { name: "Foto 3 von Gemüsecurry mit Reis ansehen (Vorschau)" }).click();
|
||
await page.getByRole("dialog").getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page.getByRole("heading", { name: "Fotos · 4 von 5" })).toBeVisible();
|
||
await expect(cover).toHaveAttribute("src", first!);
|
||
expect(chosen).not.toBe(first);
|
||
});
|
||
|
||
test("removing a dish offers undo instead of asking first", async ({ page }) => {
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: /Flammkuchen/ }).click();
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
await expect(page.getByRole("status")).toContainText("Flammkuchen");
|
||
await expect(page.getByRole("link", { name: /Flammkuchen/ })).toHaveCount(0);
|
||
await page.getByRole("button", { name: "Rückgängig" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Flammkuchen");
|
||
});
|
||
|
||
// Rezept-Link: eine Rezeptseite wie bei den Portalen, ausgeliefert von einem
|
||
// kleinen Server im Test. Die App darf ihn nur, weil IMPORT_TEST_ORIGIN genau
|
||
// diese Adresse nennt (lib/fetch-safe.ts); jede andere lokale Adresse lehnt sie ab.
|
||
test.describe("recipe link", () => {
|
||
let server: import("node:http").Server;
|
||
const origin = process.env.IMPORT_TEST_ORIGIN ?? "http://127.0.0.1:3021";
|
||
|
||
test.beforeAll(async () => {
|
||
const { createServer } = await import("node:http");
|
||
const jpg = await sharp({ create: { width: 800, height: 600, channels: 3, background: { r: 200, g: 160, b: 90 } } }).jpeg().toBuffer();
|
||
const recipe = {
|
||
"@context": "https://schema.org",
|
||
"@graph": [
|
||
{ "@type": "WebSite", name: "Testküche" },
|
||
{
|
||
"@type": "Recipe",
|
||
name: "Linsensuppe vom Blog",
|
||
recipeYield: "4 Portionen",
|
||
totalTime: "PT45M",
|
||
image: "/bild.jpg",
|
||
recipeIngredient: ["250 g rote Linsen", "2 Zwiebeln", "1 Becher Sahne", "2 EL Eier", "1 Handvoll Glück"],
|
||
recipeInstructions: [{ "@type": "HowToStep", text: "Zwiebeln anschwitzen." }, { "@type": "HowToStep", text: "Linsen dazu und weich kochen." }],
|
||
},
|
||
],
|
||
};
|
||
server = createServer((req, res) => {
|
||
if (req.url === "/bild.jpg") {
|
||
res.writeHead(200, { "content-type": "image/jpeg" }).end(jpg);
|
||
} else if (req.url === "/rezept") {
|
||
res.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end(
|
||
`<html><head><script type="application/ld+json">${JSON.stringify(recipe)}</script></head><body>Rezept</body></html>`,
|
||
);
|
||
} else {
|
||
res.writeHead(200, { "content-type": "text/html" }).end("<html><body>Kein Rezept</body></html>");
|
||
}
|
||
});
|
||
await new Promise<void>((done) => server.listen(Number(new URL(origin).port), "127.0.0.1", done));
|
||
});
|
||
test.afterAll(() => new Promise<void>((done) => server.close(() => done())));
|
||
|
||
test("a page without a recipe says so, a local address is refused", async ({ page }) => {
|
||
await page.goto("/gerichte/hinzufuegen");
|
||
await page.getByRole("link", { name: /Rezept-Link einfügen/ }).click();
|
||
await page.fill("#recipe-url", `${origin}/leer`);
|
||
await page.getByRole("button", { name: "Rezept holen" }).click();
|
||
await expect(page.locator("main [role=alert]")).toContainText("kein Rezept");
|
||
await page.fill("#recipe-url", "http://127.0.0.1:3020/gerichte");
|
||
await page.getByRole("button", { name: "Rezept holen" }).click();
|
||
await expect(page.locator("main [role=alert]")).toContainText("öffentlichen Link");
|
||
});
|
||
|
||
test("a recipe link becomes a draft, the person fills the gaps and saves", async ({ page }) => {
|
||
await page.goto("/gerichte/link");
|
||
await page.fill("#recipe-url", `${origin}/rezept`);
|
||
await page.getByRole("button", { name: "Rezept holen" }).click();
|
||
await expect(page.locator("#title")).toHaveValue("Linsensuppe vom Blog");
|
||
await expect(page.locator("#effort")).toHaveValue("45");
|
||
await expect(page.getByRole("note").filter({ hasText: "1 Handvoll Glück" })).toBeVisible();
|
||
// Ohne AI: nach Regeln in Abschnitte eingeordnet, Wortlaut bleibt.
|
||
await expect(page.getByRole("note").filter({ hasText: "Nach Regeln in Abschnitte eingeordnet" })).toBeVisible();
|
||
await expect(page.getByLabel("Abschnitt von Schritt 1")).toHaveValue("cook");
|
||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||
await expect(amounts).toHaveCount(4);
|
||
await expect(amounts.nth(0)).toHaveValue("250");
|
||
await expect(amounts.nth(1)).toHaveValue("2");
|
||
// Becher ist das Gebinde der Sahne (26.11.39): 1 Packung zu 200 ml.
|
||
await expect(amounts.nth(2)).toHaveValue("1");
|
||
await expect(page.getByRole("combobox", { name: "Einheit" }).nth(2).locator("option:checked")).toHaveText("Packung (200 ml)");
|
||
await expect(amounts.nth(3)).toHaveValue("");
|
||
// Eier in Esslöffeln passen nicht: Menge fehlt — Speichern sagt es, statt die Zeile wegzulassen.
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("status").filter({ hasText: "1 Angabe fehlt noch" })).toBeVisible();
|
||
await expect(amounts.nth(3)).toBeFocused();
|
||
await expect(page.getByText("Menge fehlt.")).toBeVisible();
|
||
await amounts.nth(3).fill("2");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Linsensuppe vom Blog");
|
||
// Gespeichert unter „Ausprobieren“ — und die Seite sagt es (26.11.41).
|
||
await expect(page.getByRole("note").filter({ hasText: "Steht unter „Ausprobieren“" })).toBeVisible();
|
||
await expect(page.locator("main img").first()).toHaveAttribute("src", /\/api\/fotos\//);
|
||
await expect(page.locator(`main a[href="${origin}/rezept"]`)).toBeVisible();
|
||
});
|
||
});
|
||
|
||
// Kochbuchfoto und Textmodell: ein kleiner Server in OpenAI-Form spielt LiteLLM
|
||
// (gleiche Testadresse wie oben). Er antwortet mit festen Rezepten und prüft
|
||
// den Schlüssel — so sieht der Test auch, dass der Tresor ihn richtig herausgibt.
|
||
test.describe("cookbook photo and AI setting", () => {
|
||
let server: import("node:http").Server;
|
||
const origin = process.env.IMPORT_TEST_ORIGIN ?? "http://127.0.0.1:3021";
|
||
const reply = (r: object) => JSON.stringify({ choices: [{ message: { content: "```json\n" + JSON.stringify(r) + "\n```" } }] });
|
||
|
||
let pagesSeen = 0;
|
||
|
||
test.beforeAll(async () => {
|
||
const { createServer } = await import("node:http");
|
||
server = createServer((req, res) => {
|
||
let raw = "";
|
||
req.on("data", (c) => (raw += c));
|
||
req.on("end", () => {
|
||
if (req.url === "/blog") {
|
||
const text = "Unsere liebste Pasta. ".repeat(10) + "Zutaten: 400 g Spaghetti, Salz. Nudeln kochen.";
|
||
return res.writeHead(200, { "content-type": "text/html" }).end(`<html><body><article><p>${text}</p></article></body></html>`);
|
||
}
|
||
if (!req.url?.startsWith("/v1/")) return res.writeHead(404).end();
|
||
if (req.headers.authorization !== "Bearer sk-test") return res.writeHead(401).end();
|
||
// Sprache zu Text: die Aufnahme kommt als multipart; die Abschrift ist fest.
|
||
if (req.url === "/v1/audio/transcriptions") {
|
||
return res.writeHead(200, { "content-type": "application/json" }).end(
|
||
JSON.stringify({
|
||
text: "Omas Linsencurry für vier Leute. Zweihundertfünfzig Gramm rote Linsen, zwei Zwiebeln und Tomaten. Zwiebeln würfeln, dann alles zwanzig Minuten köcheln lassen.",
|
||
}),
|
||
);
|
||
}
|
||
if (req.url === "/v1/models") {
|
||
return res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({ data: [{ id: "qwen-vl" }, { id: "qwen-text" }] }));
|
||
}
|
||
// Gesprochenes Rezept: das Modell erfindet absichtlich eine Menge (800 g Tomaten) und eine Zeit.
|
||
if (raw.includes("spoken recipe")) {
|
||
return res.writeHead(200, { "content-type": "application/json" }).end(
|
||
reply({
|
||
title: "Omas Linsencurry",
|
||
portions: 4,
|
||
minutes: null,
|
||
ingredients: ["250 g rote Linsen", "2 Zwiebeln", "800 g Tomaten"],
|
||
steps: ["Zwiebeln würfeln.", "Alles 20 Minuten köcheln lassen, bei 180 °C."],
|
||
}),
|
||
);
|
||
}
|
||
// „Einheitlich formulieren“: die Hausform-Anfrage bekommt Schritte mit Abschnitten.
|
||
if (raw.includes("house style") && raw.includes("Kartoffel")) {
|
||
return res.writeHead(200, { "content-type": "application/json" }).end(
|
||
reply({
|
||
steps: [
|
||
{ section: "prep", text: "Kartoffeln waschen.", ingredients: [1] },
|
||
{ section: "cook", text: "Kartoffeln kochen.", ingredients: [1] },
|
||
{ section: "serve", text: "Alles mischen.", ingredients: [] },
|
||
],
|
||
}),
|
||
);
|
||
}
|
||
// Andere Hausform-Anfragen: Fehler — dann ordnen die Regeln ein.
|
||
if (raw.includes("house style")) return res.writeHead(500).end();
|
||
const withImage = raw.includes("image_url");
|
||
if (withImage) pagesSeen = (raw.match(/"type":"image_url"/g) ?? []).length;
|
||
res.writeHead(200, { "content-type": "application/json" }).end(
|
||
withImage
|
||
? reply({ title: "Kartoffelsalat aus dem Kochbuch", portions: 4, minutes: 40, ingredients: ["1 kg Kartoffeln", "2 Zwiebeln", "1 Glas Gurken"], steps: ["Kartoffeln kochen.", "Alles mischen."] })
|
||
: reply({ title: "Blog-Pasta", portions: 2, minutes: 15, ingredients: ["400 g Spaghetti", "Salz"], steps: ["Nudeln kochen."] }),
|
||
);
|
||
});
|
||
});
|
||
await new Promise<void>((done) => server.listen(Number(new URL(origin).port), "127.0.0.1", done));
|
||
});
|
||
test.afterAll(() => new Promise<void>((done) => server.close(() => done())));
|
||
|
||
async function fillMissingAmounts(page: import("@playwright/test").Page) {
|
||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||
for (let i = 0; i < (await amounts.count()); i++) {
|
||
if (!(await amounts.nth(i).inputValue())) await amounts.nth(i).fill("1");
|
||
}
|
||
}
|
||
|
||
test("without an image model the photo page says how to set it up", async ({ page }) => {
|
||
await page.goto("/gerichte/hinzufuegen");
|
||
await page.getByRole("link", { name: /Kochbuch fotografieren/ }).click();
|
||
await expect(page.getByText("braucht foodplanhero ein Bildmodell")).toBeVisible();
|
||
await page.getByRole("link", { name: "AI einrichten" }).click();
|
||
await expect(page).toHaveURL(/\/mehr\/ki$/);
|
||
});
|
||
|
||
test("an admin sets up the AI and checks the connection", async ({ page }) => {
|
||
await page.goto("/mehr/ki");
|
||
await page.fill("#ai-endpoint", `${origin}/v1`);
|
||
await page.fill("#ai-vision", "qwen-vl");
|
||
await page.fill("#ai-text", "qwen-text");
|
||
await page.fill("#ai-speech", "whisper");
|
||
await page.fill("#ai-key", "sk-wrong");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("status")).toHaveText("Gespeichert.");
|
||
await page.getByRole("button", { name: "Verbindung prüfen" }).click();
|
||
await expect(page.locator("main [role=alert]")).toContainText("Schlüssel wurde abgelehnt");
|
||
await page.fill("#ai-key", "sk-test");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("status")).toHaveText("Gespeichert.");
|
||
await expect(page.locator("#ai-key")).toHaveAttribute("placeholder", /Hinterlegt/);
|
||
await page.getByRole("button", { name: "Verbindung prüfen" }).click();
|
||
await expect(page.getByRole("status")).toContainText("Verbunden");
|
||
await page.goto("/mehr");
|
||
await expect(page.getByRole("link", { name: /Eingerichtet/ })).toBeVisible();
|
||
});
|
||
|
||
test("a cookbook photo becomes a draft marked as read by the AI", async ({ page }) => {
|
||
await page.goto("/gerichte/foto");
|
||
const jpg = await sharp({ create: { width: 1000, height: 1400, channels: 3, background: { r: 245, g: 240, b: 230 } } }).jpeg().toBuffer();
|
||
// Mehrere Seiten (26.11.48): jede Auswahl kommt hinten dazu, einzelne lassen sich entfernen.
|
||
const input = page.locator("input[type=file]");
|
||
await input.setInputFiles({ name: "seite1.jpg", mimeType: "image/jpeg", buffer: jpg });
|
||
await expect(page.getByRole("img", { name: "Seite 1" })).toBeVisible();
|
||
await input.setInputFiles({ name: "seite2.jpg", mimeType: "image/jpeg", buffer: jpg });
|
||
await expect(page.getByRole("img", { name: "Seite 2" })).toBeVisible();
|
||
await page.getByRole("button", { name: "Seite 1 entfernen" }).click();
|
||
await expect(page.getByRole("img", { name: /^Seite/ })).toHaveCount(1);
|
||
await input.setInputFiles({ name: "seite3.jpg", mimeType: "image/jpeg", buffer: jpg });
|
||
await expect(page.getByRole("list", { name: "2 Seiten" })).toBeVisible();
|
||
await page.getByRole("button", { name: "Rezept lesen" }).click();
|
||
await expect(page.locator("#title")).toHaveValue("Kartoffelsalat aus dem Kochbuch");
|
||
expect(pagesSeen).toBe(2);
|
||
await expect(page.getByRole("note").first()).toContainText("Von der AI gelesen");
|
||
await expect(page.getByRole("note").filter({ hasText: "Von der AI in die foodplanhero-Form gebracht" })).toBeVisible();
|
||
await expect(page.getByLabel("Schritt 1", { exact: true })).toHaveValue("Kartoffeln waschen.");
|
||
await expect(page.getByLabel("Abschnitt von Schritt 3")).toHaveValue("serve");
|
||
await fillMissingAmounts(page);
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Kartoffelsalat aus dem Kochbuch");
|
||
});
|
||
|
||
test("a dish told into the microphone becomes a draft, with only the amounts that were said", async ({ page }) => {
|
||
await page.goto("/gerichte/hinzufuegen");
|
||
await page.getByRole("link", { name: /Einsprechen/ }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Gericht einsprechen");
|
||
await page.getByRole("button", { name: "Aufnahme starten" }).click();
|
||
await expect(page.getByText(/Nimmt auf/)).toBeVisible();
|
||
await page.waitForTimeout(1500);
|
||
await page.getByRole("button", { name: "Aufnahme beenden" }).click();
|
||
await expect(page.getByLabel("Was du erzählt hast")).toHaveValue(/Omas Linsencurry/);
|
||
await page.getByRole("button", { name: "Rezept daraus machen" }).click();
|
||
await expect(page.locator("#title")).toHaveValue("Omas Linsencurry");
|
||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||
await expect(amounts.nth(0)).toHaveValue("250"); // gesagt: zweihundertfünfzig
|
||
await expect(amounts.nth(1)).toHaveValue("2");
|
||
await expect(amounts.nth(2)).toHaveValue(""); // 800 g hat niemand gesagt
|
||
await expect(page.getByLabel("Schritt 2", { exact: true })).toHaveValue("Alles 20 Minuten köcheln lassen.");
|
||
});
|
||
|
||
test("a page without recipe data is read by the text model", async ({ page }) => {
|
||
await page.goto("/gerichte/link");
|
||
await page.fill("#recipe-url", `${origin}/blog`);
|
||
await page.getByRole("button", { name: "Rezept holen" }).click();
|
||
await expect(page.locator("#title")).toHaveValue("Blog-Pasta");
|
||
await expect(page.getByRole("note").first()).toContainText("Von der AI gelesen");
|
||
});
|
||
});
|
||
|
||
// Produktgruppen und eigene Zutaten (26.11.38, Kai: „den Oberbegriff Pasta eigentlich besser“).
|
||
test("a group term shows the group with its kinds; an own ingredient and a remembered product", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Gnocchi in Salbeibutter");
|
||
const search = page.getByRole("combobox", { name: "Zutat suchen" }).first();
|
||
await search.fill("Nudeln");
|
||
const options = page.getByRole("listbox").getByRole("option");
|
||
await expect(options.first()).toContainText("Pasta · beliebige Sorte");
|
||
await expect(page.getByRole("option", { name: "Spaghetti", exact: true })).toBeVisible();
|
||
await expect(page.getByRole("option", { name: "Penne", exact: true })).toBeVisible();
|
||
|
||
await search.fill("Gnocchi Hausmacher");
|
||
await page.getByRole("option", { name: "„Gnocchi Hausmacher“ als neue Zutat anlegen" }).click();
|
||
const create = page.getByRole("group", { name: "Neue Zutat" });
|
||
await create.getByLabel("Gehört zu").selectOption({ label: "Pasta" });
|
||
await expect(create.getByLabel("Regal im Laden")).toHaveCount(0);
|
||
await create.getByRole("button", { name: "Anlegen" }).click();
|
||
await expect(search).toHaveValue("Gnocchi Hausmacher");
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).first().fill("500");
|
||
await page.getByRole("button", { name: "Produkt hinterlegen" }).click();
|
||
await page.getByLabel("Produkt für Gnocchi Hausmacher").fill("Rana Gnocchi");
|
||
await page.getByLabel("Für alle Gerichte mit Gnocchi Hausmacher merken").check();
|
||
await page.getByLabel("Schritt 1", { exact: true }).fill("Gnocchi in Salzwasser garen.");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Gnocchi in Salbeibutter");
|
||
|
||
// Ein zweites Gericht bekommt das gemerkte Produkt gleich beim Wählen.
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Gnocchi-Auflauf");
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Gnocchi Haus");
|
||
await page.getByRole("option", { name: /Gnocchi Hausmacher.*eigene/ }).click();
|
||
await expect(page.getByText("Euer Produkt für alle Gerichte: Rana Gnocchi")).toBeVisible();
|
||
await expect(page.getByRole("button", { name: "Anderes Produkt für dieses Gericht" })).toBeVisible();
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).first().fill("400");
|
||
await page.getByLabel("Schritt 1", { exact: true }).fill("Gnocchi in die Form geben.");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.locator("main")).toContainText("Rana Gnocchi");
|
||
|
||
// Wieder aus dem Pool, damit der Plan danach denselben Bestand vorschlägt.
|
||
for (const title of ["Gnocchi-Auflauf", "Gnocchi in Salbeibutter"]) {
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: new RegExp(title) }).click();
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
}
|
||
});
|
||
|
||
// Löffel und Gebinde (26.11.39, Kai: „Teelöffel, Esslöffel … eine Dose als Einheit“).
|
||
test("spoons and cans: the ingredient preselects its measure, the dish shows spoons and grams", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Tomatensoße vom Blech");
|
||
const search = page.getByRole("combobox", { name: "Zutat suchen" });
|
||
const unit = page.getByRole("combobox", { name: "Einheit" });
|
||
await search.first().fill("Olivenöl");
|
||
await page.getByRole("option", { name: "Olivenöl", exact: true }).click();
|
||
await expect(unit.first()).toHaveValue("tbsp");
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).first().fill("2");
|
||
|
||
await page.getByRole("button", { name: "Zutaten" }).click();
|
||
await search.nth(1).fill("gehackte Tomaten");
|
||
await page.getByRole("option", { name: /Gehackte Tomaten/ }).first().click();
|
||
// Die Dose wird angeboten, mit Größe, aber nicht vorgewählt.
|
||
await expect(unit.nth(1)).toHaveValue("g");
|
||
await unit.nth(1).selectOption("can");
|
||
await expect(unit.nth(1).locator("option:checked")).toHaveText("Dose (400 g)");
|
||
await expect(page.getByText("1 Dose = 400 g")).toBeVisible();
|
||
// Unsere Dose hat 500 g.
|
||
await page.getByRole("button", { name: "Größe ändern" }).click();
|
||
await page.getByLabel("Wie viel ist 1 Dose? (in g)").fill("500");
|
||
await page.getByRole("button", { name: "Übernehmen" }).click();
|
||
await expect(page.getByText("1 Dose = 500 g")).toBeVisible();
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).nth(1).fill("1");
|
||
await page.getByLabel("Schritt 1", { exact: true }).fill("Tomaten mit Öl aufs Blech.");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Tomatensoße vom Blech");
|
||
|
||
// Auf vier Portionen: „2 EL (30 ml) Olivenöl“, „500 g (1 Dose) Gehackte Tomaten“.
|
||
const list = page.locator("main ul").first();
|
||
const portions = page.locator("output");
|
||
for (let i = 0; i < 8 && !(await portions.innerText()).startsWith("4 "); i++) {
|
||
const n = Number((await portions.innerText()).match(/\d+/)![0]);
|
||
await page.getByRole("button", { name: n > 4 ? "Eine Portion weniger" : "Eine Portion mehr" }).click();
|
||
}
|
||
await expect(list.locator("li", { hasText: "Olivenöl" })).toContainText(/2 EL\s*\(30 ml\) Olivenöl/);
|
||
await expect(list.locator("li", { hasText: "Gehackte Tomaten" })).toContainText(/500 g\s*\(1 Dose\) Gehackte Tomaten/);
|
||
await page.getByRole("button", { name: "Eine Portion weniger" }).click();
|
||
await page.getByRole("button", { name: "Eine Portion weniger" }).click();
|
||
await expect(list.locator("li", { hasText: "Olivenöl" })).toContainText(/1 EL\s*\(15 ml\)/);
|
||
await expect(list.locator("li", { hasText: "Gehackte Tomaten" })).toContainText(/250 g\s*\(½ Dose\)/);
|
||
|
||
// Bearbeiten zeigt die Mengen im eingegebenen Maß.
|
||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||
await expect(unit.first()).toHaveValue("tbsp");
|
||
await expect(page.getByRole("textbox", { name: "Menge", exact: true }).first()).toHaveValue("2");
|
||
await expect(unit.nth(1)).toHaveValue("can");
|
||
await expect(page.getByRole("textbox", { name: "Menge", exact: true }).nth(1)).toHaveValue("1");
|
||
|
||
// Aufräumen: Größe zurück, Gericht aus dem Pool — damit Plan und Einkauf gleich bleiben.
|
||
await page.getByRole("button", { name: "Größe ändern" }).click();
|
||
await page.getByLabel("Wie viel ist 1 Dose? (in g)").fill("400");
|
||
await page.getByRole("button", { name: "Übernehmen" }).click();
|
||
await expect(page.getByText("1 Dose = 400 g")).toBeVisible();
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: /Tomatensoße vom Blech/ }).click();
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
});
|
||
|
||
// Kai: „Neue Gerichte werden nicht gespeichert“ — sie standen unter „Ausprobieren“, ohne dass
|
||
// die Seite es sagte (26.11.41). Jetzt: Hinweis, Weg dorthin, und mit einem Tipp in den Pool.
|
||
test("portions are remembered and scale the amounts; a pack and cloves for any ingredient (26.11.49)", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Hackbraten");
|
||
await page.fill("#portions", "6");
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Gemischtes Hack");
|
||
await page.getByRole("option", { name: "Gemischtes Hackfleisch", exact: true }).click();
|
||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||
const units = page.getByRole("combobox", { name: "Einheit" });
|
||
await amounts.nth(0).fill("1");
|
||
await units.nth(0).selectOption("pack");
|
||
// Hackfleisch hat keine Packungsgröße: Speichern fragt danach, statt still zu rechnen.
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByText("Größe fehlt – bitte eintragen.")).toBeVisible();
|
||
await expect(page.getByLabel("Wie viel ist 1 Packung? (in g)")).toBeFocused();
|
||
await page.getByLabel("Wie viel ist 1 Packung? (in g)").fill("500");
|
||
await page.getByRole("button", { name: "Zutaten" }).click();
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).nth(1).fill("Knoblauchz");
|
||
await page.getByRole("option", { name: "Knoblauchzehe", exact: true }).click();
|
||
await amounts.nth(1).fill("3");
|
||
await units.nth(1).selectOption("clove");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Hackbraten");
|
||
|
||
// Bearbeiten zeigt das Rezept wieder für 6 Portionen, im eingegebenen Maß.
|
||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||
await expect(page.locator("#portions")).toHaveValue("6");
|
||
await expect(amounts.nth(0)).toHaveValue("1");
|
||
await expect(units.nth(0).locator("option:checked")).toHaveText("Packung (500 g)");
|
||
await expect(amounts.nth(1)).toHaveValue("3");
|
||
await expect(units.nth(1)).toHaveValue("clove");
|
||
// Portionen umstellen rechnet mit.
|
||
await page.fill("#portions", "3");
|
||
await expect(amounts.nth(0)).toHaveValue("0,5");
|
||
await expect(amounts.nth(1)).toHaveValue("1,5");
|
||
await page.fill("#portions", "6");
|
||
await expect(amounts.nth(0)).toHaveValue("1");
|
||
await page.fill("#portions", "3");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Hackbraten");
|
||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||
await expect(page.locator("#portions")).toHaveValue("3");
|
||
await expect(amounts.nth(0)).toHaveValue("0,5");
|
||
// Wieder aus dem Pool, damit der Plan später nicht anders vorschlägt.
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: /Hackbraten/ }).click();
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
});
|
||
|
||
test("millilitres for a piece ingredient: stock cubes in ml with the size per piece (26.11.50)", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Brühnudeln");
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Brühwürf");
|
||
await page.getByRole("option", { name: "Brühwürfel", exact: true }).click();
|
||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||
const units = page.getByRole("combobox", { name: "Einheit" });
|
||
await amounts.nth(0).fill("750");
|
||
await units.nth(0).selectOption("ml");
|
||
await page.getByLabel("Wie viel ml ist 1 Stück?").fill("500");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Brühnudeln");
|
||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||
await expect(amounts.nth(0)).toHaveValue("750");
|
||
await expect(units.nth(0)).toHaveValue("ml");
|
||
await expect(page.getByText("1 Stück = 500 ml")).toBeVisible();
|
||
await page.goto("/gerichte");
|
||
await page.getByRole("link", { name: /Brühnudeln/ }).click();
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
});
|
||
|
||
test("what is missing is marked at the field, counted below and shown on tap (26.11.51)", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||
const units = page.getByRole("combobox", { name: "Einheit" });
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Zwieb");
|
||
await page.getByRole("option", { name: "Zwiebeln", exact: true }).click();
|
||
await page.getByRole("button", { name: "Zutaten" }).click();
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).nth(1).fill("Eier");
|
||
await page.getByRole("option", { name: "Eier", exact: true }).click();
|
||
await amounts.nth(1).fill("100");
|
||
await units.nth(1).selectOption("ml");
|
||
// Ohne Titel, ohne Menge bei den Zwiebeln, ohne Größe für Eier in ml.
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
const left = page.getByRole("status").filter({ hasText: "fehlen noch" });
|
||
await expect(left).toHaveText(/3 Angaben fehlen noch/);
|
||
const title = page.locator("#title");
|
||
await expect(title).toBeFocused();
|
||
await expect(title).toHaveAttribute("aria-invalid", "true");
|
||
expect(await title.evaluate((e) => getComputedStyle(e).borderTopWidth)).toBe("2px");
|
||
await expect(page.getByText("Titel fehlt.")).toBeVisible();
|
||
// „Zeigen“ führt zum nächsten.
|
||
await left.getByRole("button", { name: "Zeigen" }).click();
|
||
await expect(amounts.nth(0)).toBeFocused();
|
||
await amounts.nth(0).fill("2");
|
||
await expect(left).toHaveText(/2 Angaben fehlen noch/);
|
||
await title.fill("Zwiebelkuchen");
|
||
await page.getByLabel("Wie viel ml ist 1 Stück?").fill("50");
|
||
await expect(left).toHaveCount(0);
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Zwiebelkuchen");
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
});
|
||
|
||
test("a dish to try says so, links to its tab and moves to the pool with one tap", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Probe-Auflauf");
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Zwieb");
|
||
await page.getByRole("option", { name: "Zwiebeln", exact: true }).click();
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).first().fill("2");
|
||
await page.getByLabel("Erst mal ausprobieren").check();
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Probe-Auflauf");
|
||
const note = page.getByRole("note").filter({ hasText: "Steht unter „Ausprobieren“" });
|
||
await expect(note).toBeVisible();
|
||
await expect(page.locator("main").getByRole("link", { name: "Gerichte", exact: true })).toHaveAttribute("href", "/gerichte?ansicht=ausprobieren");
|
||
await note.getByRole("button", { name: "In den Pool" }).click();
|
||
await expect(note).toHaveCount(0);
|
||
// Fotos auch aus der Mediathek, mehrere auf einmal (26.11.43): kein capture, multiple.
|
||
const picker = page.locator("input[type=file]");
|
||
expect(await picker.getAttribute("capture")).toBeNull();
|
||
expect(await picker.getAttribute("multiple")).not.toBeNull();
|
||
const shots = await Promise.all(
|
||
[[200, 80, 60], [60, 140, 90]].map(async ([r, g, b], i) => ({
|
||
name: `mediathek-${i}.png`,
|
||
mimeType: "image/png",
|
||
buffer: await sharp({ create: { width: 800, height: 600, channels: 3, background: { r: r!, g: g!, b: b! } } }).png().toBuffer(),
|
||
})),
|
||
);
|
||
await picker.setInputFiles(shots);
|
||
await expect(page.getByRole("heading", { name: "Fotos · 2 von 5" })).toBeVisible();
|
||
await page.goto("/gerichte");
|
||
await expect(page.getByRole("link", { name: /Probe-Auflauf/ })).toBeVisible();
|
||
// Aufräumen, damit der Plan danach denselben Bestand vorschlägt.
|
||
await page.getByRole("link", { name: /Probe-Auflauf/ }).click();
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
});
|
||
|
||
|
||
// Kai: „Die Karten sollen immer dieselbe Größe haben“ (26.11.44) — auch bei langen Titeln.
|
||
test("dish cards in the pool all have the same size, long titles end with an ellipsis", async ({ page }) => {
|
||
await page.goto("/gerichte/neu");
|
||
await page.fill("#title", "Gyros-Nudelauflauf in Metaxasoße mit extra viel Käse vom Blech");
|
||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Zwieb");
|
||
await page.getByRole("option", { name: "Zwiebeln", exact: true }).click();
|
||
await page.getByRole("textbox", { name: "Menge", exact: true }).first().fill("1");
|
||
await page.getByRole("button", { name: "Speichern" }).click();
|
||
await expect(page.getByRole("heading", { level: 1 })).toContainText("Gyros-Nudelauflauf");
|
||
await page.goto("/gerichte");
|
||
const sizes = await page.locator("main ul li a").evaluateAll((els) => els.map((e) => Math.round(e.getBoundingClientRect().height)));
|
||
expect(sizes.length).toBeGreaterThan(2);
|
||
expect(new Set(sizes).size).toBe(1);
|
||
// Der volle Titel bleibt erreichbar.
|
||
await expect(page.getByRole("link", { name: /Gyros-Nudelauflauf/ })).toHaveAttribute("title", /extra viel Käse vom Blech/);
|
||
// Aufräumen, damit der Plan danach denselben Bestand vorschlägt.
|
||
await page.getByRole("link", { name: /Gyros-Nudelauflauf/ }).click();
|
||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||
await expect(page).toHaveURL(/entfernt=/);
|
||
});
|