mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 06:13:12 +00:00
52 lines
1.6 KiB
TypeScript
52 lines
1.6 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 { fetchUnassignedBoardRows } from "@/domain/work-orders/api/fetch-unassigned-board-rows";
|
|
|
|
function pageResult(items: Pick<WorkOrderTableRow, "id">[], totalCount: number) {
|
|
return {
|
|
items,
|
|
scheduled: [],
|
|
unscheduled: [],
|
|
totalCount,
|
|
returnedCount: items.length,
|
|
page: 0,
|
|
pageSize: BOARD_SEARCH_MAX_PAGE_SIZE,
|
|
};
|
|
}
|
|
|
|
describe("fetchUnassignedBoardRows", () => {
|
|
beforeEach(() => {
|
|
searchBoard.mockReset();
|
|
});
|
|
|
|
it("pages until totalCount is exhausted", async () => {
|
|
const first = Array.from({ length: BOARD_SEARCH_MAX_PAGE_SIZE }, (_, index) => ({
|
|
id: `a-${index}`,
|
|
}));
|
|
const second = [{ id: "b-0" }];
|
|
searchBoard
|
|
.mockResolvedValueOnce(pageResult(first, 101))
|
|
.mockResolvedValueOnce(pageResult(second, 101));
|
|
|
|
const rows = await fetchUnassignedBoardRows();
|
|
|
|
expect(searchBoard).toHaveBeenCalledTimes(2);
|
|
expect(searchBoard.mock.calls[0]?.[0]).toMatchObject({
|
|
page: 0,
|
|
dispatchers: ["__unassigned__"],
|
|
datePreset: "Custom",
|
|
});
|
|
expect(searchBoard.mock.calls[1]?.[0]).toMatchObject({ page: 1 });
|
|
expect(rows).toHaveLength(101);
|
|
});
|
|
});
|