var-picker.test.tsx
5.42 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { render, screen } from '@testing-library/react';
import React from 'react';
import VarPicker from './var-picker';
// const Test = () => {
// const [number1, setNumber] = useState(0);
// return (
// <div>
// <button
// onClick={() => {
// setNumber(5);
// }}
// data-testid="clickBtn"
// type="button"
// >
// 点击
// </button>
// {number1 && <span data-testid="showText">{number1}</span>}
// </div>
// );
// };
// "test": "jest --no-cache --config jest.config.js"
jest.mock('@qx/utils', () => ({
getWidgetsIcon: () => <span>icon</span>,
}));
const getByTextWithFallback = (text: any) => {
try {
return screen.getByText(text);
} catch (error) {
// 如果无法找到精确的文本匹配,尝试使用包含文本的元素
return screen.getByRole('tree', { name: new RegExp(text) });
}
};
describe('test component', () => {
test('click event', () => {
render(
<VarPicker
onPick={jest.fn()}
dataSource={[
{
key: 'FORM',
titleStr: '表单变量',
children: [],
},
{
key: 'SYS',
titleStr: '系统变量',
children: [
{
key: '${SYS.CUR_USER}',
titleStr: '当前人员',
widget: 'qxObject',
fieldGroupType: 'OBJECT',
attrs: [
{
key: '${SYS.CUR_USER.id}',
titleStr: '用户ID',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_USER.name}',
titleStr: '用户名',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_USER.code}',
titleStr: '工号',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_USER.mobile}',
titleStr: '手机号',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_USER.email}',
titleStr: '邮箱',
fieldGroupType: 'TEXT',
},
],
},
{
key: '${SYS.CUR_ORG}',
titleStr: '当前部门',
widget: 'qxObject',
fieldGroupType: 'OBJECT',
attrs: [
{
key: '${SYS.CUR_ORG.id}',
titleStr: '部门ID',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_ORG.code}',
titleStr: '部门编号',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_ORG.name}',
titleStr: '部门名称',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_ORG.orgLevel}',
titleStr: '部门层级',
fieldGroupType: 'TEXT',
},
],
},
{
key: '${SYS.CUR_CORP}',
titleStr: '当前公司',
widget: 'qxObject',
fieldGroupType: 'OBJECT',
attrs: [
{
key: '${SYS.CUR_CORP.corpCode}',
titleStr: '公司编号',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.CUR_CORP.corpName}',
titleStr: '公司名称',
fieldGroupType: 'TEXT',
},
],
},
{
key: '${SYS.CUR_DATE}',
titleStr: '当前时间',
widget: 'qxDatetime',
fieldGroupType: 'DATE',
},
{
key: '${SYS.LOGIN_INFO}',
titleStr: '登录信息',
widget: 'qxObject',
fieldGroupType: 'OBJECT',
attrs: [
{
key: '${SYS.LOGIN_INFO.ipAddr}',
titleStr: 'IP地址',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.LOGIN_INFO.terminal}',
titleStr: '终端类型',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.LOGIN_INFO.browser}',
titleStr: '浏览器信息',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.LOGIN_INFO.browserRoute}',
titleStr: '当前浏览器路由信息',
fieldGroupType: 'TEXT',
},
{
key: '${SYS.LOGIN_INFO.session}',
titleStr: 'session信息',
fieldGroupType: 'TEXT',
},
],
},
],
},
]}
/>,
);
expect(screen.getByRole('tree')).not.toBeNull();
// userEvent.click(screen.getByTestId('clickBtn'));
// // 异步
// await waitFor(() => {
// });
});
});