ChannelCodeViewDrawer.test.tsx
4.28 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
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 view drawer', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('opens drawer when clicking view action', () => {
renderChannelCodes();
const firstRow = screen.getByRole('row', { name: /店销顾问渠道活码/ });
fireEvent.click(screen.getByRole('button', { name: '查看店销顾问渠道活码' }));
expect(screen.getByRole('dialog', { name: '店销顾问渠道活码' })).toBeInTheDocument();
});
it('shows all detail fields in drawer', () => {
renderChannelCodes();
fireEvent.click(screen.getByRole('button', { name: '查看店销顾问渠道活码' }));
const drawer = screen.getByRole('dialog', { name: '店销顾问渠道活码' });
expect(within(drawer).getByText('对应岗位')).toBeInTheDocument();
expect(within(drawer).getByText('渠道编码')).toBeInTheDocument();
expect(within(drawer).getByText('承接员工')).toBeInTheDocument();
expect(within(drawer).getByText('关联 Agent')).toBeInTheDocument();
expect(within(drawer).getByText('状态')).toBeInTheDocument();
expect(within(drawer).getByText('活码描述')).toBeInTheDocument();
expect(within(drawer).getByText('自动欢迎语')).toBeInTheDocument();
});
it('shows QR code image', () => {
renderChannelCodes();
fireEvent.click(screen.getByRole('button', { name: '查看店销顾问渠道活码' }));
expect(screen.getByRole('img', { name: '渠道活码二维码' })).toBeInTheDocument();
});
it('closes drawer and preserves list context', () => {
renderChannelCodes();
fireEvent.click(screen.getByRole('button', { name: '查看店销顾问渠道活码' }));
expect(screen.getByRole('dialog', { name: '店销顾问渠道活码' })).toBeInTheDocument();
// Drawer close button is aria-label="关闭{title}"
const closeButton = screen.getByRole('button', { name: '关闭店销顾问渠道活码' });
fireEvent.click(closeButton);
expect(screen.queryByRole('dialog', { name: '店销顾问渠道活码' })).not.toBeInTheDocument();
// List should still be visible
expect(screen.getByRole('heading', { name: '渠道活码管理' })).toBeInTheDocument();
expect(screen.getByText('店销顾问渠道活码')).toBeInTheDocument();
});
it('closes drawer via bottom close button', () => {
renderChannelCodes();
fireEvent.click(screen.getByRole('button', { name: '查看店销顾问渠道活码' }));
expect(screen.getByRole('dialog', { name: '店销顾问渠道活码' })).toBeInTheDocument();
const drawer = screen.getByRole('dialog', { name: '店销顾问渠道活码' });
// Footer close button uses "关闭" as text
const footerCloseButton = within(drawer).getByRole('button', { name: '关闭' });
fireEvent.click(footerCloseButton);
expect(screen.queryByRole('dialog', { name: '店销顾问渠道活码' })).not.toBeInTheDocument();
});
it('shows agent names as tags with unified color', () => {
renderChannelCodes();
fireEvent.click(screen.getByRole('button', { name: '查看店销顾问渠道活码' }));
const drawer = screen.getByRole('dialog', { name: '店销顾问渠道活码' });
// Should display agent names as tags
expect(within(drawer).getByText('店销助手Agent')).toBeInTheDocument();
expect(within(drawer).getByText('管家Agent')).toBeInTheDocument();
});
it('shows QR code load error state', () => {
renderChannelCodes('/channel-codes?scenario=qrcodeLoadError');
fireEvent.click(screen.getByRole('button', { name: '查看店销顾问渠道活码' }));
// Should show error state for QR code
expect(screen.getByText('二维码加载失败')).toBeInTheDocument();
// Other details should still be visible
const drawer = screen.getByRole('dialog', { name: '店销顾问渠道活码' });
expect(within(drawer).getByText('对应岗位')).toBeInTheDocument();
});
});