import { useState } from 'react'; import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { CloudComposerAttachments } from '@/pages/CloudAgents/CloudComposerAttachments'; import { CloudPendingContext } from '@/pages/CloudAgents/CloudPending'; import type { CloudAttachment, CloudHistory, CloudUpload } from '../../shared/cloud-agents'; const api = vi.hoisted(() => ({ call: vi.fn(), upload: vi.fn(), download: vi.fn() })); vi.mock('@/lib/cloud-agents-api', () => ({ cloudAgentsApi: api })); const photo: CloudAttachment = { file_id: 'photo-id', file_name: '我的画.png', file_size: 8192, path: '/attachments/photo', original_path: '/original/photo' }; const document: CloudAttachment = { file_id: 'document-id', file_name: '故事.docx', file_size: 1200, path: '/attachments/story', original_path: '/original/story' }; const upload: CloudUpload = { object_name: 'temporary/photo-object', file_name: photo.file_name, file_type: 'image/png', parse_supported: true, parse_methods: ['disable', 'rapid_ocr'] }; function delivered(threadId: string, path: string): CloudHistory { return { thread_id: threadId, next_offset: null, run: null, messages: [{ id: 1, role: 'assistant', content: `[下载文件](sandbox:${path})`, request_id: 'delivery-request', run_id: null, created_at: '', }] }; } function deferred() { let resolve!: (value: T) => void; let reject!: (error: Error) => void; const promise = new Promise((done, fail) => { resolve = done; reject = fail; }); return { promise, resolve, reject }; } function operationCalls(operation: string) { return api.call.mock.calls.filter(([name]) => name === operation); } function open({ initialSelected = [], threadId, disabled = false, deliveryHistory, ensureThread = vi.fn().mockResolvedValue('thread-created') }: { initialSelected?: string[]; threadId?: string; disabled?: boolean; deliveryHistory?: CloudHistory; ensureThread?: () => Promise; } = {}) { const onBusy = vi.fn(); const onSelected = vi.fn(); const pending = vi.fn(); const submit = vi.fn(); function Harness({ disabled, threadId }: { disabled: boolean; threadId?: string }) { const [selected, setSelected] = useState(initialSelected); const [text, setText] = useState('保留这些文字'); return
{ event.preventDefault(); submit(); }}> { onSelected(value); setSelected(value); }} footer={发送区}>