Files
Genarrative/src/components/common/PlatformReportDialog.test.tsx
kdletters 7411b9a435 收口平台报告弹窗
新增 PlatformReportDialog 公共可复制报告弹窗组件
将 PlatformErrorDialog 与 PlatformTaskCompletionDialog 改为薄包装
同步更新 PlatformUiKit 收口文档与团队决策记录
2026-06-10 15:50:11 +08:00

60 lines
1.7 KiB
TypeScript

/* @vitest-environment jsdom */
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { afterEach, expect, test, vi } from 'vitest';
import * as clipboardService from '../../services/clipboard';
import { PlatformReportDialog } from './PlatformReportDialog';
vi.mock('../../services/clipboard', () => ({
copyTextToClipboard: vi.fn(),
}));
afterEach(() => {
vi.clearAllMocks();
});
test('renders report fields and copies the joined report lines', async () => {
vi.mocked(clipboardService.copyTextToClipboard).mockResolvedValue(true);
render(
<PlatformReportDialog
open
title="统一报告"
onClose={() => {}}
copyIdleLabel="复制内容"
fields={[
{ label: '来源', value: '拼图草稿 puzzle-session-1' },
{ label: '状态', value: '已完成', multiline: true },
]}
/>,
);
const dialog = screen.getByRole('dialog', { name: '统一报告' });
expect(within(dialog).getByText('拼图草稿 puzzle-session-1')).toBeTruthy();
expect(within(dialog).getByText('已完成')).toBeTruthy();
fireEvent.click(within(dialog).getByRole('button', { name: '复制内容' }));
expect(clipboardService.copyTextToClipboard).toHaveBeenCalledWith(
['来源:拼图草稿 puzzle-session-1', '状态:已完成'].join('\n'),
);
await waitFor(() => {
expect(within(dialog).getByRole('button', { name: '已复制' })).toBeTruthy();
});
});
test('does not render report fields when closed', () => {
render(
<PlatformReportDialog
open={false}
title="统一报告"
onClose={() => {}}
copyIdleLabel="复制内容"
fields={[]}
/>,
);
expect(screen.queryByRole('dialog', { name: '统一报告' })).toBeNull();
});