Files
Genarrative/src/components/platform-entry/PlatformErrorDialog.test.tsx
T
kdletters 1ad25e30f8 收口前端平台组件库能力
新增 PlatformUiKit 通用弹窗、按钮、状态、空态、媒体、表单和标签等公共组件
迁移结果页、创作工作台、认证入口、RPG 暗色面板和运行态弹窗的重复 UI chrome
补充组件测试、页面回归测试、技术文档和 Hermes 共享决策记录
2026-06-10 10:24:18 +08:00

126 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* @vitest-environment jsdom */
import {
fireEvent,
render,
screen,
waitFor,
within,
} from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
import * as clipboardService from '../../services/clipboard';
import { PlatformErrorDialog } from './PlatformErrorDialog';
import { PlatformTaskCompletionDialog } from './PlatformTaskCompletionDialog';
vi.mock('../../services/clipboard', () => ({
copyTextToClipboard: vi.fn(),
}));
afterEach(() => {
vi.clearAllMocks();
});
describe('PlatformErrorDialog', () => {
test('shows source, message, and copies the full error report', async () => {
vi.mocked(clipboardService.copyTextToClipboard).mockResolvedValue(true);
render(
<PlatformErrorDialog
error={{
source: '拼图草稿 puzzle-session-123',
message: '图片生成失败,请稍后再试。',
}}
onClose={() => {}}
/>,
);
const dialog = screen.getByRole('dialog', { name: '发生错误' });
expect(
within(dialog).getByText('拼图草稿 puzzle-session-123'),
).toBeTruthy();
expect(within(dialog).getByText('图片生成失败,请稍后再试。')).toBeTruthy();
fireEvent.click(within(dialog).getByRole('button', { name: '复制报错' }));
expect(clipboardService.copyTextToClipboard).toHaveBeenCalledWith(
[
'来源:拼图草稿 puzzle-session-123',
'错误:图片生成失败,请稍后再试。',
].join('\n'),
);
await waitFor(() => {
expect(
within(dialog).getByRole('button', { name: '已复制' }),
).toBeTruthy();
});
});
test('does not render when there is no active error', () => {
render(<PlatformErrorDialog error={null} onClose={() => {}} />);
expect(screen.queryByRole('dialog', { name: '发生错误' })).toBeNull();
});
test('does not render creation entry disabled errors', () => {
render(
<PlatformErrorDialog
error={{
source: '大鱼草稿',
message: 'creation_entry_disabledrequestId: req-big-fish-gallery',
}}
onClose={() => {}}
/>,
);
expect(screen.queryByRole('dialog', { name: '发生错误' })).toBeNull();
expect(screen.queryByText(/creation_entry_disabled/u)).toBeNull();
});
});
describe('PlatformTaskCompletionDialog', () => {
test('shows source, message, and copies the full completion report', async () => {
vi.mocked(clipboardService.copyTextToClipboard).mockResolvedValue(true);
render(
<PlatformTaskCompletionDialog
completion={{
source: '抓大鹅草稿 match3d-notice-session-1',
message: '生成任务已完成,可以继续查看草稿。',
}}
onClose={() => {}}
/>,
);
const dialog = screen.getByRole('dialog', { name: '生成完成' });
expect(
within(dialog).getByText('抓大鹅草稿 match3d-notice-session-1'),
).toBeTruthy();
expect(
within(dialog).getByText('生成任务已完成,可以继续查看草稿。'),
).toBeTruthy();
fireEvent.click(within(dialog).getByRole('button', { name: '复制内容' }));
expect(clipboardService.copyTextToClipboard).toHaveBeenCalledWith(
[
'来源:抓大鹅草稿 match3d-notice-session-1',
'状态:生成任务已完成,可以继续查看草稿。',
].join('\n'),
);
await waitFor(() => {
expect(
within(dialog).getByRole('button', { name: '已复制' }),
).toBeTruthy();
});
});
test('does not render when there is no active completion', () => {
render(
<PlatformTaskCompletionDialog completion={null} onClose={() => {}} />,
);
expect(screen.queryByRole('dialog', { name: '生成完成' })).toBeNull();
});
});