import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ExportTaskCenter } from '../../src/renderer/src/components/export/ExportTaskCenter'
describe('export task center', () => {
const writeText = vi.fn().mockResolvedValue(undefined)
beforeEach(() => {
writeText.mockClear()
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText }
})
})
it('shows the failure reason and copies a diagnostic log', async () => {
render(
)
expect(
screen.getByText('失败原因:EPERM: operation not permitted, copyfile')
).toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: '复制日志' }))
expect(writeText).toHaveBeenCalledOnce()
expect(writeText.mock.calls[0][0]).toContain('会话:脱敏会话')
expect(writeText.mock.calls[0][0]).toContain('EPERM: operation not permitted, copyfile')
expect(screen.getByRole('button', { name: '已复制' })).toBeInTheDocument()
})
it('shows the current conversation for a background all-export task', () => {
render(
)
expect(screen.getByText('第 9/20 个:项目群')).toBeVisible()
expect(screen.getByText('42%')).toBeVisible()
})
})