102 lines
4.0 KiB
TypeScript
102 lines
4.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 now = "2026-05-07 10:00:00";
|
|
|
|
const buildDepartment = (department: Record<string, unknown>) => ({
|
|
description: "E2E department",
|
|
economic_department_id: 0,
|
|
created_at: now,
|
|
updated_at: now,
|
|
dimension: 0,
|
|
branding: 0,
|
|
latitude: 0,
|
|
longitude: 0,
|
|
order_priority: 1,
|
|
archived: false,
|
|
...department,
|
|
});
|
|
|
|
const departmentEnvelope = (departments: Array<Record<string, unknown>>) => ({
|
|
data: departments,
|
|
meta: {
|
|
pagination: {
|
|
page: 1,
|
|
per_page: 100,
|
|
total: departments.length,
|
|
},
|
|
},
|
|
});
|
|
|
|
test.describe("Superuser department archive filter", () => {
|
|
test("shows active departments by default and archived departments only after selecting archived", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
test.skip(!isDesktopProject(testInfo), "Desktop only");
|
|
|
|
const activeDepartments = [buildDepartment({ id: 1, name: "Active North", order_priority: 1, archived: false })];
|
|
const archivedDepartments = [buildDepartment({ id: 2, name: "Archived East", order_priority: 1, archived: true })];
|
|
const departmentFiltersSeen: string[] = [];
|
|
|
|
await page.setViewportSize({ width: 1280, height: 720 });
|
|
await seedAuthenticatedState(page, "superuser-departments-archive-token");
|
|
await mockApi(page, {
|
|
authenticated: true,
|
|
permissions: ["superuser", "user", "list_departments", "superuser_fetch_department", "edit_department"],
|
|
sessionData: {
|
|
group_id: 1,
|
|
},
|
|
});
|
|
|
|
await page.route(
|
|
/https?:\/\/(?:api\.truckwash\.io(?::\d+)?\/departments|localhost(?::\d+)?\/api\/departments|127\.0\.0\.1(?::\d+)?\/api\/departments)(?:\?.*)?$/i,
|
|
async (route) => {
|
|
const request = route.request();
|
|
const url = new URL(request.url());
|
|
|
|
if (request.method() === "PUT") {
|
|
await route.fulfill(json({ data: { message: "Department updated successfully" } }));
|
|
return;
|
|
}
|
|
|
|
const filters = url.searchParams.get("filters") || "";
|
|
departmentFiltersSeen.push(filters);
|
|
const departments = filters.includes("archived:1") ? archivedDepartments : activeDepartments;
|
|
|
|
await route.fulfill(json(departmentEnvelope(departments)));
|
|
}
|
|
);
|
|
|
|
await page.goto("/superuser/departments", { waitUntil: "domcontentloaded" });
|
|
|
|
await expect(page.getByTestId("pagination-reload-actions")).toBeVisible();
|
|
await expect(page.getByTestId("pagination-search-input")).toBeVisible();
|
|
await expect(page.getByTestId("table-labeled-pagination-filters")).toBeVisible();
|
|
await expect(page.getByTestId("superuser-departments-table")).toBeVisible();
|
|
await expect(page.getByTestId("superuser-departments-archive-filter")).toHaveValue("0");
|
|
await expect(page.getByTestId("superuser-departments-row-1")).toContainText("Active North");
|
|
await expect(page.getByTestId("superuser-departments-row-2")).toHaveCount(0);
|
|
|
|
const activeDepartmentActions = page.getByTestId("superuser-department-actions-1");
|
|
await activeDepartmentActions.locator(".action-settings-wheel-trigger").click();
|
|
await expect(page.getByTestId("superuser-department-edit-1")).toBeVisible();
|
|
await expect(page.getByTestId("superuser-department-open-1")).toBeVisible();
|
|
await expect(page.getByTestId("superuser-department-settings-1")).toBeVisible();
|
|
|
|
await page.getByTestId("superuser-departments-archive-filter").selectOption("1");
|
|
|
|
await expect(page.getByTestId("superuser-departments-row-2")).toContainText("Archived East");
|
|
await expect(page.getByTestId("superuser-departments-row-1")).toHaveCount(0);
|
|
expect(departmentFiltersSeen.some((filters) => filters.includes("archived:0"))).toBeTruthy();
|
|
expect(departmentFiltersSeen.some((filters) => filters.includes("archived:1"))).toBeTruthy();
|
|
});
|
|
});
|