feat: 支持按导出媒体文件名精确搜索

离线 HTML 搜索支持使用不含扩展名的完整图片或视频哈希文件名进行精确匹配,并保持其他消息字段的模糊搜索行为。\n\n补充图片和视频命中、大小写兼容、哈希片段及带扩展名不命中的 DOM 回归测试。
This commit is contained in:
Nanin
2026-08-12 22:02:43 +08:00
parent 34b86af0be
commit 8fac752e2b
2 changed files with 73 additions and 3 deletions
+56 -1
View File
@@ -33,7 +33,7 @@ describe('export media', () => {
expect(html).toContain('aria-expanded="')
expect(html).toContain('setExpandedTimelineYear')
expect(html).toContain('data-kind="media"')
expect(html).toContain('placeholder="搜索发送者消息内容…"')
expect(html).toContain('placeholder="搜索发送者消息内容或媒体文件名(不含后缀)…"')
expect(html).toContain('font-size: 16px;')
expect(html).toContain('filtered.slice(windowStart, windowEnd)')
expect(html).toContain('windowStart = Math.max(0, windowEnd - PAGE_SIZE)')
@@ -156,6 +156,61 @@ describe('export media', () => {
dom.window.close()
})
it('matches exported image and video filenames exactly without their extension', () => {
const html = renderExportPage('媒体文件名搜索')
const dom = new JSDOM(html, { runScripts: 'outside-only' })
const imageFileName = 'image_0123456789abcdef.jpg'
const videoFileName = 'video_fedcba9876543210.mp4'
const messages: Message[] = [
{
...messageForArchive('image-name', 'fixture', '媒体文件名搜索', '', 1),
type: '图片',
exportMediaType: 'image',
exportMediaUrl: `media/${imageFileName}`,
contentData: { type: 'image' }
},
{
...messageForArchive('video-name', 'fixture', '媒体文件名搜索', '', 2),
type: '视频',
exportMediaType: 'video',
exportMediaUrl: `media/${videoFileName}`,
contentData: { type: 'video' }
}
]
Object.assign(dom.window, {
__WECHAT_EXPORT__: {
version: 1,
sourceId: 'fixture',
name: '媒体文件名搜索',
messages
}
})
dom.window.eval(inlineScriptOf(html))
const search = dom.window.document.querySelector('#query') as HTMLInputElement
search.value = 'IMAGE_0123456789ABCDEF'
search.dispatchEvent(new dom.window.Event('input'))
expect(dom.window.document.querySelectorAll('.message')).toHaveLength(1)
expect(dom.window.document.querySelectorAll('img.media-image')).toHaveLength(1)
expect(dom.window.document.querySelectorAll('video.media-image')).toHaveLength(0)
search.value = '0123456789abcdef'
search.dispatchEvent(new dom.window.Event('input'))
expect(dom.window.document.querySelectorAll('.message')).toHaveLength(0)
search.value = 'video_fedcba9876543210'
search.dispatchEvent(new dom.window.Event('input'))
expect(dom.window.document.querySelectorAll('.message')).toHaveLength(1)
expect(dom.window.document.querySelectorAll('img.media-image')).toHaveLength(0)
expect(dom.window.document.querySelectorAll('video.media-image')).toHaveLength(1)
search.value = videoFileName
search.dispatchEvent(new dom.window.Event('input'))
expect(dom.window.document.querySelectorAll('.message')).toHaveLength(0)
dom.window.close()
})
it('filters a v2 merged archive by conversation before search and month counts', () => {
const html = renderExportPage('合并档案')
const dom = new JSDOM(html, { runScripts: 'outside-only' })