App.test.tsx
1.34 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
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import App from '../App';
// Mock child components to avoid deep rendering issues
vi.mock('../pages/Providers/ProviderList', () => ({
default: () => <div data-testid="provider-page">供应商管理</div>,
}));
vi.mock('../pages/Accounts/AccountList', () => ({
default: () => <div data-testid="account-page">账号配置</div>,
}));
// Mock authStore — 已登录状态
vi.mock('../stores/authStore', () => ({
useAuthStore: (selector: any) =>
selector({
token: 'mock-token',
user: { id: '1', username: 'admin', display_name: '管理员', role: 'admin', status: 'active' },
loading: false,
initialized: true,
login: vi.fn(),
logout: vi.fn(),
checkAuth: vi.fn(),
}),
}));
describe('App', () => {
it('显示侧边栏导航菜单、平台名称和用户信息', () => {
render(<App />);
// 平台名称
expect(screen.getByText('LLM 调度平台')).toBeInTheDocument();
// 侧边栏菜单项 - 使用 getAllByText 因为内容和菜单同时存在
expect(screen.getAllByText('供应商管理').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('账号配置')).toBeInTheDocument();
// 用户信息
expect(screen.getByText('管理员')).toBeInTheDocument();
});
});