Files
cc-switch/tests/integration
Jason 885dd94803 test: extend MCP UI test coverage with wizard, TOML, and error handling
## McpFormModal Component Tests (+5 tests)

### Infrastructure Improvements
- Enhance McpWizardModal mock from null to functional mock with testable onApply callback
- Refactor renderForm helper to support custom onSave/onClose mock injection
- Add McpServer type import for type-safe test data

### New Test Cases
1. **Wizard Integration**: Verify wizard generates config and auto-fills ID + JSON fields
   - Click "Use Wizard" → Apply → Form fields populated with wizard-id and config
   - Uses act() wrapper for React 18 async state updates

2. **TOML Auto-extraction (Codex)**: Test TOML → JSON conversion with ID extraction
   - Parse `[mcp.servers.demo]` → auto-fill ID as "demo"
   - Verify server object correctly parsed from TOML format
   - Codex-specific feature for config.toml compatibility

3. **TOML Validation Error**: Test missing required field handling
   - TOML with type="stdio" but no command → block submit
   - Display localized error toast: mcp.error.idRequired (3s duration)

4. **Edit Mode Immutability**: Verify ID field disabled during edit
   - ID input has disabled attribute and keeps original value
   - Config updates applied while enabled state preserved
   - syncOtherSide defaults to false in edit mode

5. **Error Recovery**: Test save failure button state restoration
   - Inject failing onSave mock → trigger error
   - Verify toast error displays translated message
   - Submit button disabled state resets to false for retry

## useMcpActions Hook Tests (+2 tests)

### New API Mocks
- Add syncEnabledToClaude and syncEnabledToCodex mock functions

### New Test Cases
1. **Backend Error Message Mapping**: Map Chinese error to i18n key
   - Backend: "stdio 类型的 MCP 服务器必须包含 command 字段"
   - Frontend: mcp.error.commandRequired (6s toast duration)

2. **Cross-app Sync Logic**: Verify conditional sync behavior
   - claude → claude: setEnabled called, syncEnabledToClaude NOT called
   - Validates sync only occurs when crossing app types

## Minor Changes
- McpPanel.test.tsx: Add trailing newline (formatter compliance)

## Test Coverage
- Test files: 17 (unchanged)
- Total tests: 112 → 119 (+7, +6.3%)
- Execution time: 3.20s
- All 119 tests passing 
2025-10-26 15:03:05 +08:00
..