mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-06-16 13:34:04 +08:00
refactor/ui
10 Commits
-
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.
YoVinchen ·
2025-11-21 11:12:06 +08:00 -
refactor(mcp): complete v3.7.0 cleanup - remove legacy code and warnings
This commit finalizes the v3.7.0 unified MCP architecture migration by removing all deprecated code paths and eliminating compiler warnings. Frontend Changes (~950 lines removed): - Remove deprecated components: McpPanel, McpListItem, McpToggle - Remove deprecated hook: useMcpActions - Remove unused API methods: importFrom*, syncEnabledTo*, syncAllServers - Simplify McpFormModal by removing dual-mode logic (unified/legacy) - Remove syncOtherSide checkbox and conflict detection - Clean up unused imports and state variables - Delete associated test files Backend Changes (~400 lines cleaned): - Remove unused Tauri commands: import_mcp_from_*, sync_enabled_mcp_to_* - Delete unused Gemini MCP functions: get_mcp_status, upsert/delete_mcp_server - Add #[allow(deprecated)] to compatibility layer commands - Add #[allow(dead_code)] to legacy helper functions for future migration - Simplify boolean expression in mcp.rs per Clippy suggestion API Deprecation: - Mark legacy APIs with @deprecated JSDoc (getConfig, upsertServerInConfig, etc.) - Preserve backward compatibility for v3.x, planned removal in v4.0 Verification: - ✅ Zero TypeScript errors (pnpm typecheck) - ✅ Zero Clippy warnings (cargo clippy) - ✅ All code formatted (prettier + cargo fmt) - ✅ Builds successfully Total cleanup: ~1,350 lines of code removed/marked Breaking changes: None (all legacy APIs still functional)
Jason ·
2025-11-14 22:43:25 +08:00 -
feat(frontend): implement unified MCP panel for v3.7.0
Complete Phase 3 (P0) frontend implementation for unified MCP management: **New Files:** - src/hooks/useMcp.ts: React Query hooks for unified MCP operations - src/components/mcp/UnifiedMcpPanel.tsx: Unified MCP management panel - src/components/ui/checkbox.tsx: Checkbox component from shadcn/ui **Features:** - Unified panel with three-column layout: server info + app checkboxes + actions - Multi-app control: Claude/Codex/Gemini checkboxes for each server - Real-time stats: Show enabled server counts per app - Full CRUD operations: Add, edit, delete, sync all servers **Integration:** - Replace old app-specific McpPanel with UnifiedMcpPanel in App.tsx - Update McpFormModal to support unified mode with apps field - Add i18n support: mcp.unifiedPanel namespace (zh/en) **Type Safety:** - Ensure McpServer.apps field always initialized - Fix all test files to include apps field - TypeScript type check passes ✅ **Architecture:** - Single source of truth: mcp.servers manages all MCP configs - Per-server app control: apps.claude/codex/gemini boolean flags - Backward compatible: McpFormModal supports both unified and legacy modes Next: P1 tasks (import dialogs, sub-components, tests)Jason ·
2025-11-14 15:24:48 +08:00 -
refactor(types): rename AppType to AppId for semantic clarity
Rename `AppType` to `AppId` across the entire frontend codebase to better reflect its purpose as an application identifier rather than a type category. This aligns frontend naming with backend command parameter conventions. Changes: - Rename type `AppType` to `AppId` in src/lib/api/types.ts - Remove `AppType` export from src/lib/api/index.ts - Update all component props from `appType` to `appId` (43 files) - Update all variable names from `appType` to `appId` - Synchronize documentation (CHANGELOG, refactoring plans) - Update test files and MSW mocks BREAKING CHANGE: `AppType` type is no longer exported. Use `AppId` instead. All component props have been renamed from `appType` to `appId`.
Jason ·
2025-10-30 14:59:15 +08:00 -
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 ✅Jason ·
2025-10-26 15:03:05 +08:00 -
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
Jason ·
2025-10-26 13:52:42 +08:00 -
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)
Jason ·
2025-10-25 20:43:47 +08:00 -
test: add SettingsDialog integration tests and enhance MSW infrastructure
- Add comprehensive SettingsDialog integration tests with 3 test cases: * Load default settings from MSW * Import configuration and trigger success callback * Save settings and handle restart prompt - Extend MSW handlers with settings-related endpoints: * get_settings/save_settings for settings management * app_config_dir_override for custom config directory * apply_claude_plugin_config for plugin integration * import/export config file operations * file/directory dialog mocks - Add settings state management to MSW mock state: * Settings state with default values * appConfigDirOverride state * Reset logic in resetProviderState() - Mock @tauri-apps/api/path for DirectorySettings tests - Refactor App.test.tsx to focus on happy path scenarios: * Remove delete functionality test (covered in useProviderActions unit tests) * Reorganize test flow: settings → switch → usage → create → edit → switch → duplicate * Remove unnecessary state verifications * Simplify event testing All tests passing: 4 integration tests + 12 unit tests
Jason ·
2025-10-25 19:59:31 +08:00 -
test: migrate to MSW testing architecture for App integration test
Major testing infrastructure upgrade from manual mocks to Mock Service Worker (MSW): New MSW infrastructure (tests/msw/): - Add state.ts: In-memory state manager with full CRUD operations - Manage providers and current selections per app type (Claude/Codex) - Auto-switch current provider when deleted - Deep clone to prevent reference pollution - Add handlers.ts: HTTP request handlers for 10 Tauri API endpoints - Mock get_providers, switch_provider, add/update/delete_provider - Mock update_sort_order, update_tray_menu, import_default_config - Support error scenarios (404 for non-existent providers) - Add tauriMocks.ts: Tauri API mock layer - Transparently convert invoke() calls to HTTP requests - Mock event listener system with emitTauriEvent helper - Use cross-fetch for Node.js environment - Add server.ts: MSW server setup for Node.js test environment Refactor App.test.tsx (-170 lines, -43%): - Remove 23 manual mocks (useProvidersQuery, useProviderActions, etc.) - Run real hooks with MSW-backed API calls instead of mock implementations - Test real state changes instead of mock call counts - Add comprehensive flow: duplicate → create → edit → delete → event listening - Verify actual provider list changes and current selection updates Setup integration: - Add MSW server lifecycle to tests/setupTests.ts - Start server before all tests - Reset handlers and state after each test - Close server after all tests complete - Clear all mocks in afterEach for test isolation Dependencies: - Add msw@^2.11.6 for API mocking - Add cross-fetch@^4.1.0 for fetch polyfill in Node.js Type fixes: - Add missing imports (AppType, Provider) in handlers.ts - Fix HttpResponse.json generic constraint with as any (MSW best practice) - Change invalid category "default" to "official" in state.ts Test results: All 50 tests passing across 8 files, 0 TypeScript errors
Jason ·
2025-10-25 16:48:43 +08:00 -
test: enhance SettingsDialog tests and add App integration test
Enhanced SettingsDialog component test coverage: - Add test for import/export status reset on dialog open - Add test for onImportSuccess callback propagation to hook - Add test for postponing restart flow (restart later button) - Add test for directory management callbacks (browse/reset/change) - Expand existing test to cover export, import, and clear actions - Fix type safety issues (avoid 'as any', use type guards) New App.test.tsx integration test: - Add comprehensive end-to-end test for main App component - Test settings dialog with import success callback and tray menu update - Test app switcher between Claude and Codex - Test provider CRUD operations (add, edit, delete, duplicate) - Test usage script modal workflow - Test external website link opening - Use vi.hoisted() pattern for centralized mock management Technical improvements: - Remove two environment-dependent tests (DEV flag) that required 'as any' - Use proper type guards for optional callback invocation - Clean up unused mock variables (switchProviderMock, onImportSuccessMock, refetchPromise) - Simplify useProviderActions mock to avoid spread argument type error Test results: 50 tests passing across 8 test files
Jason ·
2025-10-25 12:53:12 +08:00