7ebe9092ba
web-platform-ci / Standalone decision service (no cloud credentials) (push) Has been cancelled
web-platform-ci / TypeScript, lint, unit, build (push) Has been cancelled
web-platform-ci / Playwright E2E (push) Has been cancelled
lekiwi-compatibility / cpu-compatibility (push) Has been cancelled
115 lines
4.8 KiB
TypeScript
115 lines
4.8 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import { UrdfImportOptionsDialog } from './UrdfImportOptionsDialog';
|
|
|
|
const capabilities = vi.hoisted(() => ({ training: true }));
|
|
vi.mock('../websiteConfig', () => ({ websiteCapabilities: capabilities }));
|
|
|
|
const mobileProfiles = ['MobileManipulator-LeKiwi-v1', 'MobileManipulator-LeKiwi-Bundle'];
|
|
|
|
describe('UrdfImportOptionsDialog', () => {
|
|
beforeEach(() => {
|
|
capabilities.training = true;
|
|
});
|
|
|
|
it.each(mobileProfiles)('本地版保留训练场景 %s', (profileId) => {
|
|
const onConfirm = vi.fn();
|
|
render(<UrdfImportOptionsDialog open onConfirm={onConfirm} onSkip={() => {}} />);
|
|
expect(screen.getAllByRole('option', { name: /移动操作训练场景/ })).toHaveLength(2);
|
|
fireEvent.change(screen.getByLabelText('URDF 机器人 profile'), {
|
|
target: { value: profileId },
|
|
});
|
|
expect(screen.getByText(/强化学习任务即可一键训练/)).toBeVisible();
|
|
fireEvent.click(screen.getByRole('button', { name: '转换并加载' }));
|
|
expect(onConfirm).toHaveBeenCalledWith(
|
|
{ addActuators: false, addSensors: false, sensorType: 'camera' },
|
|
profileId,
|
|
);
|
|
});
|
|
|
|
it('网站版移除训练选项,仍可选择普通 LeKiwi profile', () => {
|
|
capabilities.training = false;
|
|
const onConfirm = vi.fn();
|
|
render(<UrdfImportOptionsDialog open onConfirm={onConfirm} onSkip={() => {}} />);
|
|
expect(screen.queryAllByRole('option', { name: /移动操作训练场景/ })).toHaveLength(0);
|
|
expect(screen.queryByText(/强化学习任务即可一键训练/)).not.toBeInTheDocument();
|
|
expect(screen.getByRole('option', { name: '不启用(通用转换)' })).toBeInTheDocument();
|
|
fireEvent.change(screen.getByLabelText('URDF 机器人 profile'), {
|
|
target: { value: 'lekiwi-v1' },
|
|
});
|
|
fireEvent.click(screen.getByRole('button', { name: '转换并加载' }));
|
|
expect(onConfirm).toHaveBeenCalledWith(
|
|
{ addActuators: false, addSensors: false, sensorType: 'camera' },
|
|
'lekiwi-v1',
|
|
);
|
|
});
|
|
|
|
it.each(mobileProfiles)('网站版不沿用已移除的初始训练场景 %s', (profileId) => {
|
|
capabilities.training = false;
|
|
const onConfirm = vi.fn();
|
|
render(
|
|
<UrdfImportOptionsDialog
|
|
open
|
|
initialProfileId={profileId}
|
|
onConfirm={onConfirm}
|
|
onSkip={() => {}}
|
|
/>,
|
|
);
|
|
expect(screen.getByLabelText('URDF 机器人 profile')).toHaveValue('');
|
|
expect(screen.queryByText(/强化学习任务即可一键训练/)).not.toBeInTheDocument();
|
|
expect(screen.getByRole('checkbox', { name: /为关节添加驱动器/ })).toBeEnabled();
|
|
expect(screen.getByRole('button', { name: '不添加,直接加载' })).toBeEnabled();
|
|
fireEvent.click(screen.getByRole('button', { name: '转换并加载' }));
|
|
expect(onConfirm).toHaveBeenCalledWith(
|
|
expect.objectContaining({ addActuators: true, addSensors: true }),
|
|
);
|
|
});
|
|
|
|
it('默认选择关节驱动器和摄像头传感器', () => {
|
|
const onConfirm = vi.fn();
|
|
render(
|
|
<UrdfImportOptionsDialog
|
|
open
|
|
path="robot.urdf"
|
|
mountBodies={['base', 'head_link']}
|
|
onConfirm={onConfirm}
|
|
onSkip={() => {}}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole('checkbox', { name: /为关节添加驱动器/ })).toBeChecked();
|
|
expect(screen.getByRole('checkbox', { name: /添加传感器/ })).toBeChecked();
|
|
expect(screen.getByLabelText('摄像头固连 Body')).toHaveValue('head_link');
|
|
fireEvent.change(screen.getByLabelText('摄像头位置 X'), { target: { value: '0.2' } });
|
|
fireEvent.click(screen.getByRole('button', { name: '转换并加载' }));
|
|
expect(onConfirm).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
addActuators: true,
|
|
addSensors: true,
|
|
sensorType: 'camera',
|
|
cameraMountBody: 'head_link',
|
|
cameraPosition: [0.2, 0, 0.05],
|
|
cameraDirection: '+X',
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('允许分别关闭自动生成项', () => {
|
|
const onConfirm = vi.fn();
|
|
render(
|
|
<UrdfImportOptionsDialog open path="robot.urdf" onConfirm={onConfirm} onSkip={() => {}} />,
|
|
);
|
|
fireEvent.click(screen.getByRole('checkbox', { name: /为关节添加驱动器/ }));
|
|
fireEvent.click(screen.getByRole('checkbox', { name: /添加传感器/ }));
|
|
fireEvent.click(screen.getByRole('button', { name: '转换并加载' }));
|
|
expect(onConfirm).toHaveBeenCalledWith(
|
|
expect.objectContaining({ addActuators: false, addSensors: false, sensorType: 'camera' }),
|
|
);
|
|
});
|
|
|
|
it('可以不添加组件并继续加载', () => {
|
|
const onSkip = vi.fn();
|
|
render(<UrdfImportOptionsDialog open path="robot.urdf" onConfirm={() => {}} onSkip={onSkip} />);
|
|
fireEvent.click(screen.getByRole('button', { name: '不添加,直接加载' }));
|
|
expect(onSkip).toHaveBeenCalledOnce();
|
|
});
|
|
});
|