Commit Graph

4 Commits

  • feat(settings): add autoSaveSettings for lightweight auto-save
    Add optimized auto-save function for General tab settings.
    - Add autoSaveSettings method for non-destructive auto-save
    - Only trigger system APIs when values actually change
    - Avoid unnecessary auto-launch and plugin config updates
    - Update tests to cover new functionality
  • test: update test suites to match component refactoring
    Comprehensive test updates to align with recent component refactoring
    and new auto-launch functionality.
    
    Component Tests:
    - AddProviderDialog.test.tsx (10 lines):
      * Updated test cases for new dialog behavior
      * Enhanced mock data for preset selection
      * Improved assertions for validation
    
    - ImportExportSection.test.tsx (16 lines):
      * Updated for new settings page integration
      * Enhanced test coverage for error scenarios
      * Better mock state management
    
    - McpFormModal.test.tsx (60 lines):
      * Extensive updates for form refactoring
      * New test cases for multi-app selection
      * Enhanced validation testing
      * Better coverage of stdio/http server types
    
    - ProviderList.test.tsx (11 lines):
      * Updated for new card layout
      * Enhanced drag-and-drop testing
    
    - SettingsDialog.test.tsx (96 lines):
      * Major updates for SettingsPage migration
      * New test cases for auto-launch functionality
      * Enhanced integration test coverage
      * Better async operation testing
    
    Hook Tests:
    - useDirectorySettings.test.tsx (32 lines):
      * Updated for refactored hook logic
      * Enhanced test coverage for edge cases
    
    - useDragSort.test.tsx (36 lines):
      * Simplified test cases
      * Better mock implementation
      * Improved assertions
    
    - useImportExport tests (16 lines total):
      * Updated for new error handling
      * Enhanced test coverage
    
    - useMcpValidation.test.tsx (23 lines):
      * Updated validation test cases
      * Better coverage of error scenarios
    
    - useProviderActions.test.tsx (48 lines):
      * Extensive updates for hook refactoring
      * New test cases for provider operations
      * Enhanced mock data
    
    - useSettings.test.tsx (12 lines):
      * New test cases for auto-launch
      * Enhanced settings state testing
      * Better async operation coverage
    
    Integration Tests:
    - App.test.tsx (41 lines):
      * Updated for new routing logic
      * Enhanced navigation testing
      * Better component integration coverage
    
    - SettingsDialog.test.tsx (88 lines):
      * Complete rewrite for SettingsPage
      * New integration test scenarios
      * Enhanced user workflow testing
    
    Mock Infrastructure:
    - handlers.ts (117 lines):
      * Major updates for MSW handlers
      * New handlers for auto-launch commands
      * Enhanced error simulation
      * Better request/response mocking
    
    - state.ts (37 lines):
      * Updated mock state structure
      * New state for auto-launch
      * Enhanced state reset functionality
    
    - tauriMocks.ts (10 lines):
      * Updated mock implementations
      * Better type safety
    
    - server.ts & testQueryClient.ts:
      * Minor cleanup (2 lines removed)
    
    Test Infrastructure Improvements:
    - Better test isolation
    - Enhanced mock data consistency
    - Improved async operation testing
    - Better error scenario coverage
    - Enhanced integration test patterns
    
    Coverage Improvements:
    - Net increase of 195 lines of test code
    - Better coverage of edge cases
    - Enhanced error path testing
    - Improved integration test scenarios
    - Better mock infrastructure
    
    All tests now pass with the refactored components while maintaining
    comprehensive coverage of functionality and edge cases.
  • fix: resolve TypeScript type errors in test files
    - 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.
  • test: add useDirectorySettings and useSettingsMetadata hook tests
    useDirectorySettings Tests:
    - Test directory initialization with overrides and remote defaults
      - Verify app config override with space trimming
      - Load Claude/Codex directories from remote API
      - Calculate resolvedDirs correctly
    - Test directory browsing functionality
      - Browse Claude/Codex config directories
      - Browse app config directory with proper default paths
      - Update settings callback when selection succeeds
    - Test error handling scenarios
      - User cancels directory selection (returns null)
      - Directory picker throws error (shows toast)
      - Verify settings not updated on failure
    - Test directory reset operations
      - Reset individual directories to computed defaults
      - Reset app config directory
      - Batch reset with provided server values
    - Use vi.hoisted() for proper mock initialization
    - Factory function for settings creation (reusability)
    
    useSettingsMetadata Tests:
    - Test portable mode flag loading
      - Verify initial loading state
      - Load portable flag from API
      - Handle async state transitions
    - Test error tolerance when API fails
      - Silent failure on network errors
      - Default to non-portable mode
      - Continue without blocking UI
    - Test restart flag management
      - Set restart required flag
      - Acknowledge restart to clear flag
      - State updates wrapped in act()
    
    All tests passing: 10/10 (7 useDirectorySettings + 3 useSettingsMetadata)