172 lines
7.3 KiB
TypeScript
172 lines
7.3 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
|
import FormalRepairEditor from '@/features/storyboard-preparation/FormalRepairEditor.vue'
|
|
import { preparationApi } from '@/features/storyboard-preparation/api'
|
|
import type { FormalShotRepairPreview, BeatSubjectPreview } from '@/features/storyboard-preparation/types'
|
|
|
|
/** 当前正式镜头有明确可补齐的动作关联,全部旧证据必须保留。 */
|
|
const preview = (): FormalShotRepairPreview => ({
|
|
projectId: 'p',
|
|
shotId: 's',
|
|
expectedFingerprint: 'a'.repeat(64),
|
|
written: false,
|
|
willCallModel: false,
|
|
requiredActions: [{ id: 'a', kind: 'action', description: '左手持铃', mustPerformInShot: true }],
|
|
durationPlanning: {
|
|
complexity: 'low',
|
|
phases: [
|
|
{
|
|
action: '持铃',
|
|
actionIds: ['a'],
|
|
estimatedSeconds: 4,
|
|
resourceOccupancy: [
|
|
{
|
|
actionId: 'a',
|
|
ownerRef: '@CH1',
|
|
resource: 'left_hand',
|
|
usage: 'hold',
|
|
shareable: false,
|
|
continuityRef: '@PR1'
|
|
}
|
|
]
|
|
}
|
|
],
|
|
transitionSeconds: 0,
|
|
recommendedDurationSeconds: 4,
|
|
reason: '原动作时长'
|
|
},
|
|
classification: {
|
|
status: 'candidate',
|
|
beforeFingerprint: 'a'.repeat(64),
|
|
proposed: null,
|
|
semanticIssues: [],
|
|
originalIssues: []
|
|
}
|
|
})
|
|
let wrapper: VueWrapper | undefined
|
|
afterEach(() => {
|
|
wrapper?.unmount()
|
|
vi.restoreAllMocks()
|
|
})
|
|
describe('正式镜头版本化修订', () => {
|
|
it('读取当前正式数据,不调用模型;人工确认后保存真实指纹和完整占用证据', async () => {
|
|
vi.spyOn(preparationApi, 'repairPreview').mockResolvedValue(preview())
|
|
const model = vi.spyOn(preparationApi, 'repairCandidate')
|
|
const save = vi.spyOn(preparationApi, 'repair').mockResolvedValue({
|
|
projectId: 'p',
|
|
shotId: 's',
|
|
written: true,
|
|
beforeFingerprint: 'a'.repeat(64),
|
|
afterFingerprint: 'b'.repeat(64)
|
|
})
|
|
wrapper = mount(FormalRepairEditor, {
|
|
props: {
|
|
projectId: 'p',
|
|
issue: { episodeNo: 1, beatNo: 1, shotNo: 1, shotId: 's', message: '关联待修复' },
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
expect(model).not.toHaveBeenCalled()
|
|
expect(save).not.toHaveBeenCalled()
|
|
await wrapper.get('[aria-label="修订原因"] textarea').setValue('逐项核对并调整动作关联')
|
|
await wrapper.get('[role="checkbox"][aria-label="确认正式镜头修订"]').trigger('click')
|
|
await wrapper.getComponent(FormalRepairEditor).vm.save()
|
|
await flushPromises()
|
|
expect(save).toHaveBeenCalledWith(
|
|
'p',
|
|
expect.objectContaining({
|
|
shotId: 's',
|
|
expectedFingerprint: 'a'.repeat(64),
|
|
confirmed: true,
|
|
reason: '逐项核对并调整动作关联',
|
|
durationPlanning: expect.objectContaining({
|
|
phases: [
|
|
expect.objectContaining({
|
|
resourceOccupancy: [expect.objectContaining({ continuityRef: '@PR1' })]
|
|
})
|
|
]
|
|
})
|
|
})
|
|
)
|
|
expect(wrapper.emitted('saved')).toHaveLength(1)
|
|
})
|
|
it('打开时不校验,保存前版本变化不得覆盖新镜头', async () => {
|
|
const read = vi.spyOn(preparationApi, 'repairPreview').mockResolvedValue(preview())
|
|
const save = vi.spyOn(preparationApi, 'repair')
|
|
wrapper = mount(FormalRepairEditor, {
|
|
props: {
|
|
projectId: 'p',
|
|
issue: { episodeNo: 1, beatNo: 1, shotNo: 1, shotId: 's', message: '关联待修复' },
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.text()).not.toContain('请填写修订原因')
|
|
await wrapper.get('[aria-label="修订原因"] textarea').setValue('明确原因')
|
|
await wrapper.get('[role="checkbox"][aria-label="确认正式镜头修订"]').trigger('click')
|
|
read.mockResolvedValue({ ...preview(), expectedFingerprint: 'c'.repeat(64) })
|
|
await wrapper.getComponent(FormalRepairEditor).vm.save()
|
|
await flushPromises()
|
|
expect(save).not.toHaveBeenCalled()
|
|
expect(wrapper.text()).toContain('已变化')
|
|
})
|
|
it('主体遗漏先保存段落的真实版本,不把段落指纹当作镜头指纹或自动追加镜头', async () => {
|
|
vi.spyOn(preparationApi, 'repairPreview').mockResolvedValue(preview())
|
|
const upstream: BeatSubjectPreview = {
|
|
projectId: 'p',
|
|
shotId: 's',
|
|
beatId: 'beat',
|
|
checkpointId: 'cp',
|
|
subjectRef: '@PR1',
|
|
subjectName: '铜铃',
|
|
subjectDescription: '项目已有铜铃',
|
|
beat: { title: '取铃', description: '阿皮拿起铜铃', visualFocus: '铜铃', subjectRefs: ['@CH1'] },
|
|
shot: { title: '取铃', description: '阿皮拿起铜铃', visualFocus: '铜铃' },
|
|
status: 'upstream-missing',
|
|
written: false,
|
|
candidate: {
|
|
checkpointId: 'cp',
|
|
beatId: 'beat',
|
|
subjectRef: '@PR1',
|
|
expectedFingerprint: 'c'.repeat(64),
|
|
proposed: { upstreamRefs: ['@CH1', '@PR1'], persistedRefs: ['@CH1', '@PR1'] },
|
|
requiresHumanReview: true
|
|
}
|
|
}
|
|
vi.spyOn(preparationApi, 'beatSubjectPreview').mockResolvedValue(upstream)
|
|
const beatWrite = vi.spyOn(preparationApi, 'repairBeatSubject').mockResolvedValue({
|
|
projectId: 'p',
|
|
shotId: 's',
|
|
beatId: 'beat',
|
|
checkpointId: 'cp',
|
|
resultFingerprint: 'd'.repeat(64),
|
|
written: true
|
|
})
|
|
const shotWrite = vi.spyOn(preparationApi, 'repairSubject')
|
|
wrapper = mount(FormalRepairEditor, {
|
|
props: {
|
|
projectId: 'p',
|
|
issue: { episodeNo: 1, beatNo: 1, shotNo: 1, shotId: 's', subjectRef: '@PR1', message: '缺少铜铃' },
|
|
disabled: false
|
|
}
|
|
})
|
|
await flushPromises()
|
|
expect(beatWrite).not.toHaveBeenCalled()
|
|
expect(wrapper.text()).toContain('剧情段落')
|
|
await wrapper.get('[aria-label="修订原因"] textarea').setValue('正文明确出现铜铃,补齐段落来源')
|
|
await wrapper.get('[role="checkbox"][aria-label="确认正式镜头修订"]').trigger('click')
|
|
await wrapper.getComponent(FormalRepairEditor).vm.save()
|
|
await flushPromises()
|
|
expect(beatWrite).toHaveBeenCalledExactlyOnceWith('p', {
|
|
shotId: 's',
|
|
subjectRef: '@PR1',
|
|
expectedFingerprint: 'c'.repeat(64),
|
|
confirmed: true,
|
|
reason: '正文明确出现铜铃,补齐段落来源'
|
|
})
|
|
expect(shotWrite).not.toHaveBeenCalled()
|
|
expect(wrapper.emitted('saved')).toHaveLength(1)
|
|
})
|
|
})
|