feat: 平台错误与完成弹窗收口

This commit is contained in:
kdletters
2026-05-26 15:57:39 +08:00
parent fbda614156
commit abea7cec1d
6 changed files with 347 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ 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(),
@@ -58,3 +59,49 @@ describe('PlatformErrorDialog', () => {
expect(screen.queryByRole('dialog', { name: '发生错误' })).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();
});
});