1ad25e30f8
新增 PlatformUiKit 通用弹窗、按钮、状态、空态、媒体、表单和标签等公共组件 迁移结果页、创作工作台、认证入口、RPG 暗色面板和运行态弹窗的重复 UI chrome 补充组件测试、页面回归测试、技术文档和 Hermes 共享决策记录
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
/* @vitest-environment jsdom */
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { expect, test, vi } from 'vitest';
|
|
|
|
import { BabyObjectMatchWorkspace } from './BabyObjectMatchWorkspace';
|
|
|
|
function findNearestClassName(
|
|
element: HTMLElement,
|
|
classNamePart: string,
|
|
): HTMLElement | null {
|
|
let current: HTMLElement | null = element;
|
|
|
|
while (current) {
|
|
if (current.className.includes(classNamePart)) {
|
|
return current;
|
|
}
|
|
|
|
current = current.parentElement;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
test('baby object match workspace requires two item names before submit', async () => {
|
|
const user = userEvent.setup();
|
|
const onCreateDraft = vi.fn();
|
|
|
|
render(
|
|
<BabyObjectMatchWorkspace
|
|
onBack={() => {}}
|
|
onCreateDraft={onCreateDraft}
|
|
title="宝贝识物"
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText('BETA').className).toContain('rounded-full');
|
|
expect(screen.getByText('BETA').className).toContain('border-emerald-200');
|
|
expect(screen.getByLabelText('宝贝识物图标').className).toContain('h-14');
|
|
expect(screen.getByLabelText('宝贝识物图标').className).toContain(
|
|
'bg-white/84',
|
|
);
|
|
expect(
|
|
findNearestClassName(
|
|
screen.getByLabelText('宝贝识物图标'),
|
|
'bg-[linear-gradient',
|
|
)?.className,
|
|
).toContain('rounded-[1.25rem]');
|
|
|
|
const submitButton = screen.getByRole('button', {
|
|
name: /生成宝贝识物草稿/u,
|
|
});
|
|
expect(submitButton).toHaveProperty('disabled', true);
|
|
|
|
await user.type(screen.getByLabelText('物品 A'), '苹果');
|
|
expect(submitButton).toHaveProperty('disabled', true);
|
|
|
|
await user.type(screen.getByLabelText('物品 B'), '香蕉');
|
|
expect(submitButton).toHaveProperty('disabled', false);
|
|
|
|
await user.click(submitButton);
|
|
|
|
expect(onCreateDraft).toHaveBeenCalledWith({
|
|
itemAName: '苹果',
|
|
itemBName: '香蕉',
|
|
});
|
|
});
|
|
|
|
test('baby object match workspace calls back when return button is clicked', async () => {
|
|
const user = userEvent.setup();
|
|
const onBack = vi.fn();
|
|
|
|
render(<BabyObjectMatchWorkspace onBack={onBack} onCreateDraft={() => {}} />);
|
|
|
|
await user.click(screen.getByRole('button', { name: '返回' }));
|
|
|
|
expect(onBack).toHaveBeenCalledTimes(1);
|
|
});
|