Files
short-drama-agent-front/tests/features/breakdown/candidate-panel.test.ts
T

93 lines
3.8 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import BreakdownCandidatePanel from '@/features/breakdown/components/BreakdownCandidatePanel.vue'
import ConfirmAction from '@/features/workflows/ConfirmAction.vue'
import { projectsApi } from '@/features/projects/api'
import { breakdownApi } from '@/features/breakdown/api'
/** 候选完整性只使用最新原始状态。 */
const state = {
candidateOnly: true,
storyboardShotValidation: { valid: true, issues: [] },
expectedEpisodeFingerprints: { 1: 'fingerprint' },
runConfig: { groupSize: 3, modules: [] as [], episodeGroups: [], sourceEpisodes: [{ episodeNo: 1 }] },
subjectCandidates: [
{
profileId: 'p',
name: '人物',
ref: '@人物',
module: 'character' as const,
description: '',
appearance_prompt: ''
}
],
subjectForms: [],
storyboardEpisodeShots: [
{
episodeNo: 1,
episodePlan: { episodeNo: 1 } as never,
beatShots: [
{
beatNo: 1,
shots: [
{ shotNo: 1, title: '', description: '', visualFocus: '', subjectRefs: [], durationSeconds: 2 }
]
}
]
}
]
}
let wrapper: VueWrapper | undefined
afterEach(() => {
wrapper?.unmount()
vi.restoreAllMocks()
document.body.innerHTML = ''
})
describe('候选版本与提交保护', () => {
it('当前版本仍有效时仅提交一次并刷新正式结果', async () => {
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([
{ checkpointId: 'ready', createdAt: '', workflowName: 'breakdown', state }
])
const commit = vi.spyOn(breakdownApi, 'commitCandidate').mockResolvedValue({
projectId: 'candidate-ready-test',
subjectCount: 1,
subjectFormCount: 0,
episodeCount: 1,
beatCount: 1,
shotCount: 1,
shotSubjectCount: 0
})
wrapper = mount(BreakdownCandidatePanel, {
props: { projectId: 'candidate-ready-test', checkpointId: 'ready', state, disabled: false }
})
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
await flushPromises()
expect(commit).toHaveBeenCalledExactlyOnceWith('candidate-ready-test')
expect(wrapper.emitted('refresh')).toHaveLength(1)
})
it('确认之后发现服务端版本已变化时禁止提交正式替换', async () => {
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([
{ checkpointId: 'new', createdAt: '', workflowName: 'breakdown', state }
])
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
wrapper = mount(BreakdownCandidatePanel, {
props: { projectId: 'candidate-version-test', checkpointId: 'old', state, disabled: false }
})
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
await flushPromises()
expect(commit).not.toHaveBeenCalled()
expect(wrapper.text()).toContain('候选版本已变化')
expect(wrapper.emitted('refresh')).toHaveLength(1)
})
it('新快照无明确候选标记时不恢复旧候选提交入口', async () => {
wrapper = mount(BreakdownCandidatePanel, {
props: { projectId: 'candidate-marker-test', checkpointId: 'old', state, disabled: false }
})
expect(wrapper.text()).toContain('提交候选为正式结果')
await wrapper.setProps({ checkpointId: 'new', state: {} })
expect(wrapper.findComponent(ConfirmAction).exists()).toBe(false)
})
})