新增 PlatformUiKit 通用弹窗、按钮、状态、空态、媒体、表单和标签等公共组件 迁移结果页、创作工作台、认证入口、RPG 暗色面板和运行态弹窗的重复 UI chrome 补充组件测试、页面回归测试、技术文档和 Hermes 共享决策记录
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
/* @vitest-environment jsdom */
|
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import { expect, test, vi } from 'vitest';
|
|
|
|
import { PlatformPillSwitch } from './PlatformPillSwitch';
|
|
|
|
test('renders checked pill switch with platform chrome', () => {
|
|
render(
|
|
<PlatformPillSwitch
|
|
label="AI重绘"
|
|
aria-label="AI重绘"
|
|
checked
|
|
onChange={() => {}}
|
|
/>,
|
|
);
|
|
|
|
const switchInput = screen.getByRole('switch', { name: 'AI重绘' });
|
|
|
|
expect(switchInput).toHaveProperty('checked', true);
|
|
expect(screen.getByText('AI重绘').closest('label')?.className).toContain(
|
|
'bg-white/94',
|
|
);
|
|
expect(screen.getByText('AI重绘').closest('label')?.className).toContain(
|
|
'backdrop-blur',
|
|
);
|
|
});
|
|
|
|
test('calls onChange when toggled', () => {
|
|
const onChange = vi.fn();
|
|
|
|
render(
|
|
<PlatformPillSwitch
|
|
label="AI重绘"
|
|
aria-label="AI重绘"
|
|
checked={false}
|
|
onChange={onChange}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole('switch', { name: 'AI重绘' }));
|
|
|
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
test('keeps disabled switch inert and styled as disabled', () => {
|
|
const onChange = vi.fn();
|
|
|
|
render(
|
|
<PlatformPillSwitch
|
|
label="AI重绘"
|
|
aria-label="AI重绘"
|
|
checked={false}
|
|
disabled
|
|
onChange={onChange}
|
|
/>,
|
|
);
|
|
|
|
const switchInput = screen.getByRole('switch', { name: 'AI重绘' });
|
|
|
|
expect(switchInput).toHaveProperty('disabled', true);
|
|
expect(screen.getByText('AI重绘').closest('label')?.className).toContain(
|
|
'cursor-not-allowed',
|
|
);
|
|
});
|
|
|
|
test('keeps local placement classes', () => {
|
|
render(
|
|
<PlatformPillSwitch
|
|
label="AI重绘"
|
|
aria-label="AI重绘"
|
|
checked={false}
|
|
className="absolute bottom-3 left-3"
|
|
onChange={() => {}}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText('AI重绘').closest('label')?.className).toContain(
|
|
'bottom-3',
|
|
);
|
|
});
|