feat: mac 档案与导出支持加载原图原视频

This commit is contained in:
Wxw-Gu committed 2026-12-01 10:40:58 +08:00
1 parent fccca5b459
commit b20e514c90
31 files changed
+1884 -111

No files matched your search

@@ -70,4 +70,62 @@ describe('ChatImageViewer', () => {
await waitFor(() => expect(opener).toHaveFocus())
expect(onClose).toHaveBeenCalledTimes(2)
})
it('loads the original image from the top toolbar and updates the displayed src', async () => {
const user = userEvent.setup()
const hdUrl = `${imageUrl}#hd`
const onDownloadOriginal = vi.fn().mockResolvedValue({ success: true, data: hdUrl })
const onImageChange = vi.fn()
render(
<TooltipProvider>
<ChatImageViewer
imageUrl={imageUrl}
onDownloadOriginal={onDownloadOriginal}
onImageChange={onImageChange}
onClose={vi.fn()}
/>
</TooltipProvider>
)
const loadButton = screen.getByRole('button', { name: '加载原图' })
await user.click(loadButton)
await waitFor(() => expect(onDownloadOriginal).toHaveBeenCalledTimes(1))
expect(screen.getByAltText('图片预览')).toHaveAttribute('src', hdUrl)
expect(onImageChange).toHaveBeenCalledWith(hdUrl)
expect(screen.getByRole('button', { name: '已加载原图' })).toBeVisible()
})
it('surfaces an inline error when loading the original image fails', async () => {
const user = userEvent.setup()
const onDownloadOriginal = vi.fn().mockResolvedValue({
success: false,
error: '图片已在微信服务器过期'
})
render(
<TooltipProvider>
<ChatImageViewer
imageUrl={imageUrl}
onDownloadOriginal={onDownloadOriginal}
onClose={vi.fn()}
/>
</TooltipProvider>
)
await user.click(screen.getByRole('button', { name: '加载原图' }))
expect(await screen.findByRole('alert')).toHaveTextContent('图片已在微信服务器过期')
expect(screen.getByAltText('图片预览')).toHaveAttribute('src', imageUrl)
})
it('hides the load-original button when send/runtime capability is unavailable', () => {
render(
<TooltipProvider>
<ChatImageViewer imageUrl={imageUrl} onClose={vi.fn()} />
</TooltipProvider>
)
expect(screen.queryByRole('button', { name: '加载原图' })).not.toBeInTheDocument()
})
})
+38
View File
@@ -226,6 +226,7 @@ describe('ExportWorkspace multi-chat selection', () => {
it('restores export preferences after leaving and reopening the workspace', async () => {
const { unmount } = renderWorkspace()
await userEvent.click(screen.getByRole('button', { name: '前往设置 · 发送能力 →' }))
await userEvent.click(
within(screen.getByRole('radiogroup', { name: '导出格式' })).getByRole('radio', {
name: /HTML/
@@ -309,6 +310,43 @@ describe('ExportWorkspace multi-chat selection', () => {
})
).toBeChecked()
})
it('switches the original media option label and passes downloadOriginalMedia when Mac hook send capability is available', async () => {
const onStartExport = vi.fn(async () => ({ success: false }))
Object.defineProperty(window, 'api', {
configurable: true,
value: {
...window.api,
getMacSendRuntimeAvailability: vi
.fn()
.mockResolvedValue({ state: 'available', message: '微信发送组件可用' })
}
})
renderWorkspace(onStartExport)
expect(
await screen.findByRole('checkbox', {
name: '下载原图原视频替换(如视频或图片过期可导致下载失败)'
})
).toBeChecked()
await userEvent.click(screen.getByRole('button', { name: '前往设置 · 发送能力 →' }))
await userEvent.click(
within(screen.getByRole('radiogroup', { name: '导出格式' })).getByRole('radio', {
name: /HTML/
})
)
await userEvent.click(screen.getByRole('button', { name: '开始导出' }))
await waitFor(() => expect(onStartExport).toHaveBeenCalledOnce())
expect(onStartExport).toHaveBeenCalledWith(
expect.objectContaining({
preferOriginal: true,
downloadOriginalMedia: true
})
)
})
})
describe('ExportTaskCenter details', () => {
+60 -2
View File
@@ -3,9 +3,11 @@ import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
const requestImage = vi.fn()
const setCachedLoadedImage = vi.fn()
vi.mock('../../src/renderer/src/components/image-loader', () => ({
getCachedLoadedImage: vi.fn(() => undefined),
requestImage: (...args: unknown[]) => requestImage(...args)
requestImage: (...args: unknown[]) => requestImage(...args),
setCachedLoadedImage: (...args: unknown[]) => setCachedLoadedImage(...args)
}))
import { ImageBubble } from '../../src/renderer/src/components/ImageBubble'
@@ -18,6 +20,7 @@ const original = `${thumbnail}original`
describe('ImageBubble', () => {
beforeEach(() => {
requestImage.mockReset()
setCachedLoadedImage.mockReset()
window.api = { copyImage: vi.fn().mockResolvedValue({ success: true }) } as typeof window.api
})
@@ -59,7 +62,7 @@ describe('ImageBubble', () => {
expect(await screen.findByAltText('图片')).toBeVisible()
})
it('copies the raw message xml when right clicked', async () => {
it('opens a context menu on right click and copies the raw message xml when selected', async () => {
const writeText = vi.fn().mockResolvedValue(undefined)
Object.defineProperty(navigator, 'clipboard', {
value: { writeText },
@@ -87,6 +90,11 @@ describe('ImageBubble', () => {
const image = await screen.findByAltText('图片')
fireEvent.contextMenu(image)
expect(screen.getByRole('menuitem', { name: '下载原图' })).toBeVisible()
const copyXmlButton = screen.getByRole('menuitem', { name: '复制 XML' })
expect(copyXmlButton).toBeVisible()
await userEvent.click(copyXmlButton)
await waitFor(() =>
expect(writeText).toHaveBeenCalledWith('<msg><img aeskey="fixture" /></msg>')
)
@@ -100,6 +108,55 @@ describe('ImageBubble', () => {
alertSpy.mockRestore()
})
it('downloads the original image from the right-click context menu and updates the bubble', async () => {
const downloadOriginalImage = vi.fn().mockResolvedValue({
success: true,
data: original,
md5: 'fixture-image',
isOriginal: true
})
window.api = {
copyImage: vi.fn(),
downloadOriginalImage
} as unknown as typeof window.api
requestImage.mockResolvedValueOnce({ data: thumbnail, isThumbnail: true })
render(
<ImageBubble
imageMd5="fixture-image"
imageDatName="fixture.dat"
sessionId="fixture-session"
localId={99}
createTime={1700000100}
/>
)
const image = await screen.findByAltText('图片')
expect(image).toHaveAttribute('src', thumbnail)
fireEvent.contextMenu(image)
const downloadBtn = screen.getByRole('menuitem', { name: '下载原图' })
await userEvent.click(downloadBtn)
await waitFor(() => expect(downloadOriginalImage).toHaveBeenCalledTimes(1))
expect(downloadOriginalImage).toHaveBeenCalledWith({
sessionId: 'fixture-session',
localId: 99,
serverId: undefined,
createTime: 1700000100,
imageMd5: 'fixture-image',
imageDatName: 'fixture.dat',
fileId: undefined,
aesKey: undefined,
rawXml: undefined
})
await waitFor(() => expect(image).toHaveAttribute('src', original))
expect(setCachedLoadedImage).toHaveBeenCalledWith('fixture-image', 'fixture.dat', {
data: original,
isThumbnail: false
})
})
it('surfaces a failure instead of copying anything when the xml is unavailable', async () => {
const writeText = vi.fn().mockResolvedValue(undefined)
Object.defineProperty(navigator, 'clipboard', {
@@ -116,6 +173,7 @@ describe('ImageBubble', () => {
render(<ImageBubble imageMd5="fixture-image" sessionId="fixture-session" localId={7} />)
fireEvent.contextMenu(await screen.findByAltText('图片'))
await userEvent.click(screen.getByRole('menuitem', { name: '复制 XML' }))
await waitFor(() => expect(alertSpy).toHaveBeenCalledWith('XML 获取失败:数据库尚未连接'))
expect(writeText).not.toHaveBeenCalled()
+24
View File
@@ -180,4 +180,28 @@ describe('VideoAssetService local fallback', () => {
expect(result).toEqual({ success: false, error: '本地未找到该视频文件' })
})
it('registers a newly downloaded video and pairs it with an existing thumbnail poster', async () => {
const { accountRoot, service } = createService()
const month = join(accountRoot, 'msg', 'video', '2026-11')
mkdirSync(month, { recursive: true })
const stem = '7f3c9a2e5b1d804fc6a7e93b2d10f854'
const posterPath = join(month, `${stem}_thumb.jpg`)
writeFileSync(posterPath, jpegFixture(219, 360))
const beforeDownload = await service.resolve([stem])
expect(beforeDownload.success).toBe(false)
expect(service.pathForUrl(beforeDownload.poster!)).toBe(posterPath)
const downloadedRawPath = join(month, `${stem}_raw.mp4`)
writeFileSync(downloadedRawPath, mp4Fixture(6, 'downloaded-raw-video'))
const registered = service.registerDownloadedVideo([stem], downloadedRawPath, true)
expect(service.pathForUrl(registered.url)).toBe(downloadedRawPath)
expect(service.pathForUrl(registered.poster!)).toBe(posterPath)
const afterDownload = await service.resolve([stem])
expect(afterDownload.success).toBe(true)
expect(service.pathForUrl(afterDownload.url!)).toBe(downloadedRawPath)
expect(service.pathForUrl(afterDownload.poster!)).toBe(posterPath)
})
})