StoreDetailDrawer.test.tsx
8.77 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { StoreListingDetail } from '@/api';
import { STORE_DICTIONARIES, type StoreDictionaries } from './dictionaries';
import { StoreDetailDrawer } from './StoreDetailDrawer';
afterEach(cleanup);
// Swagger-shaped fixtures: live endpoints contain no records, so these are not real money samples.
const spec: StoreDictionaries = {
businessScenes: [
{ value: 'AFTER_SALES', label: '售后会员权益升级' },
{ value: 'PRE_SALES', label: '售前延保' },
],
productCategories: [
{ value: 'FILM', label: '太阳膜-原厂' },
{ value: 'WRAP', label: '车衣-原厂' },
],
calcModes: [{ value: 'CATEGORY', label: '按品类计算' }],
calcWays: [
{ value: 'INCOME', label: '收入' },
{ value: 'FIXED', label: '固定' },
],
onlinePointFlags: [
{ value: '1', label: '是' },
{ value: '0', label: '否' },
],
};
const detail: StoreListingDetail = {
listingId: '9007199254740993',
storeName: '当前门店',
merchantNo: 'SQ001',
businessScene: 'AFTER_SALES',
status: 'PENDING',
currentLevel: 1,
totalLevel: 2,
submitUserName: '运营甲',
submitTime: '2026-10-09T10:00:00',
costDecoration: '500',
costMonthly: '500',
costLabor: '500',
costTotal: '90071992547409.91',
items: [
{
itemId: '1',
productCategory: 'FILM',
marketFee1CalcMode: 'CATEGORY',
marketFee1CalcWay: 'INCOME',
marketFee1Value: '5',
marketFee1Unit: 'RATIO',
sunshine1OnlinePoint: 0,
sunshine1Value: '0',
sunshine1Unit: 'RATIO',
},
{
itemId: '2',
productCategory: 'WRAP',
marketFee1CalcMode: 'CATEGORY',
marketFee1CalcWay: 'FIXED',
marketFee1Value: '123.45',
marketFee1Unit: 'AMOUNT',
},
...Array.from({ length: 9 }, (_, index) => ({
itemId: `extra-${index}`,
productCategory: `分类${index}`,
})),
],
approvalLogs: [
{
logId: '1',
action: 'REJECT',
operatorName: '商务甲',
operatorRole: 'YJ_BUSINESS_MGR',
preStatus: 'PENDING',
postStatus: 'REJECTED',
reason: '请核对政策',
operateTime: '2026-10-09T11:00:00',
operateIp: '192.0.2.1',
},
],
changeHistory: [
{
changeId: 'old',
versionNo: 1,
changeField: '运营成本',
beforeValue: '0',
afterValue: '100',
changeUserName: '运营甲',
effectiveTime: '2026-09-01T10:00:00',
},
{
changeId: 'new',
versionNo: 2,
changeField: '管理层市场费',
beforeValue: '3%',
afterValue: '5%',
changeUserName: '运营乙',
effectiveTime: '2026-10-01T10:00:00',
},
],
};
function show(overrides: Partial<React.ComponentProps<typeof StoreDetailDrawer>> = {}) {
return render(
<StoreDetailDrawer
open
mode="approval"
detail={detail}
spec={spec}
onClose={() => undefined}
{...overrides}
/>,
);
}
describe('store detail presentation', () => {
it('uses local dictionaries for real Chinese policy values and numeric point flags', () => {
show({
spec: STORE_DICTIONARIES,
detail: {
...detail,
businessScene: '精品升级',
items: [
{
productCategory: '车辆美容',
sunshine1CalcMode: '按品类计算',
sunshine1CalcWay: '收入',
sunshine1OnlinePoint: 1,
sunshine2CalcMode: '按整单计算',
sunshine2CalcWay: '毛利',
sunshine2OnlinePoint: 0,
},
{ productCategory: '后续新增分类' },
],
},
});
expect(screen.getByText('精品升级')).toBeInTheDocument();
fireEvent.click(screen.getByRole('tab', { name: '一线阳光激励' }));
const panel = within(screen.getByRole('tabpanel', { name: '一线阳光激励' }));
for (const label of [
'车辆美容',
'后续新增分类',
'按品类计算',
'按整单计算',
'收入',
'毛利',
'是',
'否',
]) {
expect(panel.getByText(label)).toBeInTheDocument();
}
});
it('shows only the current scene, every category and the policy value unit', () => {
show();
expect(screen.getByText('当前门店')).toBeInTheDocument();
expect(screen.getByText('售后会员权益升级')).toBeInTheDocument();
expect(screen.queryByText('售前延保')).not.toBeInTheDocument();
expect(screen.getByText('分类8')).toBeInTheDocument();
expect(screen.getByText('5%')).toBeInTheDocument();
expect(screen.getByText('¥123.45')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: '通过' })).not.toBeInTheDocument();
});
it('displays the authoritative total even when the cost components differ', () => {
show();
fireEvent.click(screen.getByRole('tab', { name: '运营成本' }));
expect(screen.getAllByText('¥90,071,992,547,409.91').length).toBeGreaterThan(0);
expect(screen.queryByText('¥1,500.00')).not.toBeInTheDocument();
expect(screen.getAllByText('¥500.00')).toHaveLength(3);
});
it('renders zero point flags and zero policy values without treating them as missing', () => {
show();
fireEvent.click(screen.getByRole('tab', { name: '一线阳光激励' }));
expect(screen.getByText('否')).toBeInTheDocument();
expect(screen.getByText('0%')).toBeInTheDocument();
});
it('shows two approval stages by default and the returned single finance stage', () => {
const view = show({ detail: { ...detail, totalLevel: undefined } });
expect(within(screen.getByLabelText('审批流程')).getByText('优加商务经理')).toBeInTheDocument();
view.rerender(
<StoreDetailDrawer
open
mode="approval"
detail={{ ...detail, totalLevel: 1 }}
onClose={() => undefined}
/>,
);
const flow = within(screen.getByLabelText('审批流程'));
expect(flow.queryByText('优加商务经理')).not.toBeInTheDocument();
expect(flow.getByText('优加财务经理')).toBeInTheDocument();
});
it('does not describe a rejected record as awaiting approval and preserves the audit reason', () => {
show({ detail: { ...detail, status: 'REJECTED', rejectReason: '请核对政策' } });
expect(
within(screen.getByLabelText('审批流程')).queryByText('当前审批节点'),
).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('tab', { name: '审批留痕' }));
expect(screen.getByText('商务甲')).toBeInTheDocument();
expect(screen.getAllByText('请核对政策').length).toBeGreaterThan(0);
expect(screen.getByText(/192\.0\.2\.1/)).toBeInTheDocument();
});
it('opens listing history directly and shows newest changes first', () => {
show({ mode: 'listing', initialTab: 'history', detail: { ...detail, status: 'APPROVED' } });
expect(screen.getByRole('tab', { name: '变更历史' })).toHaveAttribute('aria-selected', 'true');
const panel = screen.getByRole('tabpanel');
expect(panel.textContent?.indexOf('管理层市场费')).toBeLessThan(
panel.textContent?.indexOf('运营成本') ?? -1,
);
expect(within(panel).getByText('3% → 5%')).toBeInTheDocument();
expect(screen.queryByRole('tab', { name: '审批留痕' })).not.toBeInTheDocument();
});
it('renders the batch-pass audit action as a readable business action', () => {
show({ detail: { ...detail, approvalLogs: [{ logId: 'batch', action: 'BATCH_PASS' }] } });
fireEvent.click(screen.getByRole('tab', { name: '审批留痕' }));
expect(screen.getByText('批量通过')).toBeInTheDocument();
expect(screen.queryByText('BATCH_PASS')).not.toBeInTheDocument();
});
it.each(['approval', 'listing'] as const)(
'uses approveTime for the %s effective date when effectiveTime is absent',
(mode) => {
show({ mode, detail: { ...detail, status: 'APPROVED', approveTime: '2026-10-09T12:30:45' } });
expect(screen.getByText('2026-10-09 12:30:45')).toBeInTheDocument();
},
);
it('keeps effectiveTime authoritative when both timestamp fields are present', () => {
show({
mode: 'listing',
detail: {
...detail,
status: 'APPROVED',
effectiveTime: '2026-10-09T12:45:00',
approveTime: '2026-10-09T12:30:45',
},
});
expect(screen.getByText('2026-10-09 12:45:00')).toBeInTheDocument();
expect(screen.queryByText('2026-10-09 12:30:45')).not.toBeInTheDocument();
});
it('replaces stale detail with a retryable error', () => {
const retry = vi.fn();
show({ error: new Error('请求失败'), onRetry: retry });
expect(screen.queryByText('太阳膜-原厂')).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /重\s*试/ }));
expect(retry).toHaveBeenCalledOnce();
});
});