OfficialSiteMethodologyRoute.test.tsx
3.65 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
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { App } from '../../App';
import { getAgentList } from '../../api/agent';
import { getMethodologyConfig, saveMethodologyConfig } from '../../api/methodology';
vi.mock('../../api/agent', () => ({
getAgentList: vi.fn(),
getAgentDetail: vi.fn(),
deleteAgent: vi.fn(),
updateAgentStatus: vi.fn(),
createAgent: vi.fn(),
updateAgent: vi.fn(),
getEmployeeMounts: vi.fn(() => Promise.resolve({ employee_count: 0, employees: [] })),
}));
vi.mock('../../api/methodology', () => ({
getMethodologyConfig: vi.fn(),
saveMethodologyConfig: vi.fn(),
}));
vi.mock('../../api/analytics', () => ({
reportPageView: vi.fn().mockResolvedValue({ success: true }),
reportAnalyticsEvents: vi.fn().mockResolvedValue({ success: true }),
}));
const mockMethodologyConfig = {
config_id: 'methodology_001',
display_status: 'enable' as const,
main_title: '四步打造可复用的岗位 Agent',
sub_title: '从目标澄清到上线复盘,帮助团队沉淀一套稳定可复制的方法论。',
steps: [
{
step_id: 's1',
step_icon: 'https://cdn.example.com/icon1.png',
step_name: '需求澄清',
step_order: 1,
step_image: 'https://cdn.example.com/image1.png',
},
],
updated_at: '2026-05-16T10:00:00Z',
};
function renderApp(path = '/official-site/methodology') {
window.localStorage.setItem('agent-admin-local-login', 'true');
return render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
}
function getMenuItem(label: string) {
const item = within(screen.getByLabelText('左侧导航')).getByText(label).closest('li');
if (!item) throw new Error(`Menu item ${label} was not found`);
return item;
}
describe('official site methodology route and navigation', () => {
beforeEach(() => {
window.localStorage.clear();
vi.clearAllMocks();
vi.mocked(getAgentList).mockResolvedValue({ list: [], total: 0, page: 1, page_size: 10 });
vi.mocked(getMethodologyConfig).mockResolvedValue(mockMethodologyConfig);
vi.mocked(saveMethodologyConfig).mockResolvedValue({ config_id: 'methodology_001', updated_at: '2026-05-16T12:00:00Z' });
});
it('renders the methodology page inside admin shell with correct menu ownership', async () => {
renderApp();
expect(await screen.findByRole('heading', { name: '方法论展示配置' })).toBeInTheDocument();
expect(screen.getAllByText('官网配置').length).toBeGreaterThan(0);
expect(screen.getAllByText('方法论展示配置').length).toBeGreaterThan(0);
expect(getMenuItem('方法论展示配置')).toHaveClass('t-is-active');
expect(getMenuItem('Agent列表')).not.toHaveClass('t-is-active');
});
it('shows the official site navigation entry and can navigate to the methodology page from agents', async () => {
renderApp('/agents');
await waitFor(() => {
expect(getMenuItem('Agent列表')).toHaveClass('t-is-active');
});
fireEvent.click(getMenuItem('方法论展示配置'));
expect(await screen.findByRole('heading', { name: '方法论展示配置' })).toBeInTheDocument();
expect(screen.getAllByText('官网配置').length).toBeGreaterThan(0);
expect(screen.getAllByText('方法论展示配置').length).toBeGreaterThan(0);
});
it('keeps the protected index redirect pointing to agents by default', async () => {
renderApp('/');
expect(await screen.findByRole('heading', { name: 'Agent管理' })).toBeInTheDocument();
expect(getMenuItem('Agent列表')).toHaveClass('t-is-active');
});
});