ComponentsDemoPage.test.tsx
6.96 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { ComponentsDemoPage } from './ComponentsDemoPage';
import uiStyles from '../../../packages/ui/src/components/Shared.module.css';
describe('ComponentsDemoPage', () => {
it('shows all phase-one component groups including Upload', () => {
render(<ComponentsDemoPage />);
expect(screen.getByRole('heading', { name: '组件库 Demo' })).toBeInTheDocument();
expect(screen.getByText('基础交互')).toBeInTheDocument();
expect(screen.getByText('选择与日期')).toBeInTheDocument();
expect(screen.getByText('表格与分页')).toBeInTheDocument();
expect(screen.getByText('反馈与浮层')).toBeInTheDocument();
expect(screen.getByText('数据展示')).toBeInTheDocument();
expect(screen.getByText('导航与占位')).toBeInTheDocument();
expect(screen.getByText('颜色能力')).toBeInTheDocument();
expect(screen.getByText('上传')).toBeInTheDocument();
expect(screen.getByText('暂无审批记录')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '新建审批' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '加载失败' })).toBeInTheDocument();
expect(screen.getByRole('status', { name: '暂无数据' })).toBeInTheDocument();
expect(screen.getByRole('status', { name: '未找到匹配结果' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '权限受限' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '网络不可用' })).toBeInTheDocument();
expect(screen.getByText('点击或拖拽业务资料到此上传')).toBeInTheDocument();
expect(screen.getByText('图片/视频')).toBeInTheDocument();
expect(screen.getByText('4/20')).toBeInTheDocument();
expect(screen.getByText('4/120')).toBeInTheDocument();
});
it('keeps basic component demos interactive for manual review', () => {
render(<ComponentsDemoPage />);
fireEvent.click(screen.getByLabelText('Demo 启用'));
fireEvent.click(screen.getByRole('switch', { name: 'Demo 启用审批' }));
expect(screen.getByLabelText('Demo 启用')).not.toBeChecked();
expect(screen.getByRole('switch', { name: 'Demo 启用审批' })).toHaveAttribute('aria-checked', 'false');
});
it('shows every Button type, size, and core state in the demo', () => {
render(<ComponentsDemoPage />);
expect(screen.getByRole('button', { name: '主按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '普通按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '描边按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '文字按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '危险按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '小按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '中按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '大按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '图标按钮' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '禁用按钮' })).toBeDisabled();
expect(screen.getByRole('button', { name: '加载中' })).toHaveAttribute('aria-busy', 'true');
});
it('shows Message in the feedback demo after clicking the trigger', () => {
render(<ComponentsDemoPage />);
fireEvent.click(screen.getByRole('button', { name: '展示消息提示' }));
expect(screen.getByRole('region', { name: '全局消息提示' })).toBeInTheDocument();
expect(screen.getByRole('status', { name: '保存成功' })).toBeInTheDocument();
expect(screen.getByRole('status', { name: '请补充审批人' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '删除失败' })).toBeInTheDocument();
expect(screen.getByRole('img', { name: '成功提示' })).toBeInTheDocument();
expect(screen.getByRole('img', { name: '警告提示' })).toBeInTheDocument();
expect(screen.getByRole('img', { name: '错误提示' })).toBeInTheDocument();
});
it('closes the feedback demo Modal when clicking cancel', () => {
render(<ComponentsDemoPage />);
fireEvent.click(screen.getByRole('button', { name: '取消' }));
expect(screen.queryByRole('dialog', { name: '编辑项目' })).not.toBeInTheDocument();
});
it('closes the feedback demo Modal when clicking the close button', () => {
render(<ComponentsDemoPage />);
fireEvent.click(screen.getByRole('button', { name: '关闭编辑项目' }));
expect(screen.queryByRole('dialog', { name: '编辑项目' })).not.toBeInTheDocument();
});
it('shows Form validation and horizontal FormItem layout in the feedback demo', () => {
render(<ComponentsDemoPage />);
fireEvent.click(screen.getByRole('button', { name: '提交表单' }));
expect(screen.getByRole('alert', { name: '请输入项目名称' })).toBeInTheDocument();
expect(screen.getByTestId('form-root')).toHaveClass(uiStyles.formColumnsOne);
expect(screen.getByTestId('form-item-项目名称')).toHaveClass(uiStyles.formItemHorizontal);
expect(screen.getByTestId('form-item-所属岗位')).toHaveClass(uiStyles.formItemSpanOne);
expect(screen.getByTestId('form-item-备注')).toHaveClass(uiStyles.formItemSpanTwo);
expect(screen.getByTestId('form-main-项目名称')).toHaveClass(uiStyles.formMain);
expect(screen.getByText('从 Agent 管理自动带入,不可修改')).toHaveClass(uiStyles.formTips);
expect(screen.getByTestId('form-error-项目名称')).toHaveClass(uiStyles.formErrorSlot);
});
it('shows rounded avatar and top-right progress examples in the display demo', () => {
render(<ComponentsDemoPage />);
expect(screen.getByLabelText('张三')).toHaveClass(uiStyles.avatarCircle, uiStyles.avatarText);
expect(screen.getByTestId('progress-root')).toHaveClass(uiStyles.progressTopRight);
});
it('shows Upload file and media wall states in the demo', () => {
render(<ComponentsDemoPage />);
expect(screen.getByText('product_design_v2.fig')).toBeInTheDocument();
expect(screen.getByText('12.40 MB · 已完成')).toBeInTheDocument();
expect(screen.getByText('需求文档.pdf')).toBeInTheDocument();
expect(screen.getByText('3.20 MB · 上传中 42%')).toBeInTheDocument();
expect(screen.getByText('素材包.zip')).toBeInTheDocument();
expect(screen.getByText('网络异常,请重试')).toBeInTheDocument();
expect(screen.getByLabelText('视频')).toBeInTheDocument();
expect(screen.getByText('支持 JPG、PNG、MP4、MOV,图片单张不超过 10MB,视频单个不超过 500MB')).toBeInTheDocument();
});
it('keeps the component demo route isolated from the admin shell copy', () => {
render(<ComponentsDemoPage />);
expect(screen.queryByText('岗位Agent管理后台')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '退出登录' })).not.toBeInTheDocument();
});
});