Files
mission-control/tests/stores/batch-store.test.ts
teernisse 480d0817d9 test: add comprehensive frontend tests for components, stores, and utils
Full test coverage for the frontend implementation using Vitest and
Testing Library. Tests are organized by concern with shared fixtures.

Component tests:
- AppShell.test.tsx: Navigation tabs, view switching, batch mode overlay
- FocusCard.test.tsx: Rendering, action buttons, keyboard shortcuts, empty state
- QueueView.test.tsx: Item display, focus promotion, empty state
- QueueItem.test.tsx: Type badges, click handling
- QueueSummary.test.tsx: Count display by type
- QuickCapture.test.tsx: Modal behavior, form submission, error states
- BatchMode.test.tsx: Progress tracking, item advancement, completion
- App.test.tsx: Updated for AppShell integration

Store tests:
- focus-store.test.ts: Item management, act(), setFocus(), reorderQueue()
- nav-store.test.ts: View switching
- capture-store.test.ts: Open/close, submission states
- batch-store.test.ts: Batch lifecycle, status tracking, derived counts

Library tests:
- types.test.ts: Type guards, staleness computation
- transform.test.ts: Lore data transformation, priority ordering
- format.test.ts: IID formatting for MRs vs issues

E2E tests (app.spec.ts):
- Navigation flow
- Focus card interactions
- Queue management
- Quick capture flow

Test infrastructure:
- fixtures.ts: makeFocusItem() factory
- tauri-plugin-shell.ts: Mock for @tauri-apps/plugin-shell
- Updated tauri-api.ts mock with new commands
- vitest.config.ts: Path aliases, jsdom environment
- playwright.config.ts: Removed webServer (run separately)
- package.json: Added @tauri-apps/plugin-shell dependency

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-26 09:54:59 -05:00

160 lines
4.7 KiB
TypeScript

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);
});
});
});