feat(01-01): create Zustand store with 6 slices, IPC batcher, and unit tests

- Install zustand 5.x and immer 11.x dependencies
- Create 6 Zustand slices: navigation, company, selection, ui, communication, social
- Create combined store with devtools + immer middleware
- Create IPC event batcher with 50ms debounce window (schedule/flush/dispose)
- Create typed selector hooks for narrow state subscriptions
- Add 14 unit tests covering store initialization, slice behaviors, and batcher timing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 4.6 committed 2026-03-22 01:30:37 -04:00
1 parent a4de64b876
commit 5e9d36c058
13 files changed
+818 -4

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { createEventBatcher } from "@renderer/lib/ipc-batcher";
describe("createEventBatcher", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it("calls callback after windowMs timeout (50ms)", () => {
const callback = vi.fn();
const batcher = createEventBatcher(callback, 50);
batcher.schedule();
expect(callback).not.toHaveBeenCalled();
vi.advanceTimersByTime(50);
expect(callback).toHaveBeenCalledTimes(1);
});
it("coalesces multiple schedule() calls within window into single callback", () => {
const callback = vi.fn();
const batcher = createEventBatcher(callback, 50);
batcher.schedule();
batcher.schedule();
batcher.schedule();
vi.advanceTimersByTime(50);
expect(callback).toHaveBeenCalledTimes(1);
});
it("flush() immediately invokes callback and clears pending timer", () => {
const callback = vi.fn();
const batcher = createEventBatcher(callback, 50);
batcher.schedule();
batcher.flush();
expect(callback).toHaveBeenCalledTimes(1);
// Advancing time should not trigger another callback
vi.advanceTimersByTime(100);
expect(callback).toHaveBeenCalledTimes(1);
});
it("dispose() cancels pending timer without invoking callback", () => {
const callback = vi.fn();
const batcher = createEventBatcher(callback, 50);
batcher.schedule();
batcher.dispose();
vi.advanceTimersByTime(100);
expect(callback).not.toHaveBeenCalled();
});
it("schedule() after flush() starts new timer", () => {
const callback = vi.fn();
const batcher = createEventBatcher(callback, 50);
batcher.schedule();
batcher.flush();
expect(callback).toHaveBeenCalledTimes(1);
batcher.schedule();
vi.advanceTimersByTime(50);
expect(callback).toHaveBeenCalledTimes(2);
});
});