99 lines
3.6 KiB
JavaScript
99 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),
|
|
});
|
|
|
|
async function installOverviewRoutes(page) {
|
|
await page.route(apiPathPattern("/superuser/departments/1/overview"), async (route) => {
|
|
const parsedUrl = new URL(route.request().url());
|
|
expect(parsedUrl.searchParams.get("date")).toBe("2026-07-06");
|
|
|
|
await route.fulfill(
|
|
json({
|
|
data: {
|
|
department: {
|
|
id: 1,
|
|
name: "Esbjerg",
|
|
description: "Skagerrakvej 15",
|
|
economic_department_id: 42,
|
|
branding: 14,
|
|
created_at: "2026-01-01 00:00:00",
|
|
updated_at: "2026-07-06 09:30:00",
|
|
},
|
|
overview: {
|
|
department_ids: [1],
|
|
date: "2026-07-06",
|
|
date_to: "2026-07-06",
|
|
metrics: {
|
|
bookings: { state: "ready", value: 3, out_of: 4 },
|
|
complaints: { state: "ready", value: 1 },
|
|
night_washes: { state: "ready", value: 2 },
|
|
revenue: { state: "ready", value: 1234 },
|
|
washes: { state: "ready", value: 11 },
|
|
products_sold: { state: "ready", value: 18 },
|
|
transactions: { state: "ready", value: 9 },
|
|
water_usage: { state: "ready", value: 250 },
|
|
overtime: { state: "ready", value: 1.5 },
|
|
},
|
|
products: [
|
|
{
|
|
product_id: 24,
|
|
slug: "spot-free-lastbil",
|
|
title: "Spot Free",
|
|
state: "ready",
|
|
value: 4,
|
|
out_of: 11,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
})
|
|
);
|
|
});
|
|
|
|
await page.route(apiPathPattern("/modules/edge-gateways/workspace/departments/1"), async (route) => {
|
|
await route.fulfill(
|
|
json({
|
|
data: {
|
|
gateways: [
|
|
{ id: 1, status: "ONLINE" },
|
|
{ id: 2, status: "OFFLINE" },
|
|
],
|
|
lanes: [{ id: 1 }, { id: 2 }],
|
|
gates: [{ id: 1 }],
|
|
relays: [{ id: 1 }, { id: 2 }, { id: 3 }],
|
|
scanners: [{ id: 1 }],
|
|
issues: [{ key: "gateway-offline" }],
|
|
},
|
|
})
|
|
);
|
|
});
|
|
}
|
|
|
|
test.describe("superuser department overview", () => {
|
|
test("renders the operational overview for a selected department", async ({ page }) => {
|
|
await seedAuthenticatedState(page, "superuser-department-overview-token");
|
|
await mockApi(page, {
|
|
authenticated: true,
|
|
permissions: ["superuser", "user"],
|
|
});
|
|
await installOverviewRoutes(page);
|
|
|
|
await page.goto("/superuser/departments/1?date=2026-07-06", { waitUntil: "domcontentloaded" });
|
|
|
|
await expect(page.getByTestId("superuser-department-overview")).toBeVisible();
|
|
await expect(page.getByRole("heading", { name: "Esbjerg" })).toBeVisible();
|
|
await expect(page.getByText("Operational overview for the selected department")).toBeVisible();
|
|
await expect(page.getByTestId("department-overview-kpi-revenue")).toContainText("1.234");
|
|
await expect(page.getByTestId("department-overview-kpi-bookings")).toContainText("of 4");
|
|
await expect(page.getByTestId("department-overview-products")).toContainText("Spot Free");
|
|
await expect(page.getByTestId("department-overview-hardware")).toContainText("1 / 2");
|
|
await expect(page.getByTestId("department-overview-quick-links")).toContainText("Gateways");
|
|
await expect(page.getByTestId("date-period-other-dropdown-trigger")).toBeVisible();
|
|
});
|
|
});
|