- 登录页、侧栏和 favicon 统一引用 public/logo.png 暴露的 /logo.png。 - 删除根目录 logo_square.png 和 Express 中单独提供该文件的路由。 - 同步更新组件测试、项目文档和历史工程分析说明,避免继续引用旧 logo_square。 - 同步整理 ../Seg_Server_Docker 部署包,仅保留 public/logo.png 并更新前端 Docker 构建配置。
61 lines
2.4 KiB
TypeScript
61 lines
2.4 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||
import { resetStore } from '../test/storeTestUtils';
|
||
import { useStore } from '../store/useStore';
|
||
import { Sidebar } from './Sidebar';
|
||
|
||
vi.mock('./ModelStatusBadge', () => ({
|
||
ModelStatusBadge: () => <div>模型状态</div>,
|
||
}));
|
||
|
||
describe('Sidebar', () => {
|
||
beforeEach(() => {
|
||
resetStore();
|
||
});
|
||
|
||
it('shows admin user management only for admin users', () => {
|
||
const setActiveModule = vi.fn();
|
||
useStore.setState({ currentUser: { id: 1, username: 'admin', role: 'admin' } });
|
||
|
||
render(<Sidebar activeModule="dashboard" setActiveModule={setActiveModule} />);
|
||
|
||
const adminButton = screen.getByTitle('用户管理');
|
||
expect(adminButton.querySelector('.lucide-circle-user')).toBeInTheDocument();
|
||
fireEvent.click(adminButton);
|
||
expect(setActiveModule).toHaveBeenCalledWith('admin');
|
||
});
|
||
|
||
it('hides admin user management for non-admin users', () => {
|
||
useStore.setState({ currentUser: { id: 2, username: 'doctor', role: 'annotator' } });
|
||
|
||
render(<Sidebar activeModule="dashboard" setActiveModule={vi.fn()} />);
|
||
|
||
expect(screen.queryByTitle('用户管理')).not.toBeInTheDocument();
|
||
});
|
||
|
||
it('uses an explicit AI-styled icon for AI segmentation', () => {
|
||
useStore.setState({ currentUser: { id: 2, username: 'doctor', role: 'annotator' } });
|
||
|
||
render(<Sidebar activeModule="dashboard" setActiveModule={vi.fn()} />);
|
||
|
||
expect(screen.getByTitle('AI智能分割').querySelector('[data-testid="ai-segmentation-icon"]')).toBeInTheDocument();
|
||
});
|
||
|
||
it('uses the public logo asset for the sidebar logo', () => {
|
||
render(<Sidebar activeModule="dashboard" setActiveModule={vi.fn()} />);
|
||
|
||
expect(screen.getByAltText('Logo')).toHaveAttribute('src', expect.stringContaining('logo.png'));
|
||
});
|
||
|
||
it('uses a logout icon and prevents the logout tooltip from catching workspace hover', () => {
|
||
useStore.setState({ currentUser: { id: 1, username: 'admin', role: 'admin' } });
|
||
|
||
render(<Sidebar activeModule="dashboard" setActiveModule={vi.fn()} />);
|
||
|
||
const logoutButton = screen.getByTitle('当前用户:admin,点击退出');
|
||
expect(logoutButton.querySelector('.lucide-log-out')).toBeInTheDocument();
|
||
expect(screen.getByText('admin / 退出')).toHaveClass('pointer-events-none');
|
||
expect(screen.getByText('admin / 退出')).toHaveClass('invisible');
|
||
});
|
||
});
|