ChannelCodeStatusOperations.test.tsx
4.09 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
import { fireEvent, render, screen, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it } from 'vitest';
import { App } from '../../App';
function renderChannelCodes(path = '/channel-codes') {
window.localStorage.setItem('agent-admin-local-login', 'true');
return render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
}
describe('Channel code enable/disable operations', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('shows enable confirmation dialog', () => {
renderChannelCodes();
// Find a disabled row (live_ops has status 'disable')
const disabledRow = screen.getByRole('row', { name: /直播运营渠道活码/ });
fireEvent.click(within(disabledRow).getByRole('button', { name: '启用直播运营渠道活码' }));
expect(screen.getByRole('dialog', { name: '确认启用"直播运营渠道活码"?' })).toBeInTheDocument();
expect(screen.getByText('启用后渠道活码将恢复可用,用户可以继续扫码添加。')).toBeInTheDocument();
});
it('shows disable confirmation dialog', () => {
renderChannelCodes();
// Find an enabled row (store_sales has status 'enable')
const enabledRow = screen.getByRole('row', { name: /店销顾问渠道活码/ });
fireEvent.click(within(enabledRow).getByRole('button', { name: '停用店销顾问渠道活码' }));
expect(screen.getByRole('dialog', { name: '确认停用"店销顾问渠道活码"?' })).toBeInTheDocument();
expect(screen.getByText('停用后渠道活码不可继续扫码使用,请确认是否继续。')).toBeInTheDocument();
});
it('cancels enable operation without changing status', () => {
renderChannelCodes();
const disabledRow = screen.getByRole('row', { name: /直播运营渠道活码/ });
fireEvent.click(within(disabledRow).getByRole('button', { name: '启用直播运营渠道活码' }));
fireEvent.click(screen.getByRole('button', { name: '取消' }));
expect(screen.queryByRole('dialog', { name: '确认启用' })).not.toBeInTheDocument();
// Status should remain unchanged
expect(within(disabledRow).getByText('停用')).toBeInTheDocument();
});
it('enables successfully and shows success message', () => {
renderChannelCodes();
const disabledRow = screen.getByRole('row', { name: /直播运营渠道活码/ });
fireEvent.click(within(disabledRow).getByRole('button', { name: '启用直播运营渠道活码' }));
fireEvent.click(screen.getByRole('button', { name: '确定' }));
expect(screen.queryByRole('dialog', { name: '确认启用' })).not.toBeInTheDocument();
expect(screen.getByRole('status', { name: '启用成功' })).toBeInTheDocument();
expect(within(disabledRow).getByText('启用')).toBeInTheDocument();
});
it('disables successfully and shows success message', () => {
renderChannelCodes('/channel-codes?scenario=normal');
const enabledRow = screen.getByRole('row', { name: /私域增长渠道活码/ });
fireEvent.click(within(enabledRow).getByRole('button', { name: '停用私域增长渠道活码' }));
fireEvent.click(screen.getByRole('button', { name: '确定' }));
expect(screen.queryByRole('dialog', { name: '确认停用' })).not.toBeInTheDocument();
expect(screen.getByRole('status', { name: '停用成功' })).toBeInTheDocument();
expect(within(enabledRow).getByText('停用')).toBeInTheDocument();
});
it('blocks disable with business error message', () => {
renderChannelCodes('/channel-codes?scenario=statusBlockError');
const enabledRow = screen.getByRole('row', { name: /店销顾问渠道活码/ });
fireEvent.click(within(enabledRow).getByRole('button', { name: '停用店销顾问渠道活码' }));
fireEvent.click(screen.getByRole('button', { name: '确定' }));
// The error message should be shown
const alert = screen.getByRole('alert');
expect(alert).toHaveTextContent('官网展示中');
// Status should remain enabled
expect(within(enabledRow).getByText('启用')).toBeInTheDocument();
});
});