import { fireEvent, render, screen } from '@testing-library/react'; import { ShortcutHelpDialog } from './ShortcutHelpDialog'; import { TreeSearchField } from './TreeSearchField'; import { EmptyWorkspace } from './WorkspaceOverlays'; import { ViewerDisplayPopover } from './ViewerDisplayPopover'; import { DEFAULT_VIEWER_DISPLAY_OPTIONS } from '../../viewer/displayOptions'; describe('第二批工作台组件', () => { it('搜索框发送内容并可清除', () => { const change = vi.fn(); const { rerender } = render(); fireEvent.change(screen.getByRole('searchbox'), { target: { value: 'arm' } }); expect(change).toHaveBeenCalledWith('arm'); rerender(); expect(screen.getByRole('status')).toHaveTextContent('找到 2 个匹配项'); fireEvent.click(screen.getByRole('button', { name: '清除搜索' })); expect(change).toHaveBeenLastCalledWith(''); }); it('快捷键帮助展示说明并支持 Escape', () => { const close = vi.fn(); render(); expect(screen.getByRole('dialog', { name: '快捷键与视口操作' })).toBeVisible(); expect(screen.getByText('播放 / 暂停')).toBeVisible(); fireEvent.keyDown(document, { key: 'Escape' }); expect(close).toHaveBeenCalledTimes(1); }); it('空工作区解释导入到仿真的三步流程', () => { render(); expect(screen.getByRole('region', { name: '导入模型工程' })).toBeVisible(); expect(screen.getByText('Local Simulation Workspace')).toBeVisible(); expect(screen.getByText('本地解析、编译并运行机器人模型,无需上传资源')).toBeVisible(); expect(screen.getByLabelText('支持格式')).toHaveTextContent('OBJ / STL / DAE'); expect(screen.getByRole('button', { name: '选择文件' })).toBeVisible(); expect(screen.getByRole('button', { name: '选择文件夹' })).toBeVisible(); expect(screen.queryByText('导入与仿真流程')).not.toBeInTheDocument(); expect(screen.getByRole('list', { name: '仿真工作流程' })).toHaveTextContent('导入'); expect(screen.getByRole('list', { name: '仿真工作流程' })).toHaveTextContent('检查与配置'); expect(screen.getByRole('list', { name: '仿真工作流程' })).toHaveTextContent('运行与调试'); expect(screen.getByText('模型与资源仅在当前浏览器会话中处理')).toBeVisible(); }); it('显示浮窗切换碰撞体和结构辅助标记', () => { const change = vi.fn(); render( , ); fireEvent.click(screen.getByRole('button', { name: '显示设置' })); expect(screen.getByRole('dialog', { name: '视图显示设置' })).toBeVisible(); expect(screen.getAllByRole('switch')).toHaveLength(7); fireEvent.click(screen.getByRole('switch', { name: /碰撞体/ })); expect(change).toHaveBeenCalledWith({ ...DEFAULT_VIEWER_DISPLAY_OPTIONS, showCollision: true }); }); });