PromptDetail.test.tsx
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import PromptDetail from '../pages/Prompts/PromptDetail';
const mockPrompt = {
id: 'test-id-1',
template_type: 'general',
title: '通用质检提示词',
code: 'TEMPLATE-GENERAL-001',
system_prompt: '你是一个专业的质检审核助手。',
user_prompt: '请审核以下内容:{{content}}',
variables: [{ name: 'content', type: 'string' }],
version: 3,
status: 'published',
created_at: '2026-06-01T10:00:00Z',
updated_at: '2026-06-15T10:00:00Z',
versions: [
{
id: 'v3-id',
version: 3,
system_prompt: '你是一个专业的质检审核助手。',
user_prompt: '请审核以下内容:{{content}}',
variables: [{ name: 'content', type: 'string' }],
created_at: '2026-06-15T10:00:00Z',
},
{
id: 'v2-id',
version: 2,
system_prompt: '你是一个质检审核助手。',
user_prompt: '请审核:{{content}}',
variables: [{ name: 'content', type: 'string' }],
created_at: '2026-06-10T10:00:00Z',
},
{
id: 'v1-id',
version: 1,
system_prompt: '你是一个质检审核助手。',
user_prompt: null,
variables: null,
created_at: '2026-06-01T10:00:00Z',
},
],
};
vi.mock('../stores/promptStore', () => ({
usePromptStore: vi.fn(() => ({
detail: mockPrompt,
detailLoading: false,
getPromptDetail: vi.fn().mockResolvedValue(mockPrompt),
})),
}));
describe('PromptDetail', () => {
const baseProps = {
open: true,
promptId: 'test-id-1',
onClose: vi.fn(),
};
it('渲染模板详情标题', () => {
render(<PromptDetail {...baseProps} />);
expect(screen.getByText('模板详情')).toBeInTheDocument();
});
it('渲染基本信息区域', () => {
render(<PromptDetail {...baseProps} />);
expect(screen.getByText('基本信息')).toBeInTheDocument();
expect(screen.getByText('通用质检提示词')).toBeInTheDocument();
expect(screen.getByText(/TEMPLATE-GENERAL-001/)).toBeInTheDocument();
});
it('渲染当前内容区域', () => {
render(<PromptDetail {...baseProps} />);
expect(screen.getByText('当前内容')).toBeInTheDocument();
const promptElements = screen.getAllByText('你是一个专业的质检审核助手。');
expect(promptElements.length).toBeGreaterThanOrEqual(1);
});
it('渲染版本历史区域', () => {
render(<PromptDetail {...baseProps} />);
expect(screen.getByText('版本历史')).toBeInTheDocument();
expect(screen.getByText('3 个版本')).toBeInTheDocument();
});
it('渲染版本号标签', () => {
render(<PromptDetail {...baseProps} />);
const v3Elements = screen.getAllByText('v3');
expect(v3Elements.length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('v2')).toBeInTheDocument();
expect(screen.getByText('v1')).toBeInTheDocument();
});
it('渲染当前版本标记', () => {
render(<PromptDetail {...baseProps} />);
const elements = screen.getAllByText('当前版本');
expect(elements.length).toBeGreaterThanOrEqual(1);
});
});