Files
pleno-vue/tests/e2e/userHome.spec.ts
T
Jeppe BandJeppe Bundgaard acbbac588f [codex] disable invoice downloads until invoices exist (#158)
* disable invoice downloads until invoices exist

* enable github-hosted frontend ci runners

* Update POS invoice download visual expectations

* Fix full E2E i18n and self-serve coverage

* Review dynamic view i18n keys

---------

Co-authored-by: Jeppe Bundgaard <jb@truckwash.dk>
2026-07-06 22:35:58 +02:00

76 lines
2.9 KiB
TypeScript

import { test, expect, type Page } from "@playwright/test";
import { createPosFixture, mockApi, seedAuthenticatedState } from "./support/network.js";
import { loginAsUser } from "./fixtures";
const USER_HOME_CUSTOMER_NUMBER = 12345679;
async function gotoUserHomeWithInvoices(page: Page, collectedInvoices: Array<Record<string, unknown>>) {
await mockApi(page, {
authenticated: true,
sessionData: {
customer_number: USER_HOME_CUSTOMER_NUMBER,
display_name: "E2E User",
permissions: ["user"],
},
pos: createPosFixture({
collectedInvoices,
}),
});
await seedAuthenticatedState(page, "user-home-invoice-shortcut-token");
await page.goto("/user", { waitUntil: "domcontentloaded" });
await expect(page).toHaveURL(/\/user(?:\/)?(?:[?#].*)?$/);
}
/** User home Tests */
// User home page content tests
test("[PAGES][User][/user] should display a welcome message", async ({ page }) => {
await loginAsUser(page);
await expect(page.locator(".title")).toContainText(/Velkommen\s+\S+/);
});
// Book wash button visibility test
test("[PAGES][User][/user] should display the book wash button", async ({ page }) => {
await loginAsUser(page);
// Check if the "book wash" element is visible
await expect(page.locator("a#book-wash-button")).toBeVisible();
});
// Add vehicle button visibility test
test("[PAGES][User][/user] should display the add vehicle button", async ({ page }) => {
await loginAsUser(page);
// Check if the "create vehicle" element is visible
await expect(page.locator("a#add-vehicle-button")).toBeVisible();
});
// Download wash certificate button visibility test
test("[PAGES][User][/user] should display the download certificate button", async ({ page }) => {
await loginAsUser(page);
// Check if the "download certificate" element is visible
await expect(page.locator("a#download-certificates-button")).toBeVisible();
});
test("[PAGES][User][/user] should disable the download invoices button when no invoice exists", async ({ page }) => {
await gotoUserHomeWithInvoices(page, []);
const button = page.locator("button#download-invoices-button");
await expect(button).toBeVisible();
await expect(button).toBeDisabled();
await expect(button).not.toHaveClass(/is-loading/);
await expect(page.locator("a#download-invoices-button")).toHaveCount(0);
});
test("[PAGES][User][/user] should enable the download invoices button when an invoice exists", async ({ page }) => {
await gotoUserHomeWithInvoices(page, [
{
id: 7001,
customer_number: USER_HOME_CUSTOMER_NUMBER,
customer_name: "E2E User",
total_net_amount: 1250,
created_at: "2026-07-01",
closed_at: "2026-07-01",
},
]);
const link = page.locator("a#download-invoices-button");
await expect(link).toBeVisible();
await expect(link).toHaveAttribute("href", "/user/invoices");
await expect(page.locator("button#download-invoices-button")).toHaveCount(0);
});