import { getPaginationState } from "../pagination"; // The component module imports view-layer deps (`@expo/vector-icons`, // `react-native-reanimated` via Button) that the unit-suite babel transform // does not process. The shared setup stubs `react-native` / `nativewind`; // stub the rest here so the pure helper under test loads without a render // runtime. `jest.mock` is hoisted above the import by babel-plugin-jest-hoist // (same pattern as the existing context tests). jest.mock("@expo/vector-icons", () => ({ Ionicons: "Ionicons" })); jest.mock("react-native-reanimated", () => ({ __esModule: true, default: { View: "Animated.View" }, useSharedValue: () => ({ value: 0 }), useAnimatedStyle: () => ({}), withTiming: (v: number) => v, })); describe("getPaginationState", () => { it("derives total pages and item range from page/size/total", () => { const s = getPaginationState(1, 10, 25); expect(s.totalPages).toBe(3); expect(s.currentPage).toBe(1); expect(s.rangeStart).toBe(1); expect(s.rangeEnd).toBe(10); }); it("computes the trailing partial-page range", () => { const s = getPaginationState(3, 10, 25); expect(s.currentPage).toBe(3); expect(s.rangeStart).toBe(21); expect(s.rangeEnd).toBe(25); }); it("disables prev on the first page", () => { const s = getPaginationState(1, 10, 25); expect(s.canPrev).toBe(false); expect(s.canNext).toBe(true); }); it("disables next on the last page", () => { const s = getPaginationState(3, 10, 25); expect(s.canNext).toBe(false); expect(s.canPrev).toBe(true); }); it("disables both controls when a single page holds everything", () => { const s = getPaginationState(1, 10, 4); expect(s.totalPages).toBe(1); expect(s.canPrev).toBe(false); expect(s.canNext).toBe(false); }); it("reports an empty range with no items but still one page", () => { const s = getPaginationState(1, 10, 0); expect(s.totalPages).toBe(1); expect(s.rangeStart).toBe(0); expect(s.rangeEnd).toBe(0); expect(s.canPrev).toBe(false); expect(s.canNext).toBe(false); }); it("clamps an out-of-range page up or down", () => { expect(getPaginationState(99, 10, 25).currentPage).toBe(3); expect(getPaginationState(-5, 10, 25).currentPage).toBe(1); expect(getPaginationState(0, 10, 25).currentPage).toBe(1); }); it("tolerates degenerate page sizes by flooring to at least one", () => { const s = getPaginationState(1, 0, 5); expect(s.totalPages).toBe(5); expect(s.rangeEnd).toBe(1); }); });