Files
pleno-vue/tests/e2e/superuser-department-shells.spec.js
T

105 lines
3.6 KiB
JavaScript

import { expect, test } from "@playwright/test";
import { apiPathPattern, mockApi, seedAuthenticatedState } from "./support/network.js";
const json = (body, status = 200) => ({
status,
contentType: "application/json",
body: JSON.stringify(body),
});
const department = {
id: 1,
name: "Esbjerg",
description: "Skagerrakvej 15",
branding: null,
custom_pricing_only: false,
created_at: "2026-01-01 00:00:00",
updated_at: "2026-07-06 09:30:00",
};
async function installCommonDepartmentRoutes(page) {
await page.route(apiPathPattern("/superuser/department"), async (route) => {
await route.fulfill(json({ data: department }));
});
await page.route(apiPathPattern("/departments/categories"), async (route) => {
await route.fulfill(json({ data: [] }));
});
await page.route(apiPathPattern("/department_variables"), async (route) => {
await route.fulfill(json({ data: [] }));
});
await page.route(apiPathPattern("/modules/workfeed/departments"), async (route) => {
await route.fulfill(json({ data: [] }));
});
await page.route(apiPathPattern("/departments/self-serve/enabled"), async (route) => {
await route.fulfill(json({ data: { enabled: false } }));
});
await page.route(apiPathPattern("/modules/stripe/terminal/locations"), async (route) => {
await route.fulfill(json({ data: { data: [] } }));
});
await page.route(apiPathPattern("/modules/stripe/department/terminal/location"), async (route) => {
const request = route.request();
if (request.method() === "GET") {
await route.fulfill(json({ data: { id: null, location: null } }));
return;
}
await route.fulfill(json({ data: { location: null } }));
});
await page.route(apiPathPattern("/modules/stripe/department/terminal/readers"), async (route) => {
await route.fulfill(json({ data: { data: [] } }));
});
}
test.describe("superuser department shells", () => {
test.beforeEach(async ({ page }) => {
await seedAuthenticatedState(page, "superuser-department-shells-token");
await mockApi(page, {
authenticated: true,
permissions: [
"superuser",
"user",
"list_departments",
"edit_department",
"superuser_fetch_department",
"superuser_fetch_department_prices",
],
});
await installCommonDepartmentRoutes(page);
});
test("shows the department title and module summary", async ({ page }) => {
await page.goto("/superuser/departments/1/modules", { waitUntil: "domcontentloaded" });
await expect(page.getByRole("heading", { name: "Esbjerg" })).toBeVisible();
await expect(page.getByTestId("department-module-variables")).toBeVisible();
});
test("shows the department title and category tools", async ({ page }) => {
await page.goto("/superuser/departments/1/categories", { waitUntil: "domcontentloaded" });
await expect(page.getByRole("heading", { name: "Esbjerg" })).toBeVisible();
await expect(page.getByRole("table")).toBeVisible();
});
test("shows the department title and Stripe location setup", async ({ page }) => {
await page.goto("/superuser/departments/1/stripe/setup", { waitUntil: "domcontentloaded" });
await expect(page.getByRole("heading", { name: "Esbjerg" })).toBeVisible();
});
test("shows the department title and Stripe readers table", async ({ page }) => {
await page.goto("/superuser/departments/1/stripe/terminals/readers", { waitUntil: "domcontentloaded" });
await expect(page.getByRole("heading", { name: "Esbjerg" })).toBeVisible();
await expect(page.getByRole("table")).toBeVisible();
});
});