shoc-frontend-new/src/test/domain/work-orders/dashboard-drilldown-params.test.ts
Codex Review Integration 0279cfac64 feat(dashboard): paginate dispatcher tables and fix Aveta drilldown
Workload and Performance page server-side at 10 rows and now return Page,
PageSize, and TotalDispatchers on dev (backend#126/#127), so wire the pager
that SH-346 and SH-347 require: getWorkload/getPerformance send a 1-based
`page` and parse the paging envelope, the hooks and query keys carry the page,
and each dispatcher table renders a 10-row pager. Page state is per-table and
resets on a range change so switching range never lands on an out-of-range
empty page that reads as a false "no dispatchers" state.

Drop `docs=No` from the Aveta Pending drilldown. `docs` filters on
completion-document status, not the Aveta clearance document the tile counts
(SH-294 / backend#138), so it narrowed to the wrong rows. The board has no
missing-Aveta-document filter, so the drilldown is now the Aveta-required work
in the two-day open window — a deliberate superset of the count.
2026-09-17 00:36:55 -03:00

62 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { parseDashboardDrilldownParams } from "@/domain/work-orders/utils/dashboard-drilldown-params";
import { avetaPendingDrilldownSearch } from "@/domain/dashboard/utils/work-order-drilldown-links";
describe("parseDashboardDrilldownParams", () => {
it("returns null when no recognized param is present", () => {
expect(parseDashboardDrilldownParams(new URLSearchParams())).toBeNull();
expect(
parseDashboardDrilldownParams(new URLSearchParams({ dateFrom: "2026-09-16" })),
).toBeNull();
expect(parseDashboardDrilldownParams(new URLSearchParams({ aveta: "0" }))).toBeNull();
});
it("maps dates to a custom advanced-filter range", () => {
const filters = parseDashboardDrilldownParams(
new URLSearchParams({ dateFrom: "2026-09-14", dateTo: "2026-09-18" }),
);
expect(filters).not.toBeNull();
expect(filters?.dateRange).toBe("custom");
expect(filters?.customFrom).toBe("2026-09-14");
expect(filters?.customTo).toBe("2026-09-18");
});
it("parses the Aveta Pending drilldown and drops unknown statuses", () => {
const params = avetaPendingDrilldownSearch("2026-09-16");
params.append("statuses", "NotAStatus");
const filters = parseDashboardDrilldownParams(params);
expect(filters).not.toBeNull();
expect(filters?.avetaOnly).toBe(true);
// The Aveta drilldown no longer sends `docs=No` (completion-doc status), so
// no completion-document filter is applied.
expect(filters?.docs.size).toBe(0);
expect(filters?.statuses).not.toBeNull();
expect([...(filters?.statuses ?? [])]).not.toContain("Completed");
expect([...(filters?.statuses ?? [])]).not.toContain("NotAStatus");
expect(filters?.statuses.has("Scheduled")).toBe(true);
expect(filters?.statuses.has("Pending Quote")).toBe(true);
});
it("parses dispatcher and uplift params", () => {
const filters = parseDashboardDrilldownParams(
new URLSearchParams({
dispatchers: " 12 , 13",
upliftStatuses: "pending,bogus",
}),
);
expect(filters?.dispatchers).toEqual(new Set(["12", "13"]));
expect(filters?.hasUplift).toBe(true);
expect(filters?.upliftStatuses).toEqual(new Set(["pending"]));
});
it("rejects partial or malformed date ranges", () => {
expect(
parseDashboardDrilldownParams(
new URLSearchParams({ dateFrom: "2026-9-16", dateTo: "2026-09-18" }),
),
).toBeNull();
});
});