Files
itworx-knowledge-hub-Public/tests/e2e/specs/auth-journey.spec.ts
T

57 lines
2.5 KiB
TypeScript

import AxeBuilder from "@axe-core/playwright";
import { expect, test } from "@playwright/test";
import { OWNER_DISPLAY_NAME, OWNER_EMAIL, OWNER_PASSWORD } from "./support/credentials";
test.describe("login / shell / logout journey", () => {
test("a user can log in with the keyboard alone, reach the shell, and log out", async ({
page
}) => {
await page.goto("/");
await expect(page.getByRole("heading", { name: "Aanmelden" })).toBeVisible();
// Keyboard-only: no page.click() anywhere in this test.
await page.getByLabel("E-mailadres").click();
await page.keyboard.type(OWNER_EMAIL);
await page.keyboard.press("Tab");
await page.keyboard.type(OWNER_PASSWORD);
await page.keyboard.press("Enter");
await expect(page.getByRole("button", { name: "Accountmenu" })).toContainText(OWNER_DISPLAY_NAME);
await expect(page.getByRole("heading", { name: "Operationeel overzicht" })).toBeVisible();
const shellAccessibility = await new AxeBuilder({ page }).analyze();
expect(shellAccessibility.violations).toEqual([]);
// Account menu and logout remain keyboard-operable in the V2 shell.
await page.getByRole("button", { name: "Accountmenu" }).focus();
await page.keyboard.press("Enter");
await page.getByRole("menuitem", { name: "Afmelden" }).focus();
await page.keyboard.press("Enter");
await expect(page.getByRole("heading", { name: "Aanmelden" })).toBeVisible();
});
test("an incorrect password shows a clear, accessible error and does not sign the user in", async ({
page
}) => {
await page.goto("/");
// Deliberately a non-existent account rather than the shared owner account: the
// owner is reused (and logged in) by every project in this suite, and repeatedly
// failing its password here would risk tripping real account lockout across
// parallel workers/projects. The generic error text and non-authenticated outcome
// are the same either way (see LoginUseCase — unknown account and wrong password
// are indistinguishable by design).
await page.getByLabel("E-mailadres").fill("onbekend@itworx.e2e");
await page.getByLabel("Wachtwoord", { exact: true }).fill("whatever-password-value");
await page.getByRole("button", { name: "Aanmelden" }).click();
const alert = page.getByRole("alert");
await expect(alert).toBeVisible();
await expect(alert).toContainText("onjuist");
// Still on the login screen, not silently signed in.
await expect(page.getByRole("heading", { name: "Aanmelden" })).toBeVisible();
});
});