@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
64 lines (51 loc) • 1.41 kB
text/typescript
import { act, renderHook } from '@testing-library/react';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { messageService } from '@/services/message';
import { useChatStore } from '../../store';
// Mock messageService 和 chatService
vi.mock('@/services/message', () => ({
messageService: {
updateMessageTTS: vi.fn(),
updateMessageTranslate: vi.fn(),
updateMessage: vi.fn(),
},
}));
vi.mock('@/services/chat', () => ({
chatService: {
fetchPresetTaskResult: vi.fn(),
},
}));
vi.mock('@/chains/langDetect', () => ({
chainLangDetect: vi.fn(),
}));
vi.mock('@/chains/translate', () => ({
chainTranslate: vi.fn(),
}));
// Mock supportLocales
vi.mock('@/locales/options', () => ({
supportLocales: ['en-US', 'zh-CN'],
}));
beforeEach(() => {
vi.clearAllMocks();
useChatStore.setState(
{
// ... 初始状态
},
false,
);
});
afterEach(() => {
vi.restoreAllMocks();
});
describe('ChatEnhanceAction', () => {
describe('clearTTS', () => {
it('should clear TTS for a message and refresh messages', async () => {
const { result } = renderHook(() => useChatStore());
const messageId = 'message-id';
await act(async () => {
await result.current.clearTTS(messageId);
});
expect(messageService.updateMessageTTS).toHaveBeenCalledWith(messageId, false);
});
});
});