mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 23:53:21 +00:00
Empty search waits until the Unassigned queue has settled. Reschedule selects the destination day's page before flashing the row.
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
DAY_PAGE_SIZE_OPTIONS,
|
|
DEFAULT_DAY_PAGE_SIZE,
|
|
findItemPageIndex,
|
|
formatDayPaginationSummary,
|
|
pageIndexForItem,
|
|
paginateItems,
|
|
shouldShowDayPagination,
|
|
} from "@/domain/work-orders/utils/day-pagination";
|
|
|
|
describe("day pagination utils (SH-241)", () => {
|
|
it("defaults to 50 and exposes 25/50/100/200", () => {
|
|
expect(DEFAULT_DAY_PAGE_SIZE).toBe(50);
|
|
expect(DAY_PAGE_SIZE_OPTIONS).toEqual([25, 50, 100, 200]);
|
|
});
|
|
|
|
it("paginates 60 items at 50 per page", () => {
|
|
const items = Array.from({ length: 60 }, (_, index) => index);
|
|
const first = paginateItems(items, 0, 50);
|
|
expect(first.visible).toHaveLength(50);
|
|
expect(first.pageCount).toBe(2);
|
|
const second = paginateItems(items, 1, 50);
|
|
expect(second.visible).toEqual(items.slice(50));
|
|
});
|
|
|
|
it("re-paginates immediately when page size changes", () => {
|
|
const items = Array.from({ length: 60 }, (_, index) => index);
|
|
expect(paginateItems(items, 0, 25).visible).toHaveLength(25);
|
|
expect(paginateItems(items, 0, 25).pageCount).toBe(3);
|
|
});
|
|
|
|
it("clamps an out-of-range page to the last page", () => {
|
|
const paged = paginateItems([1, 2, 3], 9, 2);
|
|
expect(paged.pageIndex).toBe(1);
|
|
expect(paged.visible).toEqual([3]);
|
|
});
|
|
|
|
it("shows pagination in day view even when the page is not full", () => {
|
|
expect(
|
|
shouldShowDayPagination({
|
|
flatListMode: false,
|
|
isLoading: false,
|
|
noSearchResults: false,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("hides pagination in flat-list / loading / empty search", () => {
|
|
expect(
|
|
shouldShowDayPagination({
|
|
flatListMode: true,
|
|
isLoading: false,
|
|
noSearchResults: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldShowDayPagination({
|
|
flatListMode: false,
|
|
isLoading: true,
|
|
noSearchResults: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldShowDayPagination({
|
|
flatListMode: false,
|
|
isLoading: false,
|
|
noSearchResults: true,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("maps a row past the first page onto page 2 at the default size", () => {
|
|
const items = Array.from({ length: 60 }, (_, index) => ({ id: `wo-${index}` }));
|
|
expect(pageIndexForItem(50, 50)).toBe(1);
|
|
expect(findItemPageIndex(items, "wo-55", 50)).toBe(1);
|
|
expect(findItemPageIndex(items, "missing", 50)).toBeNull();
|
|
});
|
|
|
|
it("formats the AAP footer summary", () => {
|
|
expect(formatDayPaginationSummary("Mon · 06/01", 9)).toBe("MON · 06/01 · 9 items");
|
|
expect(formatDayPaginationSummary("Tue · 06/02", 1)).toBe("TUE · 06/02 · 1 item");
|
|
});
|
|
});
|