import { describe, it, expect, beforeEach } from "vitest"; import { useBatchStore } from "@/stores/batch-store"; import { makeFocusItem } from "../helpers/fixtures"; describe("useBatchStore", () => { beforeEach(() => { useBatchStore.getState().exitBatch(); }); describe("startBatch", () => { it("activates batch mode with items", () => { const items = [ makeFocusItem({ id: "r1", title: "Review A" }), makeFocusItem({ id: "r2", title: "Review B" }), makeFocusItem({ id: "r3", title: "Review C" }), ]; useBatchStore.getState().startBatch(items, "CODE REVIEWS"); const state = useBatchStore.getState(); expect(state.isActive).toBe(true); expect(state.batchLabel).toBe("CODE REVIEWS"); expect(state.items).toHaveLength(3); expect(state.statuses).toEqual(["pending", "pending", "pending"]); expect(state.currentIndex).toBe(0); expect(state.startedAt).toBeGreaterThan(0); }); it("initializes with zero completed and skipped", () => { useBatchStore.getState().startBatch( [makeFocusItem({ id: "r1" })], "TEST" ); const state = useBatchStore.getState(); expect(state.completedCount()).toBe(0); expect(state.skippedCount()).toBe(0); expect(state.isFinished()).toBe(false); }); }); describe("markDone", () => { it("marks current item as done and advances", () => { useBatchStore.getState().startBatch( [ makeFocusItem({ id: "r1" }), makeFocusItem({ id: "r2" }), makeFocusItem({ id: "r3" }), ], "TEST" ); useBatchStore.getState().markDone(); const state = useBatchStore.getState(); expect(state.statuses[0]).toBe("done"); expect(state.currentIndex).toBe(1); expect(state.completedCount()).toBe(1); }); it("finishes when last item is marked done", () => { useBatchStore.getState().startBatch( [makeFocusItem({ id: "r1" }), makeFocusItem({ id: "r2" })], "TEST" ); useBatchStore.getState().markDone(); useBatchStore.getState().markDone(); const state = useBatchStore.getState(); expect(state.completedCount()).toBe(2); expect(state.isFinished()).toBe(true); }); }); describe("markSkipped", () => { it("marks current item as skipped and advances", () => { useBatchStore.getState().startBatch( [makeFocusItem({ id: "r1" }), makeFocusItem({ id: "r2" })], "TEST" ); useBatchStore.getState().markSkipped(); const state = useBatchStore.getState(); expect(state.statuses[0]).toBe("skipped"); expect(state.currentIndex).toBe(1); expect(state.skippedCount()).toBe(1); }); it("mixed done and skipped tracks correctly", () => { useBatchStore.getState().startBatch( [ makeFocusItem({ id: "r1" }), makeFocusItem({ id: "r2" }), makeFocusItem({ id: "r3" }), ], "TEST" ); useBatchStore.getState().markDone(); useBatchStore.getState().markSkipped(); useBatchStore.getState().markDone(); const state = useBatchStore.getState(); expect(state.completedCount()).toBe(2); expect(state.skippedCount()).toBe(1); expect(state.isFinished()).toBe(true); }); }); describe("exitBatch", () => { it("clears all batch state", () => { useBatchStore.getState().startBatch( [makeFocusItem({ id: "r1" })], "TEST" ); useBatchStore.getState().markDone(); useBatchStore.getState().exitBatch(); const state = useBatchStore.getState(); expect(state.isActive).toBe(false); expect(state.items).toHaveLength(0); expect(state.statuses).toHaveLength(0); expect(state.currentIndex).toBe(0); expect(state.startedAt).toBeNull(); }); }); describe("progress tracking", () => { it("reports correct progress through batch", () => { useBatchStore.getState().startBatch( [ makeFocusItem({ id: "r1" }), makeFocusItem({ id: "r2" }), makeFocusItem({ id: "r3" }), makeFocusItem({ id: "r4" }), ], "REVIEWS" ); expect(useBatchStore.getState().isFinished()).toBe(false); useBatchStore.getState().markDone(); useBatchStore.getState().markDone(); expect(useBatchStore.getState().completedCount()).toBe(2); expect(useBatchStore.getState().isFinished()).toBe(false); useBatchStore.getState().markSkipped(); useBatchStore.getState().markDone(); expect(useBatchStore.getState().completedCount()).toBe(3); expect(useBatchStore.getState().skippedCount()).toBe(1); expect(useBatchStore.getState().isFinished()).toBe(true); }); }); });