eigent/test/setup.ts
Tong Chen af93bb3065
feat: Add Lint & Format (#878)
Co-authored-by: a7m-1st <Ahmed.jimi.awelkeir500@gmail.com>
Co-authored-by: eigent-ai <camel@eigent.ai>
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
Co-authored-by: Wendong-Fan <w3ndong.fan@gmail.com>
2026-02-01 23:16:18 +08:00

118 lines
3.7 KiB
TypeScript

// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
// Global test setup file
import '@testing-library/jest-dom';
import { vi } from 'vitest';
// 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.it-ticket-creation': 'IT Ticket Creation',
'chat.bank-transfer-csv-analysis-and-visualization':
'Bank Transfer CSV Analysis and Visualization',
'chat.help-organize-my-desktop': 'Please Help Organize My Desktop',
'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.it-ticket-creation-message': 'Plan a tennis trip to Palm Springs',
'chat.bank-transfer-csv-analysis-and-visualization-message':
'Analyze and visualize bank transfer CSV',
'chat.help-organize-my-desktop-message':
'Please Help Organize My Desktop',
'chat.no-reply-received-task-continue':
'No reply received, task will continue',
};
return translations[key] || key;
},
i18n: {
language: 'en',
changeLanguage: vi.fn(),
},
}),
initReactI18next: {
type: '3rdParty',
init: vi.fn(),
},
}));
// Mock Electron APIs if needed
global.electronAPI = {
// Add mock implementations for electron preload APIs
};
// Mock ipcRenderer
global.ipcRenderer = {
invoke: vi.fn(),
on: vi.fn(),
removeAllListeners: vi.fn(),
};
// Mock environment variables
process.env.NODE_ENV = 'test';
// Global test utilities
global.waitFor = async (callback: () => boolean, timeout = 5000) => {
const startTime = Date.now();
while (Date.now() - startTime < timeout) {
if (await callback()) {
return;
}
await new Promise((resolve) => setTimeout(resolve, 100));
}
throw new Error(`Timeout waiting for condition after ${timeout}ms`);
};
// Add type declarations for globals
declare global {
var electronAPI: any;
var ipcRenderer: any;
var waitFor: (callback: () => boolean, timeout?: number) => Promise<void>;
}
// Setup DOM environment
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
// Mock ResizeObserver
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));
// Mock IntersectionObserver
global.IntersectionObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));