OfficialSiteAgentDisplayConfigRoutes.test.tsx
3.16 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
import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it } from 'vitest';
import { App } from '../../App';
import { resetAgentDisplayConfigMockState } from '../../../packages/contracts/official-site-agent-display-config-mock';
import { resetOfficialSiteJobTabMockState } from '../../../packages/contracts/official-site-job-tab-mock';
function renderApp(path = '/official-site/job-tabs/1/agents') {
window.localStorage.setItem('agent-admin-local-login', 'true');
return render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
}
describe('official site agent display config routes and navigation', () => {
beforeEach(() => {
window.localStorage.clear();
resetOfficialSiteJobTabMockState();
resetAgentDisplayConfigMockState();
});
it('renders the agent display config page at /official-site/job-tabs/:tabId/agents', () => {
renderApp();
expect(screen.getByRole('heading', { name: '店销顾问 - 店销顾问渠道活码 - Agent展示配置' })).toBeInTheDocument();
});
it('shows navigation entry under 官网配置 group', () => {
renderApp();
expect(screen.getByRole('button', { name: '岗位展示配置' })).toBeInTheDocument();
});
it('marks 岗位展示配置 navigation entry as active when on agents route', () => {
renderApp();
expect(screen.getByRole('button', { name: '岗位展示配置' })).toHaveAttribute('aria-current', 'page');
});
it('shows breadcrumb for agent display config page', () => {
renderApp();
expect(screen.getByText('官网配置 / 岗位展示配置')).toBeInTheDocument();
});
it('shows return to list button', () => {
renderApp();
expect(screen.getByRole('button', { name: '返回' })).toBeInTheDocument();
});
it('shows position name in page title', () => {
renderApp();
expect(screen.getByRole('heading', { name: /店销顾问.*Agent展示配置/ })).toBeInTheDocument();
});
it('shows tab context info (qrcode, channel code, employee)', () => {
renderApp();
expect(screen.getByText('店销顾问渠道活码')).toBeInTheDocument();
expect(screen.getByText('DSC-QR-001')).toBeInTheDocument();
expect(screen.getByText((content) => content.includes('张小萌'))).toBeInTheDocument();
});
it('returns to job tabs list when clicking return button', () => {
renderApp();
fireEvent.click(screen.getByRole('button', { name: '返回' }));
expect(screen.getByRole('heading', { name: '岗位展示配置' })).toBeInTheDocument();
});
it('shows error state for non-existent tab', () => {
renderApp('/official-site/job-tabs/99999/agents');
expect(screen.getByText('岗位展示配置不存在')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '返回列表' })).toBeInTheDocument();
});
it('can navigate to agent display config from job tabs list', () => {
renderApp('/official-site/job-tabs');
fireEvent.click(screen.getByRole('button', { name: '配置Agent-店销顾问' }));
expect(screen.getByRole('heading', { name: /店销顾问.*Agent展示配置/ })).toBeInTheDocument();
});
});