Files
pleno-vue/tests/e2e/superuser-users.spec.ts
T

96 lines
3.0 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { mockApi, seedAuthenticatedState } from "./support/network.js";
import { isDesktopProject } from "./support/projects";
const json = (body: unknown, status = 200) => ({
status,
contentType: "application/json",
body: JSON.stringify(body),
});
const users = [
{
id: 11,
customer_number: 12345,
display_name: "Anna Andersen",
group_id: 1,
},
{
id: 12,
customer_number: 67890,
display_name: "Bo Nielsen",
group_id: 2,
},
];
const userEnvelope = (rows: Array<Record<string, unknown>>) => ({
data: rows,
meta: {
pagination: {
page: 1,
per_page: 100,
total: rows.length,
},
},
});
test.describe("Superuser employees list", () => {
test("uses shared search, pagination reload, and action wheel controls", async ({ page }, testInfo) => {
test.skip(!isDesktopProject(testInfo), "Desktop only");
const searchesSeen: Array<string | null> = [];
await page.setViewportSize({ width: 1280, height: 720 });
await seedAuthenticatedState(page, "superuser-users-token");
await mockApi(page, {
authenticated: true,
permissions: ["superuser", "user"],
sessionData: {
group_id: 1,
},
});
await page.route(
/https?:\/\/(?:api\.truckwash\.io(?::\d+)?\/users|localhost(?::\d+)?\/api\/users|127\.0\.0\.1(?::\d+)?\/api\/users)(?:\?.*)?$/i,
async (route) => {
const request = route.request();
const url = new URL(request.url());
if (request.method() !== "GET") {
await route.fulfill(json({ data: { message: "OK" } }));
return;
}
const search = url.searchParams.get("search");
searchesSeen.push(search);
const normalizedSearch = String(search || "").toLowerCase();
const rows = normalizedSearch.includes("anna") ? [users[0]] : users;
await route.fulfill(json(userEnvelope(rows)));
}
);
await page.goto("/superuser/users", { waitUntil: "domcontentloaded" });
await expect(page.getByTestId("pagination-reload-actions")).toBeVisible();
await expect(page.getByTestId("pagination-search-input")).toHaveAttribute(
"placeholder",
/Søg efter bruger|Search for user/
);
await expect(page.getByTestId("superuser-users-table")).toBeVisible();
await expect(page.getByTestId("superuser-users-row-11")).toContainText("Anna Andersen");
await expect(page.getByTestId("superuser-users-row-12")).toContainText("Bo Nielsen");
await page.getByTestId("pagination-search-input").fill("Anna");
await expect(page.getByTestId("superuser-users-row-11")).toContainText("Anna Andersen");
await expect(page.getByTestId("superuser-users-row-12")).toHaveCount(0);
await page.locator('[data-testid="superuser-user-actions-11"] .action-settings-wheel-trigger').click();
await expect(page.getByTestId("superuser-user-edit-11")).toBeVisible();
await expect(page.getByTestId("action-settings-wheel-section-customer")).toBeVisible();
expect(searchesSeen).toContain("Anna");
});
});