taskCenter.integration.spec.js
7.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* taskCenter 集成测试
* 测试多个模块之间的联动
*/
// 先 mock 所有依赖
const mockRequest = jest.fn();
const mockRequestMethods = { POST: 'POST', GET: 'GET' };
jest.mock('@/api/request', () => mockRequest);
jest.mock('@/api/request.methods', () => mockRequestMethods);
// Mock API 模块
const mockGetTaskCenterBizCategoryListApi = jest.fn();
jest.mock('@/views/residentManage/taskCenter/api/index.js', () => ({
getTaskCenterBizCategoryListApi: mockGetTaskCenterBizCategoryListApi,
}));
// 导入被测试模块
const { priorityOptions, statusOptions, overdueFlagOptions } = require('@/views/residentManage/taskCenter/constant/index.js');
const { getTaskCenterTaskDescriptionSchema } = require('@/views/residentManage/taskCenter/view/detail/detail.data.js');
const { getTableFormSchema, getTableColumns } = require('@/views/residentManage/taskCenter/view/table/table.data.js');
describe('taskCenter 集成测试', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('常量与数据层的联动测试', () => {
it('优先级选项应该与 detail.data.js 中的 render 函数配合使用', async () => {
const schema = await getTaskCenterTaskDescriptionSchema();
const priorityItem = schema.find((item) => item.name === 'priority');
// 验证 priorityItem 的 render 函数能正确处理 priorityOptions
const mockData = { priority: 40 }; // 紧急
const h = jest.fn((tag, data, children) => ({ tag, data, children }));
const result = priorityItem.render(h, { data: mockData });
// 应该找到对应的优先级选项
const matchingOption = priorityOptions.find((item) => item.value === mockData.priority);
expect(matchingOption).toBeDefined();
expect(matchingOption.label).toBe('紧急');
});
it('状态选项应该与 detail.data.js 中的 render 函数配合使用', async () => {
const schema = await getTaskCenterTaskDescriptionSchema();
const statusItem = schema.find((item) => item.name === 'status');
const mockData = { status: 'FINISHED' };
const h = jest.fn((tag, data, children) => ({ tag, data, children }));
const result = statusItem.render(h, { data: mockData });
// 应该找到对应的状态选项
const matchingOption = statusOptions.find((item) => item.value === mockData.status);
expect(matchingOption).toBeDefined();
expect(matchingOption.label).toBe('已完成');
expect(matchingOption.className).toBe('green-dot');
});
it('逾期标识选项应该被正确使用', () => {
// 验证 overdueFlagOptions 的结构
expect(overdueFlagOptions).toHaveLength(2);
expect(overdueFlagOptions.map((item) => item.value)).toContain('OVERDUE');
expect(overdueFlagOptions.map((item) => item.value)).toContain('NOT_OVERDUE');
});
});
describe('表格配置与常量的联动测试', () => {
beforeEach(() => {
mockGetTaskCenterBizCategoryListApi.mockResolvedValue([]);
});
it('表格列的 priority 列应该使用 priorityOptions 作为 tagOptions', async () => {
const columns = await getTableColumns();
const priorityCol = columns.find((col) => col.prop === 'priority');
// 验证 tagOptions 是基于 priorityOptions 构建的
expect(priorityCol.tagOptions).toBeDefined();
// 验证 tagOptions 包含所有优先级
const priorityValues = Object.keys(priorityCol.tagOptions);
expect(priorityValues.map(String)).toEqual(
expect.arrayContaining(priorityOptions.map((item) => String(item.value))),
);
});
it('表格列的 status 列 formatter 应该与 statusOptions 一致', async () => {
const columns = await getTableColumns();
const statusCol = columns.find((col) => col.prop === 'status');
// 测试所有状态选项
statusOptions.forEach((option) => {
const result = statusCol.formatter({ status: option.value });
expect(result).toBe(option.label);
});
// 测试未知状态
const unknownResult = statusCol.formatter({ status: 'UNKNOWN' });
expect(unknownResult).toBe('-');
});
it('表格搜索表单的优先级选项应该与 priorityOptions 一致', async () => {
const schema = await getTableFormSchema();
const priorityItem = schema.find((item) => item.name === 'condition.priorities');
// 验证 optionList 使用的是 priorityOptions
expect(priorityItem.optionList).toBe(priorityOptions);
});
it('表格搜索表单的状态选项应该与 statusOptions 一致', async () => {
const schema = await getTableFormSchema();
const statusItem = schema.find((item) => item.name === 'condition.status');
// 验证 optionList 使用的是 statusOptions
expect(statusItem.optionList).toBe(statusOptions);
});
it('表格搜索表单的逾期选项应该与 overdueFlagOptions 一致', async () => {
const schema = await getTableFormSchema();
const overdueItem = schema.find((item) => item.name === 'condition.overdueFlag');
// 验证 optionList 使用的是 overdueFlagOptions
expect(overdueItem.optionList).toBe(overdueFlagOptions);
});
it('表格列应该包含任务分类列', async () => {
const mockCategories = [
{ bizType: 'type1', categoryName: '分类 1' },
{ bizType: 'type2', categoryName: '分类 2' },
];
mockGetTaskCenterBizCategoryListApi.mockResolvedValue(mockCategories);
const columns = await getTableColumns();
const bizTypeCol = columns.find((col) => col.prop === 'bizTypeName');
expect(bizTypeCol).toBeDefined();
expect(bizTypeCol.label).toBe('任务分类');
expect(bizTypeCol.prop).toBe('bizTypeName');
});
it('表格搜索表单的任务分类选项应该来自 API', async () => {
const mockCategories = [
{ bizType: 'type1', categoryName: '分类 1' },
{ bizType: 'type2', categoryName: '分类 2' },
];
mockGetTaskCenterBizCategoryListApi.mockResolvedValue(mockCategories);
const schema = await getTableFormSchema();
const bizTypeItem = schema.find((item) => item.name === 'condition.bizTypes');
expect(bizTypeItem).toBeDefined();
expect(bizTypeItem.optionList).toEqual(mockCategories);
expect(bizTypeItem.optionId).toBe('bizType');
expect(bizTypeItem.optionLabel).toBe('categoryName');
});
});
describe('数据结构完整性测试', () => {
beforeEach(() => {
mockGetTaskCenterBizCategoryListApi.mockResolvedValue([]);
});
it('detail schema 和 table columns 应该覆盖相同的字段', async () => {
const detailSchema = await getTaskCenterTaskDescriptionSchema();
const tableColumns = await getTableColumns();
const detailFields = detailSchema
.filter((item) => item.name)
.map((item) => item.name);
const tableFields = tableColumns.map((col) => col.prop);
// 共同的字段应该都存在
const commonFields = ['taskNo', 'createdBy', 'createdDate', 'dueTime', 'completeTime', 'bizTypeName'];
commonFields.forEach((field) => {
expect(detailFields).toContain(field);
expect(tableFields).toContain(field);
});
});
it('所有常量选项的 value 值应该是唯一的', () => {
// priorityOptions 的 value 应该唯一
const priorityValues = priorityOptions.map((item) => item.value);
expect(new Set(priorityValues).size).toBe(priorityValues.length);
// statusOptions 的 value 应该唯一
const statusValues = statusOptions.map((item) => item.value);
expect(new Set(statusValues).size).toBe(statusValues.length);
// overdueFlagOptions 的 value 应该唯一
const overdueValues = overdueFlagOptions.map((item) => item.value);
expect(new Set(overdueValues).size).toBe(overdueValues.length);
});
});
});