ApprovalActionModal.test.tsx
3.29 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
import { render, screen, within } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import type { ApprovalRow } from '@/api';
import { ApprovalActionModal, type ApprovalActionType } from './ApprovalActionModal';
function renderAction(
levels: Array<Pick<ApprovalRow, 'currentLevel' | 'totalLevel'>>,
type: ApprovalActionType = 'pass',
) {
const records: ApprovalRow[] = levels.map((level, index) => ({
listingId: String(index + 1),
storeName: `门店${index + 1}`,
merchantNo: `SQ00${index + 1}`,
businessScene: '精品升级',
status: 'PENDING',
...level,
}));
render(
<ApprovalActionModal
action={{ type, records }}
pending={false}
confirmed={false}
reason=""
onConfirmed={vi.fn()}
onReason={vi.fn()}
onCancel={vi.fn()}
onConfirm={vi.fn()}
/>,
);
return within(screen.getByRole('dialog')).getByRole('alert');
}
describe('通过确认的审批结果提示', () => {
it.each([
{ currentLevel: 2, totalLevel: 2 },
{ currentLevel: 1, totalLevel: 1 },
{ currentLevel: 3, totalLevel: 3 },
])('第 $currentLevel / $totalLevel 级终审通过后提示生效,不提示还有后续审批', (level) => {
const alert = renderAction([level]);
expect(alert).toHaveTextContent('通过当前审批节点后,记录将立即生效并进入门店列表。');
expect(alert).not.toHaveTextContent('后续审批');
});
it('中间审批节点提示仍需后续审批', () => {
const alert = renderAction([{ currentLevel: 1, totalLevel: 2 }]);
expect(alert).toHaveTextContent('记录将继续后续审批');
expect(alert).not.toHaveTextContent('立即生效');
});
it('批量全部终审时提示生效,不受终审总层级差异影响', () => {
const alert = renderAction(
[
{ currentLevel: 1, totalLevel: 1 },
{ currentLevel: 2, totalLevel: 2 },
],
'batch',
);
expect(alert).toHaveTextContent('记录将立即生效并进入门店列表');
expect(alert).not.toHaveTextContent('后续审批');
});
it('批量包含不同审批阶段时分别说明终审生效和继续后续审批', () => {
const alert = renderAction(
[
{ currentLevel: 2, totalLevel: 2 },
{ currentLevel: 1, totalLevel: 2 },
],
'batch',
);
expect(alert).toHaveTextContent('终审记录通过后将立即生效并进入门店列表');
expect(alert).toHaveTextContent('其余记录将继续后续审批');
});
it.each([
{},
{ currentLevel: null, totalLevel: null },
{ currentLevel: 0, totalLevel: 0 },
{ currentLevel: 3, totalLevel: 2 },
])('缺少或非法审批层级不承诺立即生效,也不假定还有后续审批:%j', (level) => {
const alert = renderAction([level]);
expect(alert).toHaveTextContent('系统将按记录的审批进度处理');
expect(alert).not.toHaveTextContent('立即生效');
expect(alert).not.toHaveTextContent('继续后续审批');
});
it('批量存在未知层级时不会将已知终审结果套用到全部记录', () => {
const alert = renderAction([{ currentLevel: 2, totalLevel: 2 }, {}], 'batch');
expect(alert).toHaveTextContent('系统将按记录的审批进度处理');
expect(alert).not.toHaveTextContent('立即生效');
});
});