Commit Graph

4 Commits

Author SHA1 Message Date
teernisse
c32a71a0b0 test: add persistence test for nav store and update test setup
Adds test coverage for the navigation store's localStorage persistence
and ensures clean state between tests.

Changes:
- nav-store.test.ts: Add persistence test verifying activeView is saved
- Clear localStorage in beforeEach to prevent test pollution

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-26 09:55:48 -05:00
teernisse
7404acdfb4 feat: add Tauri event hook and lore.db file watcher
Adds real-time updates when lore syncs new GitLab data by watching
the lore.db file for changes.

React hook (src/hooks/useTauriEvents.ts):
- useTauriEvent(): Subscribe to a single Tauri event with auto-cleanup
- useTauriEvents(): Subscribe to multiple events with a handler map
- Typed payloads for each event type:
  - global-shortcut-triggered: toggle-window | quick-capture
  - lore-data-changed: void (refresh trigger)
  - sync-status: started | completed | failed
  - error-notification: code + message

Rust watcher (src-tauri/src/watcher.rs):
- Watches lore's data directory for lore.db modifications
- Uses notify crate with 2-second poll interval
- Emits "lore-data-changed" event to frontend on file change
- Handles atomic writes by watching parent directory
- Gracefully handles missing lore.db (logs warning, skips watcher)

Test coverage:
- Hook subscription and cleanup behavior
- Focus store test fix: clear localStorage before each test

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-26 09:55:30 -05:00
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
teernisse
c8854e59e9 test: add test infrastructure with Vitest and Playwright
Set up comprehensive testing infrastructure for both unit and E2E tests:

Unit Testing (Vitest):
- vitest.config.ts: jsdom environment, globals enabled
  - Path alias @tauri-apps/api -> tests/mocks/tauri-api.ts
  - Excludes tests/e2e/** to prevent Playwright collision
  - V8 coverage configured for src/**/*.{ts,tsx}
- tests/setup.ts: @testing-library/jest-dom matchers

Tauri API Mocking:
- tests/mocks/tauri-api.ts: Mock implementation of @tauri-apps/api
  - invoke(): Returns configurable mock responses
  - listen()/emit(): Event system stubs
  - setMockResponse()/resetMocks(): Test helpers
  - Enables testing React components without Tauri runtime

Component Tests:
- tests/components/App.test.tsx: Verifies App shell renders
  - "Mission Control" heading
  - "What should you be doing right now?" tagline
  - "THE ONE THING will appear here" placeholder

E2E Testing (Playwright):
- playwright.config.ts: Chromium + WebKit (Tauri uses WebKit on macOS)
  - Runs Vite dev server before tests
  - HTML reporter, trace on retry
- tests/e2e/app.spec.ts: Smoke tests for deployed app
  - Heading visible, tagline visible, dark mode applied

This dual-layer testing strategy (Vitest for speed, Playwright for
integration) follows the testing trophy: many unit, fewer E2E.
2026-02-25 17:01:51 -05:00