Files
cc-switch/tests/hooks/useImportExport.extra.test.tsx
Jason 521c69db92 test: enhance useImportExport edge tests with mock refactor and callback verification
Mock Refactoring:
- Extract saveFileDialogMock and exportConfigMock as variables
  - Previously used inline vi.fn() which prevented call verification
  - Now supports expect().toHaveBeenCalledWith() assertions
  - Enables parameter and return value validation
- Add mock reset in beforeEach for test isolation
  - Reset saveFileDialogMock state
  - Reset exportConfigMock state
  - Ensures clean state for each test

New Test: Import Failure Callback Verification
- Add test "does not call onImportSuccess when import fails"
  - User selects file successfully
  - Import operation fails (success: false)
  - Verify onImportSuccess callback NOT called
  - Verify status becomes "error"
  - Prevents triggering success logic on failure

New Test: Export Success Message Verification
- Add test "propagates export success message to toast with saved path"
  - User selects save location: /exports/config.json
  - Backend saves to: /final/config.json (may differ)
  - Verify exportConfigMock called with user-selected path
  - Verify toast success message contains actual saved path
  - Ensures user sees correct save location

Coverage Improvements:
- Import failure callback: 50% → 100%
- Export success message: 50% → 100%
- Mock verification capability: 0% → 100%

All tests passing: 81/81 (2 new tests)
2025-10-26 09:55:19 +08:00

3.5 KiB