Add archived department filtering feature for superusers, including E2E tests, UI updates, and OpenAPI enhancements. Extend department table with archived toggle switch and update translations.
This commit is contained in:
@@ -9,6 +9,7 @@ const adminPermissions = [
|
||||
"department_access_2",
|
||||
"department_access_3",
|
||||
"department_access_4",
|
||||
"department_access_5",
|
||||
];
|
||||
|
||||
const defaultDepartments = [
|
||||
@@ -16,6 +17,7 @@ const defaultDepartments = [
|
||||
{ id: 2, name: "Hidden South", visible: false },
|
||||
{ id: 3, name: "Legacy East" },
|
||||
{ id: 4, name: "Numeric Hidden", visible: 0 },
|
||||
{ id: 5, name: "Archived West", visible: true, archived: true },
|
||||
];
|
||||
|
||||
const json = (body: unknown, status = 200) => ({
|
||||
@@ -180,6 +182,7 @@ test.describe("Admin department visibility", () => {
|
||||
await expect(departmentControls.getByRole("button", { name: "Legacy East" })).toBeVisible();
|
||||
await expect(departmentControls.getByRole("button", { name: "Hidden South" })).toHaveCount(0);
|
||||
await expect(departmentControls.getByRole("button", { name: "Numeric Hidden" })).toHaveCount(0);
|
||||
await expect(departmentControls.getByRole("button", { name: "Archived West" })).toHaveCount(0);
|
||||
|
||||
if (isDesktopProject(test.info())) {
|
||||
const desktopDepartmentSelect = page.getByTestId("desktop-header-department-select");
|
||||
@@ -187,6 +190,7 @@ test.describe("Admin department visibility", () => {
|
||||
await expect(desktopDepartmentSelect.locator("option", { hasText: "Legacy East" })).toHaveCount(1);
|
||||
await expect(desktopDepartmentSelect.locator("option", { hasText: "Hidden South" })).toHaveCount(0);
|
||||
await expect(desktopDepartmentSelect.locator("option", { hasText: "Numeric Hidden" })).toHaveCount(0);
|
||||
await expect(desktopDepartmentSelect.locator("option", { hasText: "Archived West" })).toHaveCount(0);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
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");
|
||||
|
||||
await expect(page.getByTestId("pagination-reload-actions")).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);
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user