Commit Graph

3 Commits

  • 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: 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 
  • test: add comprehensive MCP UI test coverage with MSW infrastructure
    ## MSW Infrastructure Enhancement
    - Add 5 MCP API handlers to tests/msw/handlers.ts:
      - get_mcp_config: Fetch MCP configuration for app type
      - import_mcp_from_claude/codex: Mock import operations (returns count: 1)
      - set_mcp_enabled: Toggle MCP server enabled state
      - upsert_mcp_server_in_config: Create/update MCP server
      - delete_mcp_server_in_config: Remove MCP server
    - Add MCP state management to tests/msw/state.ts:
      - McpConfigState type with per-app server storage
      - Default test data (stdio server for Claude, http server for Codex)
      - CRUD functions: getMcpConfig, setMcpServerEnabled, upsertMcpServer, deleteMcpServer
      - Immutable state operations with deep cloning
    
    ## McpFormModal Component Tests (4 tests)
    - Test preset application: Verify ID and config JSON auto-fill from preset selection
    - Test conflict detection: Async validation shows warning when syncing to conflicting ID
    - Test field sanitization: Verify trim whitespace, split tags, clean URLs before save
    - Test validation errors: Block submit and show toast error for invalid stdio config (missing command)
    
    ## McpPanel Integration Tests (3 tests)
    - Test toggle enabled state: Click toggle button triggers useMcpActions.toggleEnabled with correct params
    - Test create server flow: Open form → submit → saveServer called with syncOtherSide option
    - Test delete server flow: Click delete → confirm dialog → deleteServer called with ID
    
    ## Test Utilities
    - Add createTestQueryClient helper with retry: false for faster test execution
    
    ## Test Coverage
    - Test files: 15 → 17 (+2)
    - Total tests: 105 → 112 (+6.7%)
    - All 112 tests passing
    - Execution time: 3.15s