test: 建立桌面端自动化回归测试体系并完善跨平台 CI

(cherry picked from commit 74267ae2f63f8256c3da84b04f5b330e6e9d4c67)
This commit is contained in:
电摇小子
2026-08-03 10:08:28 +08:00
committed by Wxw-Gu
parent b4f909a597
commit 3e57a8432d
36 changed files with 2598 additions and 110 deletions
+53
View File
@@ -0,0 +1,53 @@
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
const requestImage = vi.fn()
vi.mock('../../src/renderer/src/components/image-loader', () => ({
getCachedLoadedImage: vi.fn(() => undefined),
requestImage: (...args: unknown[]) => requestImage(...args)
}))
import { ImageBubble } from '../../src/renderer/src/components/ImageBubble'
const thumbnail =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9ZQmcAAAAASUVORK5CYII='
const original = `${thumbnail}original`
describe('ImageBubble', () => {
beforeEach(() => {
requestImage.mockReset()
window.api = { copyImage: vi.fn().mockResolvedValue({ success: true }) } as typeof window.api
})
it('loads a thumbnail lazily, then requests the original when opened', async () => {
requestImage
.mockResolvedValueOnce({ data: thumbnail, isThumbnail: true })
.mockResolvedValueOnce({ data: original, isThumbnail: false })
const onImageClick = vi.fn()
render(
<ImageBubble
imageMd5="fixture-image"
imageDatName="fixture.dat"
sessionId="fixture-session"
onImageClick={onImageClick}
/>
)
const image = await screen.findByAltText('图片')
expect(image).toHaveAttribute('src', thumbnail)
await userEvent.click(image)
await waitFor(() => expect(onImageClick).toHaveBeenCalledWith(original))
expect(requestImage.mock.calls[1][3]).toMatchObject({ force: true })
})
it('shows an explicit error and allows retry', async () => {
requestImage.mockRejectedValueOnce(new Error('不支持的 DAT 版本'))
render(<ImageBubble imageMd5="unsupported" />)
expect(await screen.findByText('不支持的 DAT 版本')).toBeVisible()
requestImage.mockResolvedValueOnce({ data: thumbnail, isThumbnail: true })
await userEvent.click(screen.getByText('加载失败'))
expect(await screen.findByAltText('图片')).toBeVisible()
})
})