import { test, expect } from "@playwright/test"; test("login with wrong credentials shows an error message", async ({ page }) => { await page.goto("/konto"); await page.getByLabel("E-Mail", { exact: true }).first().fill("unbekannt@example.de"); await page.getByLabel("Passwort", { exact: true }).first().fill("falschespasswort"); await page.getByRole("button", { name: "Anmelden" }).click(); await expect(page.getByText(/E-Mail-Adresse oder Passwort ist falsch/i)).toBeVisible(); }); test("registration rejects a password shorter than 8 characters", async ({ page }) => { await page.goto("/konto"); await page.getByLabel("Vorname").fill("Test"); await page.getByLabel("Nachname").fill("Person"); await page.getByLabel("E-Mail", { exact: true }).nth(1).fill(`e2e-${Date.now()}@example.de`); await page.getByLabel(/Passwort \(mind\. 8 Zeichen\)/).fill("kurz"); await page.getByRole("button", { name: "Konto erstellen" }).click(); await expect(page.getByText(/mindestens 8 Zeichen/i)).toBeVisible(); }); test("registering, logging out, and logging back in reaches the logged-in account page", async ({ page }) => { const email = `e2e-login-${Date.now()}@example.de`; // Zufaellig statt eines festen Werts wie "Passwort123!" — der HIBP- // Breach-Check (isPasswordBreached) lehnt bekannte Leak-Passwoerter ab, // ein per Zeitstempel eindeutiges Passwort landet nicht in solchen Listen. const password = `Xk9-qLp2-Zt${Date.now()}`; await page.goto("/konto"); await page.getByLabel("Vorname").fill("Test"); await page.getByLabel("Nachname").fill("Person"); await page.getByLabel("E-Mail", { exact: true }).nth(1).fill(email); await page.getByLabel(/Passwort \(mind\. 8 Zeichen\)/).fill(password); await page.getByLabel("Passwort bestätigen").fill(password); await page.getByRole("button", { name: "Konto erstellen" }).click(); // Registrierung meldet automatisch an — erst abmelden, um den separaten // Login-Pfad (loginAction statt der impliziten Session bei der // Registrierung) tatsaechlich zu pruefen. Zwei Buttons heissen "Abmelden" // (auch "alle Geraete abmelden") — .last() ist der einfache Logout-Button, // der tatsaechlich zur ausgeloggten Ansicht zurueckfuehrt. await expect(page.getByRole("button", { name: "Abmelden" }).first()).toBeVisible(); await page.getByRole("button", { name: "Abmelden" }).last().click(); await expect(page.getByRole("heading", { name: "Anmelden oder Konto erstellen" })).toBeVisible(); await page.getByLabel("E-Mail", { exact: true }).first().fill(email); await page.getByLabel("Passwort", { exact: true }).first().fill(password); await page.getByRole("button", { name: "Anmelden" }).click(); await expect(page.getByRole("button", { name: "Abmelden" }).first()).toBeVisible(); await expect(page.getByRole("heading", { name: "Anmelden oder Konto erstellen" })).not.toBeVisible(); });