Files

118 lines
5.8 KiB
TypeScript

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)
})
})