diff --git a/src/components/ChatBox/index.tsx b/src/components/ChatBox/index.tsx index 2ce48b093..45d29ee6a 100644 --- a/src/components/ChatBox/index.tsx +++ b/src/components/ChatBox/index.tsx @@ -50,16 +50,18 @@ export default function ChatBox(): JSX.Element { }) .catch((err) => console.error("Failed to fetch settings:", err)); - proxyFetchGet("/api/configs").then((configsRes) => { - const configs = Array.isArray(configsRes) ? configsRes : []; - const _hasApiKey = configs.find( - (item) => item.config_name === "GOOGLE_API_KEY" - ); - const _hasApiId = configs.find( - (item) => item.config_name === "SEARCH_ENGINE_ID" - ); - if (_hasApiKey && _hasApiId) setHasSearchKey(true); - }); + proxyFetchGet("/api/configs") + .then((configsRes) => { + const configs = Array.isArray(configsRes) ? configsRes : []; + const _hasApiKey = configs.find( + (item) => item.config_name === "GOOGLE_API_KEY" + ); + const _hasApiId = configs.find( + (item) => item.config_name === "SEARCH_ENGINE_ID" + ); + if (_hasApiKey && _hasApiId) setHasSearchKey(true); + }) + .catch((err) => console.error("Failed to fetch configs:", err)); }, []); // Refresh privacy status when dialog closes diff --git a/src/hooks/useInstallationSetup.ts b/src/hooks/useInstallationSetup.ts index d6b5240e7..16e19275d 100644 --- a/src/hooks/useInstallationSetup.ts +++ b/src/hooks/useInstallationSetup.ts @@ -41,16 +41,20 @@ export const useInstallationSetup = () => { }; const checkBackendStatus = async() => { - // Also check if installation is currently in progress - const installationStatus = await window.electronAPI.getInstallationStatus(); - console.log('[useInstallationSetup] Installation status check:', installationStatus); - - if (installationStatus.success && installationStatus.isInstalling) { - console.log('[useInstallationSetup] Installation in progress, starting frontend state'); - startInstallation(); + try { + // Also check if installation is currently in progress + const installationStatus = await window.electronAPI.getInstallationStatus(); + console.log('[useInstallationSetup] Installation status check:', installationStatus); + + if (installationStatus.success && installationStatus.isInstalling) { + console.log('[useInstallationSetup] Installation in progress, starting frontend state'); + startInstallation(); + } + } catch (err) { + console.error('[useInstallationSetup] Failed to check installation status:', err); } } - + checkToolInstalled(); checkBackendStatus(); }, [initState, setInitState, startInstallation]); diff --git a/test/setup.ts b/test/setup.ts index 2bd019a87..54d7c529a 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -2,6 +2,36 @@ import { vi } from 'vitest' import '@testing-library/jest-dom' +// Mock react-i18next +vi.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: (key: string) => { + // Map translation keys to English text + const translations: Record = { + 'chat.welcome-to-eigent': 'Welcome to Eigent', + 'chat.how-can-i-help-you': 'How can I help you today?', + 'chat.palm-springs-tennis-trip-planner': 'Palm Springs Tennis Trip Planner', + 'chat.bank-transfer-csv-analysis-and-visualization': 'Bank Transfer CSV Analysis and Visualization', + 'chat.find-duplicate-files-in-downloads-folder': 'Find Duplicate Files in Downloads Folder', + 'setting.search-mcp': 'Search MCPs', + 'chat.by-messaging-eigent': 'By messaging Eigent, you agree to our', + 'chat.terms-of-use': 'Terms of Use', + 'chat.and': 'and', + 'chat.privacy-policy': 'Privacy Policy', + 'chat.palm-springs-tennis-trip-planner-message': 'Plan a tennis trip to Palm Springs', + 'chat.bank-transfer-csv-analysis-and-visualization-message': 'Analyze and visualize bank transfer CSV', + 'chat.find-duplicate-files-in-downloads-folder-message': 'Find duplicate files in Downloads folder', + 'chat.no-reply-received-task-continue': 'No reply received, task will continue', + } + return translations[key] || key + }, + i18n: { + language: 'en', + changeLanguage: vi.fn(), + }, + }), +})) + // Mock Electron APIs if needed global.electronAPI = { // Add mock implementations for electron preload APIs diff --git a/test/unit/components/ChatBox.test.tsx b/test/unit/components/ChatBox.test.tsx index ca13746b1..c19bc5f0e 100644 --- a/test/unit/components/ChatBox.test.tsx +++ b/test/unit/components/ChatBox.test.tsx @@ -737,11 +737,21 @@ describe('ChatBox Component', () => { }) it('should handle privacy fetch errors', async () => { + // Mock console.error to suppress expected error logs + const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}) + // Mock the fetch to reject properly for testing error handling mockProxyFetchGet.mockRejectedValue(new Error('Privacy fetch failed')) // Rendering should not throw even with fetch error expect(() => renderChatBox()).not.toThrow() + + // Wait for the promise to settle + await waitFor(() => { + expect(consoleErrorSpy).toHaveBeenCalled() + }) + + consoleErrorSpy.mockRestore() }) }) }) diff --git a/test/unit/hooks/useInstallationSetup.test.ts b/test/unit/hooks/useInstallationSetup.test.ts index b24122027..afc03e044 100644 --- a/test/unit/hooks/useInstallationSetup.test.ts +++ b/test/unit/hooks/useInstallationSetup.test.ts @@ -286,6 +286,9 @@ describe('useInstallationSetup Hook', () => { }) it('should handle installation status check failure', async () => { + // Mock console.error to suppress expected error logs + const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}) + electronAPI.getInstallationStatus.mockRejectedValue(new Error('Status check failed')) renderHook(() => useInstallationSetup()) @@ -294,6 +297,13 @@ describe('useInstallationSetup Hook', () => { await vi.waitFor(() => { expect(electronAPI.getInstallationStatus).toHaveBeenCalled() }) + + // Wait for error to be logged + await vi.waitFor(() => { + expect(consoleErrorSpy).toHaveBeenCalled() + }) + + consoleErrorSpy.mockRestore() }) })