mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 09:43:12 +00:00
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
import { BOARD_SEARCH_MAX_PAGE_SIZE } from "@/domain/work-orders/utils/board-query-params";
|
|
|
|
const searchBoard = vi.fn();
|
|
|
|
vi.mock("@/domain/work-orders/api/work-orders-api", () => ({
|
|
workOrdersApi: {
|
|
searchBoard: (...args: unknown[]) => searchBoard(...args),
|
|
},
|
|
}));
|
|
|
|
import { fetchUnassignedBoardPage } from "@/domain/work-orders/api/fetch-unassigned-board-rows";
|
|
|
|
function pageResult(items: Pick<WorkOrderTableRow, "id">[], totalCount: number, page = 0) {
|
|
return {
|
|
items,
|
|
scheduled: [],
|
|
unscheduled: [],
|
|
totalCount,
|
|
returnedCount: items.length,
|
|
page,
|
|
pageSize: BOARD_SEARCH_MAX_PAGE_SIZE,
|
|
};
|
|
}
|
|
|
|
describe("fetchUnassignedBoardPage", () => {
|
|
beforeEach(() => {
|
|
searchBoard.mockReset();
|
|
});
|
|
|
|
it("fetches a single search page instead of exhausting totalCount", async () => {
|
|
const first = Array.from({ length: 50 }, (_, index) => ({ id: `a-${index}` }));
|
|
searchBoard.mockResolvedValueOnce(pageResult(first, 1778, 0));
|
|
|
|
const result = await fetchUnassignedBoardPage(0, 50);
|
|
|
|
expect(searchBoard).toHaveBeenCalledTimes(1);
|
|
expect(searchBoard.mock.calls[0]?.[0]).toMatchObject({
|
|
page: 0,
|
|
pageSize: 50,
|
|
dispatchers: ["__unassigned__"],
|
|
datePreset: "Custom",
|
|
});
|
|
expect(result.items).toHaveLength(50);
|
|
expect(result.totalCount).toBe(1778);
|
|
});
|
|
});
|