enhance: update test (#457)

This commit is contained in:
Wendong-Fan 2025-10-06 13:27:51 +08:00 committed by GitHub
commit bbaed6a5cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 74 additions and 18 deletions

View file

@ -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

View file

@ -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]);

View file

@ -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<string, string> = {
'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

View file

@ -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()
})
})
})

View file

@ -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()
})
})