Files
superwork/vscode/webview-ui/src/codeReader/repoImage.test.ts
T

32 lines
1.4 KiB
TypeScript

import type { WebviewToExtension } from './types'
import { describe, expect, it } from 'vitest'
import { repoImageInner, RepoImages } from './repoImage'
describe('repoImages', () => {
function setup(): { images: RepoImages, sent: WebviewToExtension[] } {
const sent: WebviewToExtension[] = []
return { images: new RepoImages(msg => sent.push(msg)), sent }
}
it('路径变了才问哪些在,还没回是路径,不在是找不到图片,迟到的回答丢掉', () => {
const { images, sent } = setup()
const path = 'frontend/src/components/overview/screenshots/OverviewSection.png'
images.scan([path])
images.scan([path])
expect(sent).toEqual([{ type: 'checkRepoImages', id: 1, paths: [path] }])
expect(images.state(path)).toBe('pending')
expect(repoImageInner(path, '概览卡片', images.state(path))).toBe(path)
expect(images.checked(0, [{ path }])).toBe(false)
expect(images.state(path)).toBe('pending')
expect(images.checked(1, [{ path }])).toBe(true)
expect(images.state(path)).toBe('missing')
expect(repoImageInner(path, '概览卡片', 'missing')).toBe(`找不到图片 ${path}`)
expect(repoImageInner(path, '概览卡片', 'missing')).not.toContain('<img')
const src = 'https://file+.vscode-resource.vscode-cdn.net/OverviewSection.png'
expect(images.checked(1, [{ path, src }])).toBe(true)
expect(repoImageInner(path, '概览卡片', images.state(path))).toContain('<img')
})
})