Commit Graph

2 Commits

  • test: add error handling and edge case tests for hooks
    useSettings Tests:
    - Add test for null settings state protection
      - Returns null immediately without calling APIs
      - Prevents null pointer errors in save flow
    - Add test for save mutation failure
      - Verifies error propagates to caller
      - Ensures restart flag remains untouched on failure
      - Validates no side effects when save fails
    
    useProviderActions Tests:
    - Add error propagation tests for CRUD operations
      - updateProvider: propagates errors to caller
      - addProvider: propagates errors to caller
      - deleteProvider: propagates errors to caller
    - Add switch mutation error handling tests
      - Claude switch: handles errors silently (no throw)
      - Codex switch: skips plugin sync when mutation fails
      - Verifies plugin sync APIs not called on failure
    - Add loading state verification
      - Test all mutations pending scenario (existing)
      - Test all mutations idle scenario (new)
      - Ensures isLoading flag accuracy
    
    useImportExport Edge Case Tests (new file):
    - Add test for user cancelling file dialog
      - File dialog returns null (user cancelled)
      - State remains unchanged (selectedFile: "", status: "idle")
      - No error toast shown
    - Add test for resetStatus behavior
      - Clears error message and status
      - Preserves selected file path for retry
      - Resets backupId to null
    
    All tests passing: 79/79 (10 new tests)
  • test: add directory browsing/reset and useSettings hook tests
    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)