ChannelCodeRoutes.test.tsx
1.54 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
import { cleanup, render, screen } 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 routes and navigation', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('renders the list route at /channel-codes', () => {
renderChannelCodes();
expect(screen.getByRole('heading', { name: '渠道活码管理' })).toBeInTheDocument();
});
it('renders the new route at /channel-codes/new', () => {
renderChannelCodes('/channel-codes/new');
expect(screen.getByRole('heading', { name: '新增员工渠道活码' })).toBeInTheDocument();
});
it('renders the edit route at /channel-codes/:codeId/edit', () => {
renderChannelCodes('/channel-codes/1/edit');
expect(screen.getByRole('heading', { name: '编辑员工渠道活码' })).toBeInTheDocument();
});
it('shows navigation entry under Agent群管理 group', () => {
renderChannelCodes();
expect(screen.getByRole('button', { name: '渠道活码' })).toBeInTheDocument();
});
it('marks navigation entry as active when on channel-codes routes', () => {
renderChannelCodes();
expect(screen.getByRole('button', { name: '渠道活码' })).toHaveAttribute('aria-current', 'page');
});
});