- Add vitest/globals to tsconfig.json types array to provide type
definitions for global test functions (describe, it, expect, vi)
- Fix vi.fn type parameter in useDirectorySettings.test.tsx from
<[], Promise<string>> to <() => Promise<string>>
- Remove unused setMcpConfig import from MSW handlers
- Add type assertions for mock.calls access in McpFormModal tests
to resolve union type inference issues
This ensures pnpm typecheck passes without errors while maintaining
test functionality with vitest globals: true configuration.
## MSW Infrastructure Enhancement
- Add 5 MCP API handlers to tests/msw/handlers.ts:
- get_mcp_config: Fetch MCP configuration for app type
- import_mcp_from_claude/codex: Mock import operations (returns count: 1)
- set_mcp_enabled: Toggle MCP server enabled state
- upsert_mcp_server_in_config: Create/update MCP server
- delete_mcp_server_in_config: Remove MCP server
- Add MCP state management to tests/msw/state.ts:
- McpConfigState type with per-app server storage
- Default test data (stdio server for Claude, http server for Codex)
- CRUD functions: getMcpConfig, setMcpServerEnabled, upsertMcpServer, deleteMcpServer
- Immutable state operations with deep cloning
## McpFormModal Component Tests (4 tests)
- Test preset application: Verify ID and config JSON auto-fill from preset selection
- Test conflict detection: Async validation shows warning when syncing to conflicting ID
- Test field sanitization: Verify trim whitespace, split tags, clean URLs before save
- Test validation errors: Block submit and show toast error for invalid stdio config (missing command)
## McpPanel Integration Tests (3 tests)
- Test toggle enabled state: Click toggle button triggers useMcpActions.toggleEnabled with correct params
- Test create server flow: Open form → submit → saveServer called with syncOtherSide option
- Test delete server flow: Click delete → confirm dialog → deleteServer called with ID
## Test Utilities
- Add createTestQueryClient helper with retry: false for faster test execution
## Test Coverage
- Test files: 15 → 17 (+2)
- Total tests: 105 → 112 (+6.7%)
- All 112 tests passing
- Execution time: 3.15s
SettingsDialog Integration Tests:
- Add test for directory browsing and reset functionality
- Verify app config directory browse/reset flow
- Verify Claude config directory manual change, browse, and reset
- Test multiple directory inputs with getAllByTitle pattern
- Add test for export failure error handling
- User cancels file selection (save_file_dialog returns null)
- Export operation fails (disk full scenario)
- Use server.use() to dynamically override MSW handlers
- Verify toast error messages match i18n keys
MSW Handler Extension:
- Add pick_directory handler to support directory selection API
- Consistent with select_config_directory mock strategy
useSettings Hook Unit Tests:
- Add comprehensive tests for settings save logic
- Test restart flag when app config directory changes
- Test no restart when directory unchanged
- Verify space trimming and empty string to undefined conversion
- Test Claude plugin sync failure tolerance
- Add test for settings reset functionality
- Verify form/language/directories reset with server data
- Use factory functions for mock creation (reusability)
- Complete dependency isolation with mock hooks
All tests passing: 9/9 (5 integration + 4 unit tests)
Major testing infrastructure upgrade from manual mocks to Mock Service Worker (MSW):
New MSW infrastructure (tests/msw/):
- Add state.ts: In-memory state manager with full CRUD operations
- Manage providers and current selections per app type (Claude/Codex)
- Auto-switch current provider when deleted
- Deep clone to prevent reference pollution
- Add handlers.ts: HTTP request handlers for 10 Tauri API endpoints
- Mock get_providers, switch_provider, add/update/delete_provider
- Mock update_sort_order, update_tray_menu, import_default_config
- Support error scenarios (404 for non-existent providers)
- Add tauriMocks.ts: Tauri API mock layer
- Transparently convert invoke() calls to HTTP requests
- Mock event listener system with emitTauriEvent helper
- Use cross-fetch for Node.js environment
- Add server.ts: MSW server setup for Node.js test environment
Refactor App.test.tsx (-170 lines, -43%):
- Remove 23 manual mocks (useProvidersQuery, useProviderActions, etc.)
- Run real hooks with MSW-backed API calls instead of mock implementations
- Test real state changes instead of mock call counts
- Add comprehensive flow: duplicate → create → edit → delete → event listening
- Verify actual provider list changes and current selection updates
Setup integration:
- Add MSW server lifecycle to tests/setupTests.ts
- Start server before all tests
- Reset handlers and state after each test
- Close server after all tests complete
- Clear all mocks in afterEach for test isolation
Dependencies:
- Add msw@^2.11.6 for API mocking
- Add cross-fetch@^4.1.0 for fetch polyfill in Node.js
Type fixes:
- Add missing imports (AppType, Provider) in handlers.ts
- Fix HttpResponse.json generic constraint with as any (MSW best practice)
- Change invalid category "default" to "official" in state.ts
Test results: All 50 tests passing across 8 files, 0 TypeScript errors