OfficialSiteMethodologyRoute.test.tsx
1.76 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 { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it } from 'vitest';
import { App } from '../../App';
function renderApp(path = '/official-site/methodology') {
window.localStorage.setItem('agent-admin-local-login', 'true');
return render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
}
describe('official site methodology route and navigation', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('renders the methodology page inside admin shell with correct menu ownership', () => {
renderApp();
expect(screen.getByRole('heading', { name: '方法论展示配置' })).toBeInTheDocument();
expect(screen.getByText('官网配置 / 方法论展示配置')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '方法论展示配置' })).toHaveAttribute('aria-current', 'page');
expect(screen.getByRole('button', { name: 'Agent列表' })).not.toHaveAttribute('aria-current');
});
it('shows the official site navigation entry and can navigate to the methodology page from agents', () => {
renderApp('/agents');
fireEvent.click(screen.getByRole('button', { name: '方法论展示配置' }));
expect(screen.getByRole('heading', { name: '方法论展示配置' })).toBeInTheDocument();
expect(screen.getByText('官网配置 / 方法论展示配置')).toBeInTheDocument();
});
it('keeps the protected index redirect pointing to agents by default', () => {
renderApp('/');
expect(screen.getByRole('heading', { name: 'Agent管理' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Agent列表' })).toHaveAttribute('aria-current', 'page');
});
});