feat(short-drama-agent-front): 接入联合修订与图片费用审计
This commit is contained in:
1 parent
87427d9d43
commit
f6edc4eb70
52 files changed
+5060
-516
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { defineComponent, h } from 'vue'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { expect, it, vi } from 'vitest'
|
||||
import BeatShotDirectory from '@/features/storyboard/components/BeatShotDirectory.vue'
|
||||
import { designedShot } from '@/features/storyboard/testing/fixtures'
|
||||
|
||||
it('定位嵌套镜头时避让所属段落标题,首行镜号不被吸顶标题遮挡', async () => {
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
props: { activeId: { type: String, required: true } },
|
||||
setup: props => () =>
|
||||
h('div', { class: 'n-scrollbar-container' }, [
|
||||
h(BeatShotDirectory, {
|
||||
shots: [designedShot('first'), { ...designedShot('next'), beatNo: 2 }],
|
||||
activeId: props.activeId,
|
||||
itemClass: 'shot-link'
|
||||
})
|
||||
])
|
||||
}),
|
||||
{ props: { activeId: 'first' } }
|
||||
)
|
||||
try {
|
||||
await flushPromises()
|
||||
const viewport = wrapper.get<HTMLElement>('.n-scrollbar-container').element
|
||||
const selected = wrapper.findAll<HTMLElement>('.directory-item')[1]!.element
|
||||
const heading = selected.closest('[role="group"]')!.querySelector('h4')!
|
||||
Object.defineProperty(heading, 'offsetHeight', { configurable: true, value: 38 })
|
||||
vi.spyOn(viewport, 'getBoundingClientRect').mockReturnValue(new DOMRect(0, 100, 240, 400))
|
||||
vi.spyOn(selected, 'getBoundingClientRect').mockReturnValue(new DOMRect(0, 180, 240, 88))
|
||||
viewport.scrollTop = 80
|
||||
/** 记录目录自身滚动目标,断言标题避让距离。 */
|
||||
const scrollTo = vi.fn<(options: ScrollToOptions) => void>()
|
||||
Object.defineProperty(viewport, 'scrollTo', { configurable: true, value: scrollTo })
|
||||
await wrapper.setProps({ activeId: 'next' })
|
||||
await flushPromises()
|
||||
expect(scrollTo).toHaveBeenLastCalledWith({ top: 122, behavior: 'smooth' })
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,381 @@
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { NCheckbox, NInput } from 'naive-ui'
|
||||
import JointDraftReviewPanel from '@/features/storyboard/components/JointDraftReviewPanel.vue'
|
||||
import { jointDraftDifferences } from '@/features/storyboard/joint-review'
|
||||
import { visualStateTimeSections, visualStateTimeIssueLabel } from '@/features/storyboard/visual-state-time'
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { jointReviewFixture } from '../../fixtures/joint-review'
|
||||
|
||||
/** 每个镜头用例隔离项目锁。 */
|
||||
let serial = 0
|
||||
/** 释放查询和免费请求。 */
|
||||
const wrappers: VueWrapper[] = []
|
||||
afterEach(() => wrappers.splice(0).forEach(wrapper => wrapper.unmount()))
|
||||
/**
|
||||
* 正式包装的独立Mock响应。
|
||||
* @param data 原契约数据
|
||||
* @returns 独立响应
|
||||
*/
|
||||
function response(data: unknown) {
|
||||
return new Response(JSON.stringify({ data }))
|
||||
}
|
||||
|
||||
describe('联合采用完整差异与时间展示', () => {
|
||||
it('完整列出摄影、主体及四项环境差异,身份与主体集合仍禁止修改', () => {
|
||||
const fixture = jointReviewFixture(),
|
||||
draft = structuredClone(fixture.saved.draft)
|
||||
let differences = jointDraftDifferences(fixture.formal, draft)
|
||||
expect(differences).toHaveLength(4)
|
||||
expect(differences.every(item => item.allowed)).toBe(true)
|
||||
expect(differences.map(item => item.change?.target)).toEqual([
|
||||
'direction',
|
||||
'direction',
|
||||
'visualState',
|
||||
'subject'
|
||||
])
|
||||
draft.visualState.environment.weather = ''
|
||||
draft.visualState.subjects[0]!.formId = '不能偷偷换形态'
|
||||
differences = jointDraftDifferences(fixture.formal, draft)
|
||||
expect(differences.find(item => item.label === '环境 · 天气')).toMatchObject({
|
||||
allowed: true,
|
||||
change: { target: 'environment', field: 'weather', before: '小雨', after: '' }
|
||||
})
|
||||
expect(differences.filter(item => !item.allowed).map(item => item.label)).toContain('@CH0001 · 形态身份')
|
||||
draft.visualState.subjects.push({ ...draft.visualState.subjects[0]!, subjectRef: '@CH9999' })
|
||||
expect(
|
||||
jointDraftDifferences(fixture.formal, draft).some(item => !item.allowed && item.label.includes('主体集合'))
|
||||
).toBe(true)
|
||||
})
|
||||
it('只按正式四个时间标记排版,旧文字和原问题不被重写或判通过', () => {
|
||||
const note = jointReviewFixture().saved.draft.visualState.continuityNote
|
||||
expect(visualStateTimeSections(note).map(section => section.kind)).toEqual([
|
||||
'input',
|
||||
'planned',
|
||||
'continuity',
|
||||
'video'
|
||||
])
|
||||
expect(visualStateTimeSections('角色已经持物,后续动作尚待拍摄。')).toEqual([
|
||||
{ kind: 'legacy', title: '原衔接说明(未分段)', text: '角色已经持物,后续动作尚待拍摄。' }
|
||||
])
|
||||
expect(visualStateTimeIssueLabel({ code: 'VISUAL_STATE_START_CONFLICT', severity: 'error' })).toBe(
|
||||
'开拍状态冲突'
|
||||
)
|
||||
expect(visualStateTimeIssueLabel({ code: 'VISUAL_STATE_TIME_NEEDS_REVIEW', severity: 'needs_review' })).toBe(
|
||||
'时间语义待人工核对'
|
||||
)
|
||||
expect(
|
||||
visualStateTimeIssueLabel({ code: 'VISUAL_STATE_VIDEO_END_UNSUPPORTED', severity: 'needs_review' })
|
||||
).toBe('真实视频末态缺少证据')
|
||||
expect(visualStateTimeIssueLabel({ code: 'other', severity: 'needs_review' })).toBe('需要人工核对')
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* 点击真实组件当前显示的指定操作。
|
||||
* @param wrapper 实际表单
|
||||
* @param label 可见按钮名称
|
||||
*/
|
||||
async function click(wrapper: VueWrapper, label: string) {
|
||||
const button = wrapper.findAll('button').find(item => item.text() === label)!
|
||||
expect(button.attributes('disabled')).toBeUndefined()
|
||||
await button.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
/**
|
||||
* 明确填写实际审核人及剪辑依据。
|
||||
* @param wrapper 实际表单
|
||||
*/
|
||||
async function author(wrapper: VueWrapper) {
|
||||
wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '联合修订依据')!
|
||||
.vm.$emit('update:value', '本次仅调整当前开拍状态,保留原动作和相邻观察轴。')
|
||||
wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '联合审核人')!
|
||||
.vm.$emit('update:value', '测试联合审核人')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
describe('原摄影抽屉内的联合流程', () => {
|
||||
/**
|
||||
* 挂载真实联合模式,成功/冲突均只写隔离投影。
|
||||
* @param conflict 是否模拟相邻版本冲突
|
||||
* @param reused 是否模拟幂等采用
|
||||
* @param environment 是否包含有据环境修订
|
||||
* @returns 组件、模拟请求及正式来源
|
||||
*/
|
||||
async function editor(conflict = false, reused = false, environment = false) {
|
||||
const projectId = `joint-flow-${++serial}`,
|
||||
fixture = jointReviewFixture(projectId)
|
||||
/** 正式项目详情中的本集身份与原始正文,摘要不能代替正文哈希。 */
|
||||
const episode = {
|
||||
id: 'source-episode',
|
||||
projectId,
|
||||
episode: 1,
|
||||
title: '当前源集',
|
||||
content: '第一行\r\n午后,维修间透入日光。\n天气未指定。'
|
||||
}
|
||||
if (environment) {
|
||||
fixture.saved.draft.visualState.environment.timeOfDay = '午后'
|
||||
fixture.saved.draft.visualState.environment.weather = ''
|
||||
fixture.saved.draft.visualState.environment.atmosphere = '自然日光'
|
||||
fixture.saved.draft.visualState.environment.transientState = ''
|
||||
}
|
||||
const fetcher = vi.fn<typeof fetch>(async (url, init) => {
|
||||
const path = String(url)
|
||||
if (path === `/api/projects/${projectId}`) return response({ id: projectId, episodes: [episode] })
|
||||
if (path.includes('/keyframe-review-draft')) {
|
||||
if (init?.method === 'PUT') {
|
||||
const body = JSON.parse(String(init.body))
|
||||
fixture.saved.draft = body.draft
|
||||
fixture.saved.revision++
|
||||
fixture.saved.providerInput = body.providerInput
|
||||
fixture.saved.expectedCurrentFormalSourceFingerprint = body.expectedCurrentFormalSourceFingerprint
|
||||
}
|
||||
return response(fixture.saved)
|
||||
}
|
||||
if (path.endsWith('/storyboard-quality-confirmation'))
|
||||
return response({ ...fixture.approval.approval, valid: true, confirmation: fixture.approval.record })
|
||||
if (path.includes('/storyboard-directions?')) return response(fixture.directions)
|
||||
if (path.includes('/storyboard-visual-states?')) return response(fixture.visuals)
|
||||
if (path.includes('/keyframe-spec')) return response(fixture.keyframe)
|
||||
if (path.includes('/keyframe/preview')) {
|
||||
const body = JSON.parse(String(init?.body))
|
||||
if (!body.draft) return response({ ...imagePreviewFixture(), shotId: fixture.shot.shotId })
|
||||
return response({
|
||||
...imagePreviewFixture(),
|
||||
shotId: fixture.shot.shotId,
|
||||
draftFingerprint: 'a'.repeat(64),
|
||||
currentDerivedFingerprint: 'c'.repeat(64),
|
||||
adjacentDerivedVersions: [{ shotId: 'shot-db-1-2', derivedFingerprint: 'd'.repeat(64) }],
|
||||
productionReady: false,
|
||||
productionGate: { ready: false, reason: '项目未完成' },
|
||||
sceneSources: []
|
||||
})
|
||||
}
|
||||
if (path.endsWith('/storyboard-derived-reviews/confirm')) {
|
||||
const body = JSON.parse(String(init?.body))
|
||||
if (conflict) {
|
||||
if (environment) episode.content += '\n源正文已被其他人修改。'
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: environment
|
||||
? 'JOINT_REVISION_ENVIRONMENT_SOURCE_STALE: 本集原文已变化。'
|
||||
: 'JOINT_REVISION_NEIGHBOR_STALE: 紧邻镜头已更新,请重读。'
|
||||
}),
|
||||
{ status: 409 }
|
||||
)
|
||||
}
|
||||
if (!body.preview) fixture.saved.status = 'stale'
|
||||
return response({
|
||||
projectId,
|
||||
preview: body.preview,
|
||||
changed: !body.preview && !reused,
|
||||
reused: !body.preview && reused,
|
||||
requestFingerprint: 'f'.repeat(64),
|
||||
shots: [
|
||||
{ shotId: fixture.shot.shotId, directionId: 'direction-formal', visualStateId: 'visual-formal' }
|
||||
]
|
||||
})
|
||||
}
|
||||
throw new Error(`未模拟 ${init?.method ?? 'GET'} ${path}`)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const wrapper = mount(JointDraftReviewPanel, {
|
||||
props: { projectId, episodeNo: 1, shot: fixture.shot, shots: fixture.shots, disabled: false }
|
||||
})
|
||||
wrappers.push(wrapper)
|
||||
await flushPromises()
|
||||
return { wrapper, fixture, fetcher, episode }
|
||||
}
|
||||
it.each([false, true])('保存、画面预览、联合免费预检和采用分开,幂等回执=%s', async reused => {
|
||||
const { wrapper, fetcher, fixture } = await editor(false, reused)
|
||||
expect(wrapper.text()).toContain('完整字段差异(4 项)')
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '联合摄影意图')!
|
||||
.vm.$emit('update:value', '明确修改后保存的摄影意图')
|
||||
await flushPromises()
|
||||
await wrapper.vm.save()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('changed')).toBeUndefined()
|
||||
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'PUT')).toHaveLength(1)
|
||||
await click(wrapper, '免费核对草案画面输入')
|
||||
expect(wrapper.text()).toContain('相邻镜头依据')
|
||||
await author(wrapper)
|
||||
await click(wrapper, '免费预检联合采用')
|
||||
expect(wrapper.vm.canAdopt).toBe(false)
|
||||
wrapper.getComponent(NCheckbox).vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
expect(wrapper.vm.canAdopt).toBe(true)
|
||||
await wrapper.vm.adopt()
|
||||
await flushPromises()
|
||||
const confirms = fetcher.mock.calls.filter(([url]) =>
|
||||
String(url).endsWith('/storyboard-derived-reviews/confirm')
|
||||
)
|
||||
expect(confirms).toHaveLength(2)
|
||||
const first = JSON.parse(String(confirms[0]![1]?.body)),
|
||||
second = JSON.parse(String(confirms[1]![1]?.body))
|
||||
expect(second).toEqual({ ...first, preview: false })
|
||||
expect(first.shots[0].jointRevision).toMatchObject({
|
||||
expectedDraftRevision: 8,
|
||||
expectedDerivedFingerprint: 'c'.repeat(64),
|
||||
expectedNeighbors: [{ shotId: 'shot-db-1-2', derivedFingerprint: 'd'.repeat(64) }]
|
||||
})
|
||||
expect(first.shots[0].jointRevision.changes).toHaveLength(4)
|
||||
expect(first.shots[0].jointRevision).not.toHaveProperty('environmentSource')
|
||||
expect(first.shots[0].expectedCurrentFormalSourceFingerprint).toBe(fixture.keyframe.formalSourceFingerprint)
|
||||
expect(first.shots[0].draft).not.toHaveProperty('subjectStateRevision')
|
||||
expect(wrapper.emitted('changed')).toHaveLength(1)
|
||||
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'PUT')).toHaveLength(1)
|
||||
expect(fetcher.mock.calls.some(([url]) => /\/keyframe$|\/generate|\/vision|\/primary/.test(String(url)))).toBe(
|
||||
false
|
||||
)
|
||||
expect(wrapper.text()).toContain('原草案和历史保留')
|
||||
})
|
||||
it('邻镜变化409保留原稿并重读,不自动采用或改为当前新版本', async () => {
|
||||
const { wrapper, fetcher } = await editor(true)
|
||||
await click(wrapper, '免费核对草案画面输入')
|
||||
await author(wrapper)
|
||||
await click(wrapper, '免费预检联合采用')
|
||||
expect(wrapper.vm.canAdopt).toBe(false)
|
||||
expect(wrapper.text()).toContain('当前输入已保留')
|
||||
expect(
|
||||
wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '联合摄影意图')!
|
||||
.props('value')
|
||||
).toBe('保留正式动作的开拍意图')
|
||||
const confirms = fetcher.mock.calls.filter(([url]) =>
|
||||
String(url).endsWith('/storyboard-derived-reviews/confirm')
|
||||
)
|
||||
expect(confirms).toHaveLength(1)
|
||||
expect(JSON.parse(String(confirms[0]![1]?.body)).preview).toBe(true)
|
||||
expect(wrapper.emitted('changed')).toBeUndefined()
|
||||
})
|
||||
it('内容改变撤销原预检,不自动套用重新读取的草案', async () => {
|
||||
const { wrapper, fetcher, fixture } = await editor()
|
||||
await click(wrapper, '免费核对草案画面输入')
|
||||
await author(wrapper)
|
||||
await click(wrapper, '免费预检联合采用')
|
||||
wrapper.getComponent(NCheckbox).vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '摄影构图')!
|
||||
.vm.$emit('update:value', '重新编辑,旧确认失效')
|
||||
await flushPromises()
|
||||
expect(wrapper.vm.canAdopt).toBe(false)
|
||||
fixture.saved.draft.visualState.environment.weather = '不能暗改天气'
|
||||
await click(wrapper, '重新读取正式来源与草案')
|
||||
expect(
|
||||
fetcher.mock.calls.filter(([url]) => String(url).endsWith('/storyboard-derived-reviews/confirm'))
|
||||
).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('环境差异须逐字本集证据,冻结原字节全文SHA;保存和预检不自动采用', async () => {
|
||||
const { wrapper, fetcher, episode } = await editor(false, false, true)
|
||||
expect(wrapper.text()).toContain('本集原文依据')
|
||||
await wrapper.vm.save()
|
||||
await flushPromises()
|
||||
await click(wrapper, '免费核对草案画面输入')
|
||||
await author(wrapper)
|
||||
const preflight = () => wrapper.findAll('button').find(item => item.text() === '免费预检联合采用')!
|
||||
expect(preflight().attributes('disabled')).toBeDefined()
|
||||
const quote = wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '环境原文片段')!
|
||||
quote.vm.$emit('update:value', '另一集才有的晴天')
|
||||
await flushPromises()
|
||||
expect(preflight().attributes('disabled')).toBeDefined()
|
||||
quote.vm.$emit('update:value', '午后,维修间透入日光。')
|
||||
await flushPromises()
|
||||
await click(wrapper, '免费预检联合采用')
|
||||
const confirms = () =>
|
||||
fetcher.mock.calls.filter(([url]) => String(url).endsWith('/storyboard-derived-reviews/confirm'))
|
||||
expect(confirms()).toHaveLength(1)
|
||||
const previewBody = JSON.parse(String(confirms()[0]![1]?.body))
|
||||
expect(previewBody.shots[0].jointRevision.environmentSource).toEqual({
|
||||
episodeId: 'source-episode',
|
||||
expectedContentFingerprint: createHash('sha256').update(episode.content).digest('hex'),
|
||||
quote: '午后,维修间透入日光。'
|
||||
})
|
||||
expect(
|
||||
previewBody.shots[0].jointRevision.changes.filter((row: { target: string }) => row.target === 'environment')
|
||||
).toHaveLength(4)
|
||||
expect(wrapper.vm.canAdopt).toBe(false)
|
||||
wrapper.getComponent(NCheckbox).vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
quote.vm.$emit('update:value', '午后,维修间透入日光。\n天气未指定。')
|
||||
await flushPromises()
|
||||
expect(wrapper.vm.canAdopt).toBe(false)
|
||||
await click(wrapper, '免费预检联合采用')
|
||||
wrapper.getComponent(NCheckbox).vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
await Promise.all([wrapper.vm.adopt(), wrapper.vm.adopt()])
|
||||
expect(confirms()).toHaveLength(3)
|
||||
const second = JSON.parse(String(confirms()[1]![1]?.body)),
|
||||
adopted = JSON.parse(String(confirms()[2]![1]?.body))
|
||||
expect(adopted).toEqual({ ...second, preview: false })
|
||||
expect(fetcher.mock.calls.some(([url]) => /\/keyframe$|\/generate|\/vision|\/primary/.test(String(url)))).toBe(
|
||||
false
|
||||
)
|
||||
})
|
||||
it('环境来源409重读本集全文并保留片段和草案,不自动重试', async () => {
|
||||
const { wrapper, fetcher, episode } = await editor(true, false, true)
|
||||
await click(wrapper, '免费核对草案画面输入')
|
||||
await author(wrapper)
|
||||
const quote = wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '环境原文片段')!
|
||||
quote.vm.$emit('update:value', '午后,维修间透入日光。')
|
||||
await flushPromises()
|
||||
await click(wrapper, '免费预检联合采用')
|
||||
expect(quote.props('value')).toBe('午后,维修间透入日光。')
|
||||
expect(wrapper.vm.canAdopt).toBe(false)
|
||||
expect(
|
||||
fetcher.mock.calls.filter(([url]) => String(url).endsWith('/storyboard-derived-reviews/confirm'))
|
||||
).toHaveLength(1)
|
||||
expect(
|
||||
fetcher.mock.calls.filter(([url]) => String(url) === `/api/projects/${episode.projectId}`).length
|
||||
).toBeGreaterThanOrEqual(2)
|
||||
await wrapper
|
||||
.findAll('.n-collapse-item__header-main')
|
||||
.find(item => item.text() === '环境修订(需本集原文)')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(
|
||||
wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '环境天气')!
|
||||
.props('value')
|
||||
).toBe('')
|
||||
})
|
||||
it('正式集身份或全文缺失时保留输入但不允许环境预检', async () => {
|
||||
const { wrapper, episode, fetcher } = await editor(false, false, true)
|
||||
await click(wrapper, '免费核对草案画面输入')
|
||||
await author(wrapper)
|
||||
const quote = wrapper
|
||||
.findAllComponents(NInput)
|
||||
.find(input => input.attributes('aria-label') === '环境原文片段')!
|
||||
quote.vm.$emit('update:value', '午后,维修间透入日光。')
|
||||
await flushPromises()
|
||||
Reflect.deleteProperty(episode, 'content')
|
||||
await click(wrapper, '刷新本集原文')
|
||||
expect(wrapper.text()).toContain('缺少本集正式身份或全文')
|
||||
expect(quote.props('value')).toBe('午后,维修间透入日光。')
|
||||
expect(
|
||||
wrapper
|
||||
.findAll('button')
|
||||
.find(item => item.text() === '免费预检联合采用')!
|
||||
.attributes('disabled')
|
||||
).toBeDefined()
|
||||
expect(
|
||||
fetcher.mock.calls.filter(([url]) => String(url).endsWith('/storyboard-derived-reviews/confirm'))
|
||||
).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,117 @@
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import StoryboardPage from '@/features/storyboard/StoryboardPage.vue'
|
||||
import { projectContextKey } from '@/features/projects/context'
|
||||
import { testProjectContext } from '@/testing/project-context'
|
||||
import { directionsResult, visualStatesResult, storyboardCheckpoint } from '@/features/storyboard/testing/fixtures'
|
||||
import { preparationFixture } from '../storyboard-preparation/fixtures'
|
||||
import type { WorkflowExecution } from '@/features/workflows/execution.types'
|
||||
|
||||
/** 释放真实页面及任务订阅,避免迟到响应跨用例。 */
|
||||
const wrappers: VueWrapper[] = []
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach(wrapper => wrapper.unmount())
|
||||
localStorage.clear()
|
||||
})
|
||||
/**
|
||||
* 还原进入页面后发现已结束历史任务的场景,不连接真实服务。
|
||||
* @param projectId 当前隔离项目
|
||||
* @returns 实际页面和请求记录
|
||||
*/
|
||||
async function page(projectId: string) {
|
||||
const context = testProjectContext(projectId)
|
||||
context.data.value!.checkpoints = [storyboardCheckpoint()]
|
||||
const fixture = preparationFixture(projectId)
|
||||
const history: WorkflowExecution = {
|
||||
id: 'restored-direction-history',
|
||||
projectId,
|
||||
workflowName: 'storyboard-direction',
|
||||
status: 'completed',
|
||||
stage: 'completed',
|
||||
current: 2,
|
||||
total: 2,
|
||||
currentResourceId: null,
|
||||
metadata: { episodeNo: 1 },
|
||||
error: null,
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
createdAt: '2026-11-16T00:00:00Z',
|
||||
updatedAt: '2026-11-16T00:00:00Z',
|
||||
result: {
|
||||
projectId,
|
||||
episodeCount: 1,
|
||||
completedEpisodes: 1,
|
||||
skippedEpisodes: 0,
|
||||
failedEpisodes: 0,
|
||||
episodes: [{ episodeNo: 1, status: 'completed', directionCount: 2, shotCount: 2 }]
|
||||
}
|
||||
}
|
||||
localStorage.setItem(`short-drama:workflow-execution:${projectId}:storyboard-direction`, history.id)
|
||||
const fetcher = vi.fn<typeof fetch>(async (url, init) => {
|
||||
const path = String(url)
|
||||
if (init?.method && init.method !== 'GET') throw new Error('浏览页面不应产生写入')
|
||||
let data: unknown
|
||||
if (path.includes('/storyboard-directions?')) data = directionsResult(projectId)
|
||||
else if (path.includes('/storyboard-visual-states?')) data = visualStatesResult(projectId, 1, true)
|
||||
else if (path.endsWith('/storyboard-quality-confirmation'))
|
||||
data = { ...fixture.approval, valid: true, confirmation: fixture.record }
|
||||
else if (path.endsWith('/storyboard-quality-confirmation/preflight'))
|
||||
data = {
|
||||
current: { ...fixture.approval, valid: true, confirmation: fixture.record },
|
||||
quality: fixture.quality
|
||||
}
|
||||
else if (path.endsWith('/production/entry-readiness')) data = fixture.entry
|
||||
else if (path.endsWith('/storyboard/duration-audit')) data = { projectId, issues: [] }
|
||||
else if (path.endsWith('/duration-budget')) data = { projectId, episodes: [] }
|
||||
else if (path.includes('/workflow-executions/latest'))
|
||||
data = path.includes('workflowName=storyboard-direction') ? history : null
|
||||
else if (path.includes('/workflow-executions/restored-direction-history')) data = history
|
||||
else throw new Error(`未模拟只读请求 ${path}`)
|
||||
return Response.json({ data })
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const wrapper = mount(StoryboardPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context } }
|
||||
})
|
||||
wrappers.push(wrapper)
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return { wrapper, fetcher }
|
||||
}
|
||||
|
||||
describe('分镜浏览与生成配置分离', () => {
|
||||
it('恢复历史回执只提示入口,不自动打开生成配置', async () => {
|
||||
const { wrapper, fetcher } = await page('browse-restored-history')
|
||||
expect(wrapper.find('[data-workspace-tools]').attributes('aria-expanded')).toBe('false')
|
||||
expect(wrapper.find('[data-workspace-tools]').text()).toContain('有回执')
|
||||
expect(document.body.querySelector('.n-drawer')).toBeNull()
|
||||
expect(fetcher.mock.calls.every(([, init]) => !init?.method || init.method === 'GET')).toBe(true)
|
||||
})
|
||||
it('普通目录只浏览,用户打开生成范围后才能按镜头勾选,历史回执仍可查看', async () => {
|
||||
const { wrapper, fetcher } = await page('browse-range-selection')
|
||||
const directory = wrapper.get('nav[aria-label="本集镜头"]')
|
||||
expect(directory.findAll('[role="checkbox"]')).toHaveLength(0)
|
||||
await directory.findAll('button')[1]!.trigger('click')
|
||||
expect(directory.findAll('.selected')).toHaveLength(1)
|
||||
await wrapper.get('[data-workspace-tools]').trigger('click')
|
||||
await flushPromises()
|
||||
const history = [...document.querySelectorAll<HTMLElement>('.n-collapse-item__header-main')].find(item =>
|
||||
item.textContent?.includes('历史任务与回执')
|
||||
)!
|
||||
history.click()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('摄影设计任务')
|
||||
const range = [...document.querySelectorAll<HTMLElement>('.n-collapse-item__header-main')].find(item =>
|
||||
item.textContent?.includes('选择镜头')
|
||||
)!
|
||||
range.click()
|
||||
await flushPromises()
|
||||
const checkbox = document.querySelector<HTMLElement>('.n-drawer [aria-label="选择镜头 1.1"]')!
|
||||
checkbox.click()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('第 1 集所选 1 镜')
|
||||
expect(directory.findAll('[role="checkbox"]')).toHaveLength(0)
|
||||
expect(fetcher.mock.calls.every(([, init]) => !init?.method || init.method === 'GET')).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user