88 lines
4.0 KiB
TypeScript
88 lines
4.0 KiB
TypeScript
import { flushPromises, mount } from '@vue/test-utils'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import KeyframeInputDetails from '@/features/production/components/KeyframeInputDetails.vue'
|
|
import { historicalReferenceUrl, type HistoricalKeyframeReference } from '@/features/production/keyframe-input'
|
|
|
|
/** 两种职责对应同一张实际参考图。 */
|
|
const reference: HistoricalKeyframeReference = {
|
|
imageNumber: 1,
|
|
sha256: 'a'.repeat(64),
|
|
pixelFingerprint: 'b'.repeat(64),
|
|
mimeType: 'image/png',
|
|
width: 512,
|
|
height: 512,
|
|
byteLength: 100,
|
|
bindings: [
|
|
{ role: 'identity-anchor', subjectRef: '@CH01' },
|
|
{ role: 'form-primary', subjectRef: '@CH02' }
|
|
],
|
|
availability: 'available',
|
|
imageUrl: '/api/storyboard-shots/shot/keyframes/one/generation-input/references/1?projectId=project'
|
|
}
|
|
|
|
describe('历史首帧输入', () => {
|
|
it('只解析归属当前候选的正式原件地址', () => {
|
|
expect(historicalReferenceUrl(reference, 'project', 'shot', 'one')).toContain('?projectId=project')
|
|
expect(historicalReferenceUrl(reference, 'project', 'shot', 'two')).toBeNull()
|
|
expect(historicalReferenceUrl(reference, 'wrong', 'shot', 'one')).toBeNull()
|
|
expect(historicalReferenceUrl({ ...reference, availability: 'changed' }, 'project', 'shot', 'one')).toBeNull()
|
|
})
|
|
|
|
it('展开才读取历史,切换候选不混用输入和参考', async () => {
|
|
const fetcher = vi.fn<typeof fetch>().mockImplementation(async path => {
|
|
const keyframeId = String(path).includes('/one/') ? 'one' : 'two'
|
|
return new Response(
|
|
JSON.stringify({
|
|
data: {
|
|
shotId: 'shot',
|
|
keyframeId,
|
|
inputSnapshotStatus: 'recorded',
|
|
providerInputFingerprint: 'fingerprint',
|
|
providerInputSnapshot: {
|
|
provider: 'seedream',
|
|
model: 'test',
|
|
providerPrompt: '当次描述 ' + keyframeId,
|
|
fingerprint: 'fingerprint',
|
|
sourceFingerprint: 'source',
|
|
generationOptions: { size: '2048x2048' },
|
|
version: 1,
|
|
references: [
|
|
{
|
|
...reference,
|
|
imageUrl: null,
|
|
availability: keyframeId === 'one' ? 'changed' : 'unavailable'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
})
|
|
)
|
|
})
|
|
vi.stubGlobal('fetch', fetcher)
|
|
const wrapper = mount(KeyframeInputDetails, {
|
|
props: { projectId: 'project', shotId: 'shot', keyframeId: 'one' }
|
|
})
|
|
try {
|
|
expect(fetcher).not.toHaveBeenCalled()
|
|
await wrapper.get('.n-collapse-item__header-main').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain('当次描述 one')
|
|
expect(wrapper.text()).toContain('原图已变化')
|
|
expect(wrapper.text()).toContain('@CH01')
|
|
expect(wrapper.text()).toContain('@CH02')
|
|
expect(wrapper.find('img').exists()).toBe(false)
|
|
await wrapper.setProps({ keyframeId: 'two' })
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain('当次描述 two')
|
|
expect(wrapper.text()).not.toContain('当次描述 one')
|
|
expect(wrapper.text()).toContain('原图不可用')
|
|
expect(fetcher.mock.calls.map(([url]) => url)).toEqual([
|
|
'/api/storyboard-shots/shot/keyframes/one/generation-input?projectId=project',
|
|
'/api/storyboard-shots/shot/keyframes/two/generation-input?projectId=project'
|
|
])
|
|
} finally {
|
|
wrapper.unmount()
|
|
}
|
|
})
|
|
})
|