feat: refine business chat workflow
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { ChatMessage } from '@/pages/Chat/ChatMessage';
|
||||
import type { RawMessage } from '@/stores/chat';
|
||||
import { appendBusinessResponseGuidance } from '../../shared/business-guidance';
|
||||
|
||||
describe('ChatMessage attachment dedupe', () => {
|
||||
it('keeps attachment-only assistant replies visible even when process attachments are suppressed', () => {
|
||||
@@ -79,3 +80,67 @@ describe('ChatMessage LaTeX rendering', () => {
|
||||
expect(container.querySelector('.katex')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ChatMessage business answer rendering', () => {
|
||||
it('renders a business summary panel for structured operational replies', () => {
|
||||
const message: RawMessage = {
|
||||
role: 'assistant',
|
||||
content: [
|
||||
'状态:需处理,携程渠道房态与 PMS 不一致。',
|
||||
'依据:携程 0508 房型显示可售 3 间,PMS 为 0 间。',
|
||||
'影响:可能产生超售风险。',
|
||||
'下一步:请先暂停该房型自动售卖,并复核渠道登录态。',
|
||||
].join('\n'),
|
||||
};
|
||||
|
||||
render(<ChatMessage message={message} />);
|
||||
|
||||
const panel = screen.getByTestId('business-answer-panel');
|
||||
expect(panel).toHaveTextContent('业务摘要');
|
||||
expect(panel).toHaveTextContent('需处理,携程渠道房态与 PMS 不一致');
|
||||
expect(panel).toHaveTextContent('携程 0508 房型显示可售 3 间');
|
||||
expect(panel).toHaveTextContent('请先暂停该房型自动售卖');
|
||||
});
|
||||
|
||||
it('does not add the business panel to ordinary assistant chat', () => {
|
||||
const message: RawMessage = {
|
||||
role: 'assistant',
|
||||
content: '你好,我可以帮你处理问题。',
|
||||
};
|
||||
|
||||
render(<ChatMessage message={message} />);
|
||||
|
||||
expect(screen.queryByTestId('business-answer-panel')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ChatMessage markdown rendering', () => {
|
||||
it('hides legacy injected business guidance from visible user messages', () => {
|
||||
const message: RawMessage = {
|
||||
role: 'user',
|
||||
content: appendBusinessResponseGuidance('会话中的 markdown 结构化,表格也可以加强 UI 渲染'),
|
||||
};
|
||||
|
||||
render(<ChatMessage message={message} />);
|
||||
|
||||
expect(screen.getByText('会话中的 markdown 结构化,表格也可以加强 UI 渲染')).toBeInTheDocument();
|
||||
expect(screen.queryByText(/YINIAN_BUSINESS_RESPONSE_GUIDANCE/)).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(/请按智念业务员工/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders markdown tables inside the enhanced table shell', () => {
|
||||
const message: RawMessage = {
|
||||
role: 'assistant',
|
||||
content: [
|
||||
'| 渠道 | 房型 | 状态 |',
|
||||
'| --- | --- | --- |',
|
||||
'| 携程 | 豪华大床房 | 需复核 |',
|
||||
].join('\n'),
|
||||
};
|
||||
|
||||
render(<ChatMessage message={message} />);
|
||||
|
||||
expect(screen.getByTestId('markdown-table-scroll')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('markdown-table')).toHaveTextContent('豪华大床房');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user