UNPKG

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

79 lines (69 loc) 1.75 kB
import { describe, expect, it } from 'vitest'; import { LOADING_FLAT } from '@/const/message'; import { ChatMessage } from '@/types/message'; import { generateMarkdown } from './template'; describe('generateMarkdown', () => { // 创建测试用的消息数据 const mockMessages = [ { id: '1', content: 'Hello', role: 'user', createdAt: Date.now(), }, { id: '2', content: 'Hi there', role: 'assistant', createdAt: Date.now(), }, { id: '3', content: LOADING_FLAT, role: 'assistant', createdAt: Date.now(), }, { id: '4', content: '{"result": "tool data"}', role: 'tool', createdAt: Date.now(), tool_call_id: 'tool1', }, { id: '5', content: 'Message with tools', role: 'assistant', createdAt: Date.now(), tools: [{ name: 'calculator', result: '42' }], }, ] as ChatMessage[]; const defaultParams = { messages: mockMessages, title: 'Chat Title', includeTool: false, includeUser: true, withSystemRole: false, withRole: false, systemRole: '', }; it('should filter out loading messages', () => { const result = generateMarkdown(defaultParams); expect(result).not.toContain(LOADING_FLAT); }); it('should handle messages with special characters', () => { const messagesWithSpecialChars = [ { id: '1', content: '**Bold** *Italic* `Code`', role: 'user', createdAt: Date.now(), }, ] as ChatMessage[]; const result = generateMarkdown({ ...defaultParams, messages: messagesWithSpecialChars, }); expect(result).toContain('**Bold** *Italic* `Code`'); }); });