Commit Graph

4 Commits

  • refactor(types): rename AppType to AppId for semantic clarity
    Rename `AppType` to `AppId` across the entire frontend codebase to better
    reflect its purpose as an application identifier rather than a type category.
    This aligns frontend naming with backend command parameter conventions.
    
    Changes:
    - Rename type `AppType` to `AppId` in src/lib/api/types.ts
    - Remove `AppType` export from src/lib/api/index.ts
    - Update all component props from `appType` to `appId` (43 files)
    - Update all variable names from `appType` to `appId`
    - Synchronize documentation (CHANGELOG, refactoring plans)
    - Update test files and MSW mocks
    
    BREAKING CHANGE: `AppType` type is no longer exported. Use `AppId` instead.
    All component props have been renamed from `appType` to `appId`.
  • test: add SettingsDialog integration tests and enhance MSW infrastructure
    - Add comprehensive SettingsDialog integration tests with 3 test cases:
      * Load default settings from MSW
      * Import configuration and trigger success callback
      * Save settings and handle restart prompt
    - Extend MSW handlers with settings-related endpoints:
      * get_settings/save_settings for settings management
      * app_config_dir_override for custom config directory
      * apply_claude_plugin_config for plugin integration
      * import/export config file operations
      * file/directory dialog mocks
    - Add settings state management to MSW mock state:
      * Settings state with default values
      * appConfigDirOverride state
      * Reset logic in resetProviderState()
    - Mock @tauri-apps/api/path for DirectorySettings tests
    - Refactor App.test.tsx to focus on happy path scenarios:
      * Remove delete functionality test (covered in useProviderActions unit tests)
      * Reorganize test flow: settings → switch → usage → create → edit → switch → duplicate
      * Remove unnecessary state verifications
      * Simplify event testing
    
    All tests passing: 4 integration tests + 12 unit tests
  • test: migrate to MSW testing architecture for App integration test
    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
  • test: enhance SettingsDialog tests and add App integration test
    Enhanced SettingsDialog component test coverage:
    - Add test for import/export status reset on dialog open
    - Add test for onImportSuccess callback propagation to hook
    - Add test for postponing restart flow (restart later button)
    - Add test for directory management callbacks (browse/reset/change)
    - Expand existing test to cover export, import, and clear actions
    - Fix type safety issues (avoid 'as any', use type guards)
    
    New App.test.tsx integration test:
    - Add comprehensive end-to-end test for main App component
    - Test settings dialog with import success callback and tray menu update
    - Test app switcher between Claude and Codex
    - Test provider CRUD operations (add, edit, delete, duplicate)
    - Test usage script modal workflow
    - Test external website link opening
    - Use vi.hoisted() pattern for centralized mock management
    
    Technical improvements:
    - Remove two environment-dependent tests (DEV flag) that required 'as any'
    - Use proper type guards for optional callback invocation
    - Clean up unused mock variables (switchProviderMock, onImportSuccessMock, refetchPromise)
    - Simplify useProviderActions mock to avoid spread argument type error
    
    Test results: 50 tests passing across 8 test files