ComponentsDemoPage.test.tsx
4.67 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
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 except 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.getByRole('button', { name: '新建审批' })).toBeInTheDocument();
expect(screen.queryByText('Upload')).not.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('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.formColumnsTwo);
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);
});
});