feat(short-drama-agent-front): 完善镜头定位与项目配置
This commit is contained in:
1 parent
470b52e26d
commit
5b134207b8
66 files changed
+2042
-984
No files matched your search
@@ -1,25 +1,41 @@
|
||||
import { h } from 'vue'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import App from '@/App.vue'
|
||||
import ProjectLayout from '@/features/projects/ProjectLayout.vue'
|
||||
import { isProjectComplete } from '@/features/projects/access'
|
||||
import { useProjectContext } from '@/features/projects/context'
|
||||
import { projectsApi } from '@/features/projects/api'
|
||||
import { getOperation } from '@/features/workflows/operations'
|
||||
import type { ProjectDetail, ProjectStatus } from '@/features/projects/types'
|
||||
import type { ProjectDetail, ProjectStageReadiness, ProjectStatus } from '@/features/projects/types'
|
||||
import { readAllStyles } from '@/testing/styles'
|
||||
|
||||
const downstream = [
|
||||
'breakdown',
|
||||
'visual-style',
|
||||
'subject-identity',
|
||||
'subject-images',
|
||||
'assets',
|
||||
'storyboard',
|
||||
'production'
|
||||
]
|
||||
const downstream = ['breakdown', 'visual-style', 'subject-identity', 'subject-images', 'storyboard', 'production']
|
||||
/**
|
||||
* 构造服务端完整阶段状态,允许测试单独模拟各步骤的就绪变化。
|
||||
* @param id 项目编号
|
||||
* @param ready 所有制作阶段是否就绪
|
||||
* @returns 项目阶段响应
|
||||
*/
|
||||
function readiness(id: string, ready = true): ProjectStageReadiness {
|
||||
/** 每个阶段独立创建,避免修改某一步时污染其它前置状态。 */
|
||||
const stage = () => ({ ready, reason: ready ? null : '请先完成剧本创作' })
|
||||
return {
|
||||
projectId: id,
|
||||
script: stage(),
|
||||
breakdown: stage(),
|
||||
visualStyle: stage(),
|
||||
identity: stage(),
|
||||
subjectAssets: stage(),
|
||||
storyboard: stage()
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(projectsApi, 'stageReadiness').mockImplementation(async id => readiness(id))
|
||||
})
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
@@ -30,7 +46,12 @@ afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
/** 用已有剧集模拟中途生成的项目,完成与否必须取 status 而非数组长度。 */
|
||||
/**
|
||||
* 用已有剧集模拟中途生成的项目,完成与否必须取 status 而非数组长度。
|
||||
* @param id 项目编号
|
||||
* @param status 项目状态
|
||||
* @returns 含部分剧集的项目详情
|
||||
*/
|
||||
function project(id: string, status: ProjectStatus): ProjectDetail {
|
||||
return {
|
||||
id,
|
||||
@@ -46,12 +67,17 @@ function project(id: string, status: ProjectStatus): ProjectDetail {
|
||||
}
|
||||
}
|
||||
|
||||
/** 真实项目布局与侧栏,子工作区以挂载探针代替,防止测试发起实际生成请求。 */
|
||||
/**
|
||||
* 真实项目布局与侧栏,子工作区以挂载探针代替,防止测试发起实际生成请求。
|
||||
* @param initialPath 首次访问的项目地址
|
||||
* @returns 真实路由与工作区挂载记录
|
||||
*/
|
||||
async function openProject(initialPath: string) {
|
||||
const mounted = vi.fn<(path: string) => void>()
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: '/assets', component: { render: () => h('div', '资产库') } },
|
||||
{ path: '/projects', component: { render: () => h('div', '项目列表') } },
|
||||
{
|
||||
path: '/projects/:projectId',
|
||||
@@ -61,7 +87,12 @@ async function openProject(initialPath: string) {
|
||||
component: {
|
||||
setup() {
|
||||
mounted(path)
|
||||
return () => h('div', { class: 'workspace-probe' }, path)
|
||||
/** 测试探针只执行手动项目读取,不发起制作任务。 */
|
||||
const context = useProjectContext()
|
||||
return () => [
|
||||
h('div', { class: 'workspace-probe' }, path),
|
||||
h('button', { class: 'probe-refresh', onClick: context.refresh }, '手动刷新')
|
||||
]
|
||||
}
|
||||
}
|
||||
}))
|
||||
@@ -75,7 +106,7 @@ async function openProject(initialPath: string) {
|
||||
}
|
||||
|
||||
describe('剧本完成前的下游访问限制', () => {
|
||||
it('进入图库暂停父级轮询,返回其他工作区恢复定时更新', async () => {
|
||||
it('切换图库与其他工作区不自动重复读取项目状态', async () => {
|
||||
vi.useFakeTimers()
|
||||
const detail = vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('manual-gallery', 'completed'))
|
||||
const checkpoints = vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
@@ -88,13 +119,15 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
await router.push('/projects/manual-gallery/production')
|
||||
await flushPromises()
|
||||
await vi.advanceTimersByTimeAsync(6000)
|
||||
expect(detail).toHaveBeenCalledTimes(2)
|
||||
expect(checkpoints).toHaveBeenCalledTimes(2)
|
||||
expect(detail).toHaveBeenCalledTimes(1)
|
||||
expect(checkpoints).toHaveBeenCalledTimes(1)
|
||||
expect(projectsApi.stageReadiness).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('图库直接链接只读取一次项目,未完成时可手动刷新解锁', async () => {
|
||||
vi.useFakeTimers()
|
||||
let status: ProjectStatus = 'generating'
|
||||
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, status === 'completed'))
|
||||
const detail = vi.spyOn(projectsApi, 'detail').mockImplementation(async id => project(id, status))
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
await openProject('/projects/manual-gate/subject-images')
|
||||
@@ -112,6 +145,7 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
it.each(['draft', 'generating', 'need_review', 'failed'] as const)(
|
||||
'%s 不解锁导航,也不挂载直接链接对应的工作区',
|
||||
async status => {
|
||||
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(readiness('unfinished', false))
|
||||
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('unfinished', status))
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
const { router, mounted } = await openProject('/projects/unfinished/production')
|
||||
@@ -126,31 +160,41 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
expect(wrapper!.findAll('.n-menu [aria-disabled="true"]')).toHaveLength(6)
|
||||
await wrapper!.get('.project-access-gate button').trigger('click')
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.path).toBe('/projects/unfinished/breakdown')
|
||||
expect(mounted).not.toHaveBeenCalled()
|
||||
await wrapper!.get('.project-access-gate button').trigger('click')
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.path).toBe('/projects/unfinished/create-drama')
|
||||
expect(wrapper!.get('.workspace-probe').text()).toBe('create-drama')
|
||||
expect(mounted).toHaveBeenCalledExactlyOnceWith('create-drama')
|
||||
}
|
||||
)
|
||||
|
||||
it('轮询完成状态自动解锁;重新变为待审核时撤下下游面板', async () => {
|
||||
it('手动刷新就绪状态解锁;服务端撤销就绪后撤下下游面板', async () => {
|
||||
vi.useFakeTimers()
|
||||
let status: ProjectStatus = 'generating'
|
||||
vi.spyOn(projectsApi, 'detail').mockImplementation(async id => project(id, status))
|
||||
let ready = false
|
||||
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('manual-refresh', 'completed'))
|
||||
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, ready))
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
const { mounted } = await openProject('/projects/polling/production')
|
||||
const { router, mounted } = await openProject('/projects/manual-refresh/subject-images')
|
||||
expect(mounted).not.toHaveBeenCalled()
|
||||
status = 'completed'
|
||||
await vi.advanceTimersByTimeAsync(6000)
|
||||
ready = true
|
||||
await vi.advanceTimersByTimeAsync(30_000)
|
||||
expect(mounted).not.toHaveBeenCalled()
|
||||
const refresh = wrapper!.findAll('button').find(button => button.text() === '刷新项目状态')!
|
||||
await refresh.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper!.get('.workspace-probe').text()).toBe('production')
|
||||
expect(wrapper!.get('.workspace-probe').text()).toBe('subject-images')
|
||||
expect(wrapper!.findAll('.n-menu a')).toHaveLength(9)
|
||||
status = 'need_review'
|
||||
await vi.advanceTimersByTimeAsync(6000)
|
||||
await router.push('/projects/manual-refresh/production')
|
||||
await flushPromises()
|
||||
ready = false
|
||||
await wrapper!.get('.probe-refresh').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
|
||||
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本创作')
|
||||
expect(wrapper!.findAll('.n-menu a')).toHaveLength(3)
|
||||
expect(mounted).toHaveBeenCalledExactlyOnceWith('production')
|
||||
expect(mounted.mock.calls.map(([path]) => path)).toEqual(['subject-images', 'production'])
|
||||
})
|
||||
|
||||
it('切换项目与首次读取期间不能沿用上一个已完成项目的权限', async () => {
|
||||
@@ -162,6 +206,7 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
id === 'first' ? project(id, 'completed') : pending
|
||||
)
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, id === 'first'))
|
||||
const { router, mounted } = await openProject('/projects/first/production')
|
||||
expect(wrapper!.findAll('.n-menu a')).toHaveLength(9)
|
||||
await router.push('/projects/second/production')
|
||||
@@ -177,7 +222,7 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
expect(wrapper!.findAll('.n-menu a')).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('读取失败保持锁定;错误区重试成功后解锁,页头不恢复标签与刷新按钮', async () => {
|
||||
it('读取失败保持锁定;重试成功后解锁,标题只保留项目配置入口', async () => {
|
||||
const detail = vi
|
||||
.spyOn(projectsApi, 'detail')
|
||||
.mockRejectedValueOnce(new Error('项目读取失败'))
|
||||
@@ -186,7 +231,8 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
const { mounted } = await openProject('/projects/retry/storyboard')
|
||||
expect(mounted).not.toHaveBeenCalled()
|
||||
expect(wrapper!.findAll('.n-menu a')).toHaveLength(3)
|
||||
expect(wrapper!.find('.project-header .n-button').exists()).toBe(false)
|
||||
expect(wrapper!.get('.project-header .n-button').text()).toBe('项目配置')
|
||||
expect(wrapper!.get('.project-header button').attributes('disabled')).toBeDefined()
|
||||
expect(wrapper!.find('.project-header .n-tag').exists()).toBe(false)
|
||||
await wrapper!.get('.project-notices button').trigger('click')
|
||||
await flushPromises()
|
||||
@@ -194,6 +240,36 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
expect(mounted).toHaveBeenCalledExactlyOnceWith('storyboard')
|
||||
})
|
||||
|
||||
it('剧本完成仍按服务端前置步骤逐步解锁,不能直接进入生产', async () => {
|
||||
const state = readiness('staged', false)
|
||||
state.script = { ready: true, reason: null }
|
||||
state.breakdown.reason = '请先完成剧本拆解'
|
||||
vi.mocked(projectsApi.stageReadiness).mockImplementation(async () => structuredClone(state))
|
||||
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('staged', 'completed'))
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
const { router, mounted } = await openProject('/projects/staged/production')
|
||||
expect(mounted).not.toHaveBeenCalled()
|
||||
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本拆解')
|
||||
expect(wrapper!.find('.n-menu a[href="/projects/staged/breakdown"]').exists()).toBe(true)
|
||||
expect(wrapper!.find('.n-menu a[href="/projects/staged/visual-style"]').exists()).toBe(false)
|
||||
await wrapper!.get('.project-access-gate button').trigger('click')
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.path).toBe('/projects/staged/breakdown')
|
||||
state.breakdown = { ready: true, reason: null }
|
||||
state.subjectAssets = { ready: true, reason: null }
|
||||
state.storyboard = { ready: false, reason: '请先完成分镜设计' }
|
||||
await wrapper!.get('.probe-refresh').trigger('click')
|
||||
await flushPromises()
|
||||
await router.push('/projects/staged/production')
|
||||
await flushPromises()
|
||||
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
|
||||
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成分镜设计')
|
||||
await wrapper!.get('.project-access-gate button').trigger('click')
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.path).toBe('/projects/staged/storyboard')
|
||||
expect(wrapper!.get('.workspace-probe').text()).toBe('storyboard')
|
||||
})
|
||||
|
||||
it('不存在、未知状态或项目 ID 不匹配时默认锁定', () => {
|
||||
expect(isProjectComplete(null, 'p')).toBe(false)
|
||||
expect(isProjectComplete({ id: 'other', status: 'completed' }, 'p')).toBe(false)
|
||||
|
||||
Reference in new issue
Block a user