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
@@ -414,7 +414,7 @@ describe('拆解页内容滚动', () => {
|
||||
await flushPromises()
|
||||
expect(drawerPanel().element.closest('.workspace-split')).toBeNull()
|
||||
await drawerPanel().get('#group-size').setValue('2')
|
||||
await drawerPanel().get('[aria-label="关闭操作面板"]').trigger('click')
|
||||
await drawerPanel().get('.n-card-header__close').trigger('click')
|
||||
provided.data.value!.checkpoints = [checkpoint()]
|
||||
await flushPromises()
|
||||
expect(wrapper!.get('.breakdown-results-scroll .n-scrollbar-container').element).toBe(results)
|
||||
|
||||
@@ -4,6 +4,11 @@ import { describe, expect, it } from 'vitest'
|
||||
import GenerationOptionFields from '../../../src/features/generation-config/components/GenerationOptionFields.vue'
|
||||
import type { GenerationOptionSchema } from '../../../src/features/generation-config/types'
|
||||
|
||||
/**
|
||||
* 挂载实际模型参数组件以核对下拉枚举与当前值。
|
||||
* @param schemas 后端参数目录
|
||||
* @returns 挂载后的组件
|
||||
*/
|
||||
function mountFields(schemas: GenerationOptionSchema[]) {
|
||||
return mount(GenerationOptionFields, {
|
||||
props: { schemas, modelValue: { size: '2K', durationSeconds: 4, seed: 1 } }
|
||||
@@ -11,20 +16,24 @@ function mountFields(schemas: GenerationOptionSchema[]) {
|
||||
}
|
||||
|
||||
describe('生成模型参数字段', () => {
|
||||
it('图片尺寸使用下拉框并保留标准尺寸与当前值', () => {
|
||||
it('图片尺寸只保留当前 Provider 枚举、默认值与当前值', () => {
|
||||
const wrapper = mountFields([
|
||||
{ key: 'size', label: '图片尺寸', type: 'size', required: true, providerDefault: 'auto' }
|
||||
{
|
||||
key: 'size',
|
||||
label: '图片尺寸',
|
||||
type: 'size',
|
||||
required: true,
|
||||
providerDefault: 'auto',
|
||||
options: [{ label: '目录支持尺寸', value: '2048*2048' }]
|
||||
}
|
||||
])
|
||||
const select = wrapper.getComponent(NSelect)
|
||||
expect(select.props('clearable')).toBe(false)
|
||||
expect(select.props('options')).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ value: '1K' }),
|
||||
expect.objectContaining({ value: '1.5K' }),
|
||||
expect.objectContaining({ value: '2K' }),
|
||||
expect.objectContaining({ value: 'auto' })
|
||||
])
|
||||
)
|
||||
expect(select.props('options')).toEqual([
|
||||
{ label: '目录支持尺寸', value: '2048*2048' },
|
||||
{ label: 'auto', value: 'auto' },
|
||||
{ label: '2K', value: '2K' }
|
||||
])
|
||||
expect(wrapper.findComponent(NInputNumber).exists()).toBe(false)
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { creativeProfileDraft, creativeProfileIssues } from '../../../src/features/generation-config/profile-draft'
|
||||
import type { CreativeProfileInput, GenerationModelCatalog } from '../../../src/features/generation-config/types'
|
||||
|
||||
/** 后端已保存的竖屏自定义尺寸,不限于目录的尺寸预设。 */
|
||||
const saved: CreativeProfileInput = {
|
||||
aspectRatio: '9:16',
|
||||
imageProvider: 'qwen-image',
|
||||
imageModel: 'qwen-image-3.0-pro',
|
||||
imageOptions: { size: '1080*1920', count: 1, promptExtend: false },
|
||||
videoProvider: 'wan',
|
||||
videoModel: 'wan3.0-video',
|
||||
videoOptions: { aspectRatio: 'adaptive', resolution: '1080P', duration: 5, audio: false }
|
||||
}
|
||||
|
||||
describe('项目配置编辑草稿', () => {
|
||||
it('读取与保存草稿保留真实自定义尺寸和未显示的供应方参数', () => {
|
||||
const draft = creativeProfileDraft(saved)
|
||||
expect(draft.imageOptions).toEqual({ size: '1080*1920', count: 1, promptExtend: false })
|
||||
expect(draft.videoOptions).toEqual({ aspectRatio: 'adaptive', resolution: '1080P', duration: 5, audio: false })
|
||||
})
|
||||
it('未保存的图片和视频参数修改不会污染实际已保存对象', () => {
|
||||
const draft = creativeProfileDraft(saved)
|
||||
draft.imageOptions.size = '2048*2048'
|
||||
draft.videoOptions.duration = 10
|
||||
expect(saved.imageOptions.size).toBe('1080*1920')
|
||||
expect(saved.videoOptions.duration).toBe(5)
|
||||
})
|
||||
})
|
||||
|
||||
/** 模型目录枚举与数字限制以真实后端 schema 规则为准。 */
|
||||
const catalog: GenerationModelCatalog = {
|
||||
defaults: { imageProvider: 'qwen-image', videoProvider: 'wan' },
|
||||
images: [
|
||||
{
|
||||
type: 'image',
|
||||
provider: 'qwen-image',
|
||||
providerLabel: 'Qwen',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen',
|
||||
supported: true,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
defaults: {},
|
||||
projectConstraints: [],
|
||||
generationOptions: [
|
||||
{
|
||||
key: 'size',
|
||||
label: '图片尺寸',
|
||||
type: 'size',
|
||||
required: true,
|
||||
options: [{ label: '竖屏', value: '1536*2688' }]
|
||||
},
|
||||
{ key: 'count', label: '数量', type: 'integer', required: true, min: 1, max: 1 }
|
||||
]
|
||||
}
|
||||
],
|
||||
videos: [
|
||||
{
|
||||
type: 'video',
|
||||
provider: 'wan',
|
||||
providerLabel: 'Wan',
|
||||
model: 'wan3.0-video',
|
||||
modelLabel: 'Wan',
|
||||
supported: true,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
defaults: {},
|
||||
projectConstraints: [],
|
||||
generationOptions: [
|
||||
{
|
||||
key: 'duration',
|
||||
label: '时长',
|
||||
type: 'integer',
|
||||
required: true,
|
||||
min: 2,
|
||||
max: 30,
|
||||
specialValues: [{ label: '自动', value: -1 }]
|
||||
},
|
||||
{ key: 'audio', label: '音轨', type: 'boolean', required: true }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
describe('项目配置保存前校验', () => {
|
||||
it('保留但提示不再支持的历史尺寸,选择有效尺寸后可保存', () => {
|
||||
const draft = creativeProfileDraft(saved)
|
||||
expect(creativeProfileIssues(draft, catalog)).toHaveLength(1)
|
||||
expect(draft.imageOptions.size).toBe('1080*1920')
|
||||
draft.imageOptions.size = '1536*2688'
|
||||
expect(creativeProfileIssues(draft, catalog)).toEqual([])
|
||||
})
|
||||
it('拒绝无效数值与缺失必填参数,允许后端支持的特殊时长', () => {
|
||||
const draft = creativeProfileDraft(saved)
|
||||
draft.imageOptions.size = '1536*2688'
|
||||
draft.imageOptions.count = 2
|
||||
delete draft.videoOptions.audio
|
||||
draft.videoOptions.duration = -1
|
||||
expect(creativeProfileIssues(draft, catalog)).toHaveLength(2)
|
||||
draft.imageOptions.count = 1
|
||||
draft.videoOptions.audio = false
|
||||
expect(creativeProfileIssues(draft, catalog)).toEqual([])
|
||||
})
|
||||
it('模型更新后拒绝目录中已不存在的旧模型', () => {
|
||||
const draft = creativeProfileDraft(saved)
|
||||
draft.imageOptions.size = '1536*2688'
|
||||
draft.imageModel = 'removed-image-model'
|
||||
expect(creativeProfileIssues(draft, catalog)).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { generationProfile } from '../../fixtures/generation'
|
||||
import { defineComponent } from 'vue'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
@@ -22,6 +23,7 @@ afterEach(() => {
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
vi.unstubAllGlobals()
|
||||
localStorage.clear()
|
||||
for (const id of ['capability-test', 'new-project']) {
|
||||
Object.assign(getOperation(id), { pending: false, error: '', notice: '', label: '' })
|
||||
Object.assign(getProductionSession(id), { receipt: null, pipelineReceipt: null })
|
||||
@@ -33,7 +35,12 @@ function stageFixture() {
|
||||
return { total: 1, planned: 1, skipped: 0, upstreamResolvable: 0, manualBlocked: 0 }
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造正式预检、202 任务句柄与后续数据库结果的模拟服务。
|
||||
* @returns 测试上下文、响应数据和已提交请求
|
||||
*/
|
||||
function server() {
|
||||
localStorage.clear()
|
||||
const context = testProjectContext()
|
||||
const form = formFixture('capability-test')
|
||||
const readiness = {
|
||||
@@ -75,6 +82,9 @@ function server() {
|
||||
videoGenerationResult: { total: 1, created: 1, skipped: 0, inProgress: 0, blocked: 0, failed: 0 }
|
||||
}
|
||||
const plan = {
|
||||
canStart: true,
|
||||
canAutoRun: true,
|
||||
providers: { image: 'qwen-image', video: 'seedance' },
|
||||
projectId: 'capability-test',
|
||||
completed: false,
|
||||
stage: 'subject_images',
|
||||
@@ -114,7 +124,26 @@ function server() {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
|
||||
const path = String(url)
|
||||
let data: unknown = context.project.value
|
||||
if (path.endsWith('/checkpoints')) data = context.checkpoints.value
|
||||
if (path.endsWith('/creative-profile')) data = generationProfile('capability-test')
|
||||
else if (path.includes('/workflow-executions/'))
|
||||
data = {
|
||||
id: 'capability-execution-1',
|
||||
projectId: 'capability-test',
|
||||
workflowName: 'production',
|
||||
status: 'completed',
|
||||
stage: 'finalize',
|
||||
current: 1,
|
||||
total: 1,
|
||||
currentResourceId: null,
|
||||
metadata: null,
|
||||
result: receipt,
|
||||
error: null,
|
||||
startedAt: '2026-10-08T00:00:00Z',
|
||||
completedAt: '2026-10-08T00:00:01Z',
|
||||
createdAt: '2026-10-08T00:00:00Z',
|
||||
updatedAt: '2026-10-08T00:00:01Z'
|
||||
}
|
||||
else if (path.endsWith('/checkpoints')) data = context.checkpoints.value
|
||||
else if (path.endsWith('/subject-forms')) data = [form]
|
||||
else if (path.endsWith('/production/plan')) data = plan
|
||||
else if (path.endsWith('/production/status')) data = status
|
||||
@@ -134,7 +163,7 @@ function server() {
|
||||
}
|
||||
else if (init?.method === 'POST')
|
||||
data = path.endsWith('/production/start')
|
||||
? receipt
|
||||
? { executionId: 'capability-execution-1', status: 'pending' }
|
||||
: { total: 1, targetCount: 1, generated: 1, skipped: 0, blocked: 0, failed: 0, failures: [] }
|
||||
return new Response(JSON.stringify({ data }))
|
||||
})
|
||||
@@ -154,6 +183,10 @@ function server() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂载实际生产组合函数并等待只读绑定。
|
||||
* @returns 测试数据和实际生产服务
|
||||
*/
|
||||
async function advanced() {
|
||||
const data = server()
|
||||
let service!: ReturnType<typeof useAdvancedProduction>
|
||||
@@ -171,7 +204,7 @@ async function advanced() {
|
||||
}
|
||||
|
||||
describe('高级串联生产的安全边界', () => {
|
||||
it('挂载不查询或生成,通过预检仍需显式启动,再次预检后提交空参数', async () => {
|
||||
it('挂载不查询或生成,通过预检仍需显式启动,再次预检后提交安全范围与项目模型参数', async () => {
|
||||
const { service, fetcher, posts } = await advanced()
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
await service.start()
|
||||
@@ -180,9 +213,19 @@ describe('高级串联生产的安全边界', () => {
|
||||
expect(service.check.value?.issues).toEqual([])
|
||||
expect(posts()).toHaveLength(0)
|
||||
await service.start()
|
||||
await flushPromises()
|
||||
expect(posts()).toHaveLength(1)
|
||||
expect(posts()[0]?.[0]).toBe('/api/projects/capability-test/production/start')
|
||||
expect(JSON.parse(String(posts()[0]?.[1]?.body))).toEqual({})
|
||||
expect(JSON.parse(String(posts()[0]?.[1]?.body))).toEqual({
|
||||
stopAfter: 'videoPrompts',
|
||||
stableIdentityAnchorLimit: 1,
|
||||
subjectImageLimit: 1,
|
||||
keyframeLimit: 1,
|
||||
videoPromptLimit: 1,
|
||||
imageProvider: 'qwen-image',
|
||||
videoProvider: 'seedance',
|
||||
imageGenerationOptions: { size: '2048*2048' }
|
||||
})
|
||||
expect(fetcher.mock.calls.filter(([url]) => String(url).endsWith('/production/plan'))).toHaveLength(2)
|
||||
expect(service.session.value.pipelineReceipt?.errors).toEqual(['一个提示词未生成'])
|
||||
expect(service.check.value).toBeNull()
|
||||
@@ -248,7 +291,7 @@ describe('高级串联生产的安全边界', () => {
|
||||
await flushPromises()
|
||||
expect(service.check.value).toBeNull()
|
||||
})
|
||||
it('已提交的长请求只写回原项目的回执,不污染新项目', async () => {
|
||||
it('迟到启动响应只保存原项目句柄,返回原项目后读取真实回执', async () => {
|
||||
const { service, context, fetcher, receipt } = await advanced()
|
||||
await service.preflight()
|
||||
const original = fetcher.getMockImplementation()!
|
||||
@@ -264,18 +307,31 @@ describe('高级串联生产的安全边界', () => {
|
||||
await flushPromises()
|
||||
context.data.value!.project.id = 'new-project'
|
||||
await flushPromises()
|
||||
finish(new Response(JSON.stringify({ data: receipt })))
|
||||
finish(
|
||||
new Response(JSON.stringify({ data: { executionId: 'capability-execution-1', status: 'pending' } }), {
|
||||
status: 202
|
||||
})
|
||||
)
|
||||
await pending
|
||||
expect(service.session.value.pipelineReceipt).toBeNull()
|
||||
expect(getProductionSession('capability-test').pipelineReceipt?.projectId).toBe('capability-test')
|
||||
expect(getProductionSession('capability-test').pipelineReceipt).toBeNull()
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:capability-test:production')).toBe(
|
||||
'capability-execution-1'
|
||||
)
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:new-project:production')).toBeNull()
|
||||
context.data.value!.project.id = 'capability-test'
|
||||
await flushPromises()
|
||||
expect(getProductionSession('capability-test').pipelineReceipt?.projectId).toBe(receipt.projectId)
|
||||
})
|
||||
it('回执项目不匹配时不发布成功回执', async () => {
|
||||
const { service, receipt } = await advanced()
|
||||
await service.preflight()
|
||||
receipt.projectId = 'wrong'
|
||||
await service.start()
|
||||
await flushPromises()
|
||||
expect(service.execution.query.data.value?.status).toBe('completed')
|
||||
expect(service.execution.query.data.value?.result?.projectId).toBe('wrong')
|
||||
expect(service.session.value.pipelineReceipt).toBeNull()
|
||||
expect(getOperation('capability-test').error).toContain('回执项目不匹配')
|
||||
})
|
||||
it('界面区分流程返回与视频完成,显示部分错误,启动需要费用确认', async () => {
|
||||
const { context, receipt, posts } = server()
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import QualityResult from '@/features/production/components/QualityResult.vue'
|
||||
import { expandSections } from '@/testing/naive'
|
||||
import ShotProductionAssets from '@/features/production/components/ShotProductionAssets.vue'
|
||||
import { primaryKeyframe } from '@/features/production/model'
|
||||
import { qualityKey, qualitySession, sessionKeyframePassed, sessionVideoValidation } from '@/features/production/quality'
|
||||
import {
|
||||
qualityKey,
|
||||
qualitySession,
|
||||
sessionKeyframePassed,
|
||||
sessionVideoValidation
|
||||
} from '@/features/production/quality'
|
||||
import { keyframeFixture, videoFixture } from '@/features/production/testing/fixtures'
|
||||
import { storyboardApi } from '@/features/storyboard/api'
|
||||
import { hasRunningWorkflow } from '@/features/workflows/selectors'
|
||||
@@ -64,7 +70,13 @@ describe('精简公开资产回归', () => {
|
||||
async url =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: String(url).endsWith('/videos') ? [video] : []
|
||||
data: String(url).endsWith('/generation-models')
|
||||
? imageCatalog
|
||||
: String(url).endsWith('/creative-profile')
|
||||
? generationProfile(projectId)
|
||||
: String(url).endsWith('/videos')
|
||||
? [video]
|
||||
: []
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -100,7 +112,13 @@ describe('精简公开资产回归', () => {
|
||||
async url =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: String(url).endsWith('/keyframes') ? [variant] : []
|
||||
data: String(url).endsWith('/generation-models')
|
||||
? imageCatalog
|
||||
: String(url).endsWith('/creative-profile')
|
||||
? generationProfile('public-variant-contract')
|
||||
: String(url).endsWith('/keyframes')
|
||||
? [variant]
|
||||
: []
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -110,7 +128,10 @@ describe('精简公开资产回归', () => {
|
||||
})
|
||||
try {
|
||||
await flushPromises()
|
||||
await wrapper.findAll('button').find(item => item.text().includes('管理候选'))!.trigger('click')
|
||||
await wrapper
|
||||
.findAll('button')
|
||||
.find(item => item.text().includes('管理候选'))!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('模型输入变体')
|
||||
expect(wrapper.findAll('button').some(button => button.text() === '设为主首帧')).toBe(false)
|
||||
@@ -129,7 +150,13 @@ describe('精简公开资产回归', () => {
|
||||
async url =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: String(url).endsWith('/keyframes') ? [primary, candidate] : []
|
||||
data: String(url).endsWith('/generation-models')
|
||||
? imageCatalog
|
||||
: String(url).endsWith('/creative-profile')
|
||||
? generationProfile(projectId)
|
||||
: String(url).endsWith('/keyframes')
|
||||
? [primary, candidate]
|
||||
: []
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -144,12 +171,15 @@ describe('精简公开资产回归', () => {
|
||||
expect(wrapper.find('.primary-keyframe-mark').attributes('aria-label')).toBe('当前主首帧')
|
||||
expect(wrapper.findAll('button').some(item => item.text().includes('设为主首帧'))).toBe(false)
|
||||
|
||||
await wrapper.findAll('button').find(item => item.text().includes('管理候选'))!.trigger('click')
|
||||
await wrapper
|
||||
.findAll('button')
|
||||
.find(item => item.text().includes('管理候选'))!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('首帧候选管理')
|
||||
expect([...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))).toBe(
|
||||
false
|
||||
)
|
||||
expect(
|
||||
[...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))
|
||||
).toBe(false)
|
||||
|
||||
const session = qualitySession(
|
||||
qualityKey(projectId, { kind: 'keyframe', shotId: shot.shotId, assetId: candidate.id, title: '' })
|
||||
@@ -172,16 +202,16 @@ describe('精简公开资产回归', () => {
|
||||
}
|
||||
await flushPromises()
|
||||
expect(sessionKeyframePassed(projectId, shot.shotId, candidate.id)).toBe(false)
|
||||
expect([...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))).toBe(
|
||||
false
|
||||
)
|
||||
expect(
|
||||
[...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))
|
||||
).toBe(false)
|
||||
|
||||
session.receipt.result.passed = true
|
||||
await flushPromises()
|
||||
expect(sessionKeyframePassed(projectId, shot.shotId, candidate.id)).toBe(true)
|
||||
expect([...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))).toBe(
|
||||
true
|
||||
)
|
||||
expect(
|
||||
[...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))
|
||||
).toBe(true)
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { createApp, effectScope, type EffectScope } from 'vue'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { useShotSelection } from '../../../src/features/storyboard/useShotSelection'
|
||||
|
||||
/** 测试作用域在每例结束后释放地址监听。 */
|
||||
let scope: EffectScope | undefined
|
||||
afterEach(() => scope?.stop())
|
||||
|
||||
/**
|
||||
* 使用真实路由和注入环境创建镜头选择状态。
|
||||
* @param url 初始页面地址
|
||||
* @returns 地址同步状态与真实路由
|
||||
*/
|
||||
async function selection(url: string) {
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [{ path: '/projects/:projectId/:section', component: {} }]
|
||||
})
|
||||
await router.push(url)
|
||||
const app = createApp({})
|
||||
app.use(router)
|
||||
scope = effectScope()
|
||||
const state = app.runWithContext(() => scope!.run(() => useShotSelection(() => 2))!)
|
||||
return { router, state }
|
||||
}
|
||||
|
||||
/** 等待 replace 导航完成,不替换路由实现。 */
|
||||
async function settled() {
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
}
|
||||
|
||||
describe('镜头地址选择', () => {
|
||||
it('刷新后的分镜和生产地址恢复剧集与正式镜头', async () => {
|
||||
for (const section of ['storyboard', 'production']) {
|
||||
scope?.stop()
|
||||
const { state } = await selection(`/projects/p1/${section}?episodeNo=2&shotId=shot-9`)
|
||||
expect(state.selectedEpisode.value).toBe(2)
|
||||
expect(state.selectedShot.value).toBe('shot-9')
|
||||
}
|
||||
})
|
||||
it('选择镜头记录当前剧集并保留来源动作及其它参数', async () => {
|
||||
const { router, state } = await selection('/projects/p1/production?action=keyframe&filter=ready')
|
||||
state.selectedShot.value = 'shot-8'
|
||||
await settled()
|
||||
expect(router.currentRoute.value.query).toEqual({
|
||||
action: 'keyframe',
|
||||
filter: 'ready',
|
||||
episodeNo: '2',
|
||||
shotId: 'shot-8'
|
||||
})
|
||||
})
|
||||
it('切换剧集清除上集镜头且保留其它参数', async () => {
|
||||
const { router, state } = await selection('/projects/p1/storyboard?episodeNo=2&shotId=old-shot&filter=ready')
|
||||
state.selectedEpisode.value = 3
|
||||
await settled()
|
||||
expect(router.currentRoute.value.query).toEqual({ episodeNo: '3', filter: 'ready' })
|
||||
expect(state.selectedShot.value).toBe('')
|
||||
})
|
||||
it('浏览器导航同步目标,拒绝无效或多值剧集', async () => {
|
||||
const { router, state } = await selection('/projects/p1/storyboard?episodeNo=2&shotId=shot-9')
|
||||
await router.push('/projects/p1/storyboard?episodeNo=3&shotId=shot-11')
|
||||
expect(state.selectedEpisode.value).toBe(3)
|
||||
expect(state.selectedShot.value).toBe('shot-11')
|
||||
await router.push('/projects/p1/storyboard?episodeNo=-1&shotId=missing')
|
||||
expect(state.selectedEpisode.value).toBeUndefined()
|
||||
expect(state.selectedShot.value).toBe('missing')
|
||||
await router.push('/projects/p1/storyboard?episodeNo=2&episodeNo=3')
|
||||
expect(state.selectedEpisode.value).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { NImage, NScrollbar } from 'naive-ui'
|
||||
@@ -43,40 +44,8 @@ function input(selector: string, value: string) {
|
||||
item.dispatchEvent(new Event(item.tagName === 'SELECT' ? 'change' : 'input', { bubbles: true }))
|
||||
}
|
||||
|
||||
const imageCatalog = {
|
||||
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
|
||||
images: [{
|
||||
type: 'image' as const,
|
||||
provider: 'qwen-image',
|
||||
providerLabel: 'Qwen',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen Image',
|
||||
supported: true as const,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
generationOptions: [{
|
||||
key: 'size',
|
||||
label: '图片尺寸',
|
||||
type: 'size' as const,
|
||||
required: true,
|
||||
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }]
|
||||
}],
|
||||
defaults: { size: '2048*2048' },
|
||||
projectConstraints: []
|
||||
}],
|
||||
videos: []
|
||||
}
|
||||
const creativeProfile = {
|
||||
projectId: 'project-1',
|
||||
aspectRatio: '1:1' as const,
|
||||
imageProvider: 'qwen-image',
|
||||
imageModel: 'qwen-image-3.0-pro',
|
||||
imageOptions: { size: '2048*2048' },
|
||||
videoProvider: 'seedance',
|
||||
videoModel: 'seedance',
|
||||
videoOptions: {}
|
||||
}
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('project-1')
|
||||
|
||||
describe('身份图与母版契约', () => {
|
||||
it('详情大图 contain 完整显示,历史仍为 cover,缩略图只切换记录', async () => {
|
||||
@@ -185,7 +154,7 @@ describe('身份图与母版契约', () => {
|
||||
.findAllComponents(AssetImage)
|
||||
.find(item => item.classes().includes('asset-image-preview'))!
|
||||
expect(preview.props('src')).toBe(image.status === 'completed' ? image.imageUrl : null)
|
||||
expect(wrapper.text()).toContain(`Identity image ID · ${image.id}`)
|
||||
expect(preview.props('alt')).toBe(`林夏 · ${image.viewType === 'primary' ? '身份母版' : '正面'}`)
|
||||
}
|
||||
await history.get('[aria-label="查看身份图片 failed"]').trigger('click')
|
||||
expect(wrapper.get('.asset-image-preview').text()).toContain('本次生成失败')
|
||||
@@ -288,13 +257,14 @@ describe('身份图与母版契约', () => {
|
||||
expect(castingStatusLabel('candidate_pending')).toBe('等待确认演员')
|
||||
})
|
||||
|
||||
it('辅助视角传递明确参考图、成对尺寸和本次 Prompt,不传形态生图字段', async () => {
|
||||
it('辅助视角传递明确参考图、目录尺寸和本次 Prompt,不传旧宽高字段', async () => {
|
||||
wrapper = mount(IdentityImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
open: true,
|
||||
subjectId: 's1',
|
||||
subjectName: '林夏',
|
||||
module: 'character',
|
||||
images: [identityImageFixture()],
|
||||
disabled: false,
|
||||
catalog: imageCatalog,
|
||||
@@ -304,13 +274,14 @@ describe('身份图与母版契约', () => {
|
||||
await flushPromises()
|
||||
input('#identity-view', 'three-quarter')
|
||||
input('#identity-reference', 'identity-image-1')
|
||||
input('#identity-width', '2048')
|
||||
document.querySelector<HTMLInputElement>('#identity-image-cost')!.click()
|
||||
await flushPromises()
|
||||
expect(document.querySelector('#identity-width')).toBeNull()
|
||||
expect(document.querySelector('#identity-height')).toBeNull()
|
||||
expect(button('确认生成身份图').disabled).toBe(true)
|
||||
input('#identity-height', '2048')
|
||||
input('#identity-image-prompt', ' 自定义身份提示词 ')
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#identity-image-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成身份图').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
@@ -318,8 +289,8 @@ describe('身份图与母版契约', () => {
|
||||
{
|
||||
viewType: 'three-quarter',
|
||||
referenceImageId: 'identity-image-1',
|
||||
width: 2048,
|
||||
height: 2048,
|
||||
provider: 'qwen-image',
|
||||
generationOptions: { size: '2048*2048' },
|
||||
prompt: '自定义身份提示词'
|
||||
}
|
||||
]
|
||||
@@ -333,6 +304,7 @@ describe('身份图与母版契约', () => {
|
||||
open: true,
|
||||
subjectId: 's1',
|
||||
subjectName: '林夏',
|
||||
module: 'character',
|
||||
images: [identityImageFixture()],
|
||||
disabled: false,
|
||||
catalog: imageCatalog,
|
||||
@@ -416,20 +388,22 @@ describe('身份图与母版契约', () => {
|
||||
disabled: false,
|
||||
catalog: {
|
||||
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
|
||||
images: [{
|
||||
type: 'image',
|
||||
provider: 'qwen-image',
|
||||
providerLabel: 'Qwen',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen Image',
|
||||
supported: true,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
generationOptions: [],
|
||||
defaults: { size: '1536*2688' },
|
||||
projectConstraints: []
|
||||
}],
|
||||
images: [
|
||||
{
|
||||
type: 'image',
|
||||
provider: 'qwen-image',
|
||||
providerLabel: 'Qwen',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen Image',
|
||||
supported: true,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
generationOptions: [],
|
||||
defaults: { size: '1536*2688' },
|
||||
projectConstraints: []
|
||||
}
|
||||
],
|
||||
videos: []
|
||||
},
|
||||
profile: {
|
||||
@@ -450,9 +424,9 @@ describe('身份图与母版契约', () => {
|
||||
await flushPromises()
|
||||
button('确认生成候选').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([[
|
||||
{ provider: 'qwen-image', generationOptions: { size: '1536*2688' } }
|
||||
]])
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
[{ provider: 'qwen-image', generationOptions: { size: '1536*2688' } }]
|
||||
])
|
||||
})
|
||||
|
||||
it('角色选角接口区分批量身份、候选生图与确认事务', async () => {
|
||||
|
||||
@@ -9,10 +9,53 @@ import { referenceLocation, referenceTargets } from '@/features/production/asset
|
||||
import StaleKeyframeNotice from '@/features/production/components/StaleKeyframeNotice.vue'
|
||||
import SubjectImagesPage from '@/features/subject-images/SubjectImagesPage.vue'
|
||||
import ProductionPage from '@/features/production/ProductionPage.vue'
|
||||
import ImageGalleryDialog from '@/features/subject-images/components/ImageGalleryDialog.vue'
|
||||
import type { CreativeProfile, GenerationModelCatalog } from '@/features/generation-config/types'
|
||||
import { directionsResult, storyboardCheckpoint } from '@/features/storyboard/testing/fixtures'
|
||||
import type { ProductionIssue } from '@/features/production/types'
|
||||
import type { ShotReferences } from '@/features/storyboard/types'
|
||||
|
||||
/** 使用后端模型目录结构,避免空数组被误当成可用模型。 */
|
||||
const imageCatalog: GenerationModelCatalog = {
|
||||
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
|
||||
images: [
|
||||
{
|
||||
type: 'image',
|
||||
provider: 'qwen-image',
|
||||
providerLabel: 'Qwen',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen Image',
|
||||
supported: true,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
generationOptions: [
|
||||
{
|
||||
key: 'size',
|
||||
label: '图片尺寸',
|
||||
type: 'size',
|
||||
required: true,
|
||||
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }]
|
||||
}
|
||||
],
|
||||
defaults: { size: '2048*2048' },
|
||||
projectConstraints: []
|
||||
}
|
||||
],
|
||||
videos: []
|
||||
}
|
||||
/** 模拟当前项目持久化的创作配置。 */
|
||||
const creativeProfile: CreativeProfile = {
|
||||
projectId: 'capability-test',
|
||||
aspectRatio: '1:1',
|
||||
imageProvider: 'qwen-image',
|
||||
imageModel: 'qwen-image-3.0-pro',
|
||||
imageOptions: { size: '2048*2048' },
|
||||
videoProvider: 'seedance',
|
||||
videoModel: 'seedance',
|
||||
videoOptions: {}
|
||||
}
|
||||
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
@@ -98,29 +141,40 @@ function fixture() {
|
||||
}
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
const path = String(url)
|
||||
const data = path.endsWith('/subject-forms')
|
||||
? [first, second, other]
|
||||
: path.includes('/keyframes/readiness')
|
||||
? keyframes
|
||||
: path.includes('/videos/readiness')
|
||||
? videos
|
||||
: path.endsWith('/references')
|
||||
? references
|
||||
: []
|
||||
const data = path.endsWith('/generation-models')
|
||||
? imageCatalog
|
||||
: path.endsWith('/creative-profile')
|
||||
? creativeProfile
|
||||
: path.endsWith('/subject-forms')
|
||||
? [first, second, other]
|
||||
: path.includes('/keyframes/readiness')
|
||||
? keyframes
|
||||
: path.includes('/videos/readiness')
|
||||
? videos
|
||||
: path.endsWith('/references')
|
||||
? references
|
||||
: []
|
||||
return new Response(JSON.stringify({ data }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
return { first, second, other, references, issues, keyframes, videos, fetcher }
|
||||
}
|
||||
|
||||
/** 在真实内存路由中验证跨页 URL,不替换 RouterLink 行为。 */
|
||||
async function gallery(query = '') {
|
||||
/**
|
||||
* 在真实内存路由中验证跨页 URL,并在首次请求前设置服务端状态。
|
||||
* @param query 初始素材定位参数
|
||||
* @param prepare 挂载前准备当前项目的接口响应
|
||||
* @returns 当前接口数据与真实内存路由
|
||||
*/
|
||||
async function gallery(query = '', prepare?: (data: ReturnType<typeof fixture>) => void) {
|
||||
const data = fixture()
|
||||
prepare?.(data)
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: '/projects/:projectId/subject-images', component: SubjectImagesPage },
|
||||
{ path: '/projects/:projectId/production', component: { template: '<div />' } }
|
||||
{ path: '/projects/:projectId/production', component: { template: '<div />' } },
|
||||
{ path: '/projects/:projectId/storyboard', component: { template: '<div />' } }
|
||||
]
|
||||
})
|
||||
await router.push('/projects/capability-test/subject-images' + query)
|
||||
@@ -132,14 +186,24 @@ async function gallery(query = '') {
|
||||
return { ...data, router }
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟图片记录中的主图变更完成通知,验证父页重读图库及影响状态。
|
||||
* @returns 全部资产查询完成
|
||||
*/
|
||||
async function assetsChanged() {
|
||||
wrapper!.findComponent(ImageGalleryDialog).vm.$emit('changed')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
describe('过期首帧到具体素材定位', () => {
|
||||
it('没有图片的形态卡片标记为方形占位', async () => {
|
||||
const { first } = await gallery()
|
||||
first.images = []
|
||||
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
|
||||
await flushPromises()
|
||||
const { first } = await gallery('', data => {
|
||||
data.first.images = []
|
||||
})
|
||||
const card = wrapper!.findAll('.form-image-card').find(item => item.attributes('data-form-id') === first.id)!
|
||||
expect(card.get('.asset-image').classes()).toContain('form-image-empty')
|
||||
expect(card.get('.asset-image').classes()).not.toContain('form-image-has-source')
|
||||
expect(card.get('.asset-image-empty').text()).toContain('尚未生成主参考图')
|
||||
expect(card.find('img').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('网格与瀑布流切换保留卡片、滚动容器和筛选,不发起额外请求', async () => {
|
||||
@@ -159,7 +223,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
.get('.gallery-layout-switch')
|
||||
.findAll('button')
|
||||
.map(button => button.attributes('aria-label'))
|
||||
).toEqual(['网格布局', '瀑布流布局', '刷新图库', '批量生图'])
|
||||
).toEqual(['网格布局', '瀑布流布局', '批量生图'])
|
||||
await wrapper!.get('[aria-label="网格布局"]').trigger('click')
|
||||
expect(wrapper!.find('.form-image-masonry').exists()).toBe(false)
|
||||
expect(wrapper!.get('[aria-label="网格布局"]').attributes('aria-pressed')).toBe('true')
|
||||
@@ -182,7 +246,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(requestCount)
|
||||
})
|
||||
|
||||
it('图库与关联检查不定时刷新,手动刷新仍能更新数据', async () => {
|
||||
it('图库与关联检查不定时刷新,图片记录变更后更新数据', async () => {
|
||||
vi.useFakeTimers()
|
||||
const { fetcher } = await gallery('?sourceShotId=shot-target')
|
||||
const count = fetcher.mock.calls.length
|
||||
@@ -191,13 +255,12 @@ describe('过期首帧到具体素材定位', () => {
|
||||
await flushPromises()
|
||||
expect(fetcher).toHaveBeenCalledTimes(count)
|
||||
expect(wrapper!.get('.form-image-grid').element).toBe(grid)
|
||||
const refresh = wrapper!.get('[aria-label="刷新图库"]')
|
||||
await refresh.trigger('click')
|
||||
await flushPromises()
|
||||
await assetsChanged()
|
||||
expect(fetcher.mock.calls.length).toBeGreaterThan(count)
|
||||
const refreshed = fetcher.mock.calls.length
|
||||
await vi.advanceTimersByTimeAsync(30_000)
|
||||
expect(fetcher).toHaveBeenCalledTimes(refreshed)
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
})
|
||||
|
||||
it('切换镜头时筛选、关联说明和图片共用稳定纵向容器,长关联列表单独横向滚动', async () => {
|
||||
@@ -224,8 +287,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
})
|
||||
: original(url, init)
|
||||
)
|
||||
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
|
||||
await flushPromises()
|
||||
await assetsChanged()
|
||||
wrapper!
|
||||
.findAllComponents(NSelect)
|
||||
.find(item => item.attributes('aria-label') === '选择关联镜头')!
|
||||
@@ -428,8 +490,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
it('精简图库没有历史母版字段时,不误报形态过期或破坏定位', async () => {
|
||||
const { first, router } = await gallery('?subjectFormId=form-other')
|
||||
first.subject.identity = { id: 'identity-1', isLocked: true, anchorImageId: 'anchor-new' }
|
||||
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
|
||||
await flushPromises()
|
||||
await assetsChanged()
|
||||
expect(wrapper!.text()).not.toContain('形态主图需要更新')
|
||||
expect(router.currentRoute.value.query.subjectFormId).toBe('form-other')
|
||||
expect(wrapper!.findAll('button').some(item => item.text() === '重新生成过期形态')).toBe(false)
|
||||
@@ -437,8 +498,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
it('仅视频接口报告过期时也显示警告,并明确两种检查不一致', async () => {
|
||||
const { keyframes } = await gallery('?sourceShotId=shot-target&subjectFormId=form-special')
|
||||
keyframes.items[0]!.primaryKeyframeStale = false
|
||||
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
|
||||
await flushPromises()
|
||||
await assetsChanged()
|
||||
expect(wrapper!.get('[data-keyframe-impact]').text()).toContain('检查结果不一致')
|
||||
expect(wrapper!.get('.form-image-card').text()).toContain('不要据此重复生图')
|
||||
})
|
||||
@@ -446,8 +506,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
const { keyframes, videos } = await gallery('?sourceShotId=shot-target&subjectFormId=form-special')
|
||||
keyframes.items[0]!.primaryKeyframeStale = false
|
||||
videos.items[0]!.issues = []
|
||||
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
|
||||
await flushPromises()
|
||||
await assetsChanged()
|
||||
expect(wrapper!.find('[data-keyframe-impact]').exists()).toBe(false)
|
||||
expect(wrapper!.text()).toContain('未被标记为过期')
|
||||
})
|
||||
@@ -466,8 +525,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
? Promise.resolve(new Response('{}', { status: 500 }))
|
||||
: original(url, init)
|
||||
)
|
||||
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
|
||||
await flushPromises()
|
||||
await assetsChanged()
|
||||
expect(wrapper!.text()).toContain('暂时无法确认有无过期首帧')
|
||||
expect(wrapper!.findAll('.form-image-card')).toHaveLength(3)
|
||||
})
|
||||
@@ -480,11 +538,15 @@ describe('过期首帧到具体素材定位', () => {
|
||||
const path = String(url)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: path.includes('/storyboard-directions')
|
||||
? data
|
||||
: path.includes('/readiness') || path.endsWith('/videos/status')
|
||||
? { total: 0, items: [] }
|
||||
: []
|
||||
data: path.endsWith('/generation-models')
|
||||
? imageCatalog
|
||||
: path.endsWith('/creative-profile')
|
||||
? creativeProfile
|
||||
: path.includes('/storyboard-directions')
|
||||
? data
|
||||
: path.includes('/readiness') || path.endsWith('/videos/status')
|
||||
? { total: 0, items: [] }
|
||||
: []
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { AssetImage } from '@/components/ui'
|
||||
@@ -8,22 +9,8 @@ import { coverImage, hasRunningImages, primaryImage, validImageSize } from '@/fe
|
||||
import { formFixture, imageFixture } from '@/features/subject-images/testing/fixtures'
|
||||
import { expandSections } from '@/testing/naive'
|
||||
|
||||
const imageCatalog = {
|
||||
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
|
||||
images: [{
|
||||
type: 'image' as const, provider: 'qwen-image', providerLabel: 'Qwen', model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen Image', supported: true as const, enabled: true, isDefault: true, capabilities: {},
|
||||
generationOptions: [{ key: 'size', label: '图片尺寸', type: 'size' as const, required: true,
|
||||
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }] }],
|
||||
defaults: { size: '2048*2048' }, projectConstraints: []
|
||||
}],
|
||||
videos: []
|
||||
}
|
||||
const creativeProfile = {
|
||||
projectId: 'gallery-test', aspectRatio: '1:1' as const, imageProvider: 'qwen-image',
|
||||
imageModel: 'qwen-image-3.0-pro', imageOptions: { size: '2048*2048' },
|
||||
videoProvider: 'seedance', videoModel: 'seedance', videoOptions: {}
|
||||
}
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('gallery-test')
|
||||
let wrapper: VueWrapper | undefined
|
||||
/** Naive 将弹窗挂载到 body,需要从实际弹窗找到按钮。 */
|
||||
function button(label: string): HTMLButtonElement {
|
||||
@@ -81,7 +68,10 @@ describe('形态图片选择与操作', () => {
|
||||
it.each(['character', 'scene', 'prop'])('按后端最新 %s 模块展示母版继承范围', async module => {
|
||||
const form = formFixture()
|
||||
form.subject.module = module
|
||||
wrapper = mount(GenerateImageDialog, { attachTo: document.body, props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile } })
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
})
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('母版')
|
||||
expect(document.body.textContent).not.toContain('道具形态生图暂不自动引用')
|
||||
@@ -149,7 +139,7 @@ describe('形态图片选择与操作', () => {
|
||||
expect(validImageSize(width, height)).toBe(false)
|
||||
})
|
||||
|
||||
it('生图确认发送正式形态 ID,不覆盖后端模型,默认不替换已有主图', async () => {
|
||||
it('生图确认发送正式形态 ID 和项目模型参数,默认不替换已有主图', async () => {
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form: formFixture(), disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
@@ -160,29 +150,39 @@ describe('形态图片选择与操作', () => {
|
||||
await flushPromises()
|
||||
button('确认生成图片').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([['form-db-1', { setPrimary: false }]])
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
['form-db-1', { setPrimary: false, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
|
||||
])
|
||||
})
|
||||
|
||||
it('新形态默认设主图,填写一侧尺寸时不能提交,切换形态清空自定义提示词', async () => {
|
||||
it('新形态默认设主图并继承目录尺寸,切换形态清空提示词和费用确认', async () => {
|
||||
const form = formFixture()
|
||||
form.images = []
|
||||
wrapper = mount(GenerateImageDialog, { attachTo: document.body, props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile } })
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
})
|
||||
await flushPromises()
|
||||
const width = document.querySelector<HTMLInputElement>('#image-width')!
|
||||
width.value = '2048'
|
||||
width.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
const prompt = document.querySelector<HTMLTextAreaElement>('#image-prompt')!
|
||||
prompt.value = '上一形态自定义提示词'
|
||||
prompt.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
expect(button('确认生成图片').disabled).toBe(true)
|
||||
expect(button('确认生成图片').disabled).toBe(false)
|
||||
expect(wrapper.emitted('generate')).toBeUndefined()
|
||||
await wrapper.setProps({ form: { ...form, id: 'form-db-2' } })
|
||||
await flushPromises()
|
||||
expect(width.value).toBe('')
|
||||
expect(prompt.value).toBe('')
|
||||
expect(document.querySelector('#image-width')).toBeNull()
|
||||
expect(document.querySelector('#image-height')).toBeNull()
|
||||
expect(document.querySelector('#confirm-image-cost')!.getAttribute('aria-checked')).toBe('false')
|
||||
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成图片').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([['form-db-2', { setPrimary: true }]])
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
['form-db-2', { setPrimary: true, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
|
||||
])
|
||||
})
|
||||
|
||||
it('图库不自动生图,主图切换经确认后 PUT,失败图片不能设主图', async () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { defineComponent } from 'vue'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
@@ -10,22 +11,8 @@ import { useSubjectImages } from '@/features/subject-images/useSubjectImages'
|
||||
import FormPromptDialog from '@/features/subject-images/components/FormPromptDialog.vue'
|
||||
import GenerateImageDialog from '@/features/subject-images/components/GenerateImageDialog.vue'
|
||||
|
||||
const imageCatalog = {
|
||||
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
|
||||
images: [{
|
||||
type: 'image' as const, provider: 'qwen-image', providerLabel: 'Qwen', model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen Image', supported: true as const, enabled: true, isDefault: true, capabilities: {},
|
||||
generationOptions: [{ key: 'size', label: '图片尺寸', type: 'size' as const, required: true,
|
||||
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }] }],
|
||||
defaults: { size: '2048*2048' }, projectConstraints: []
|
||||
}],
|
||||
videos: []
|
||||
}
|
||||
const creativeProfile = {
|
||||
projectId: 'gallery-test', aspectRatio: '1:1' as const, imageProvider: 'qwen-image',
|
||||
imageModel: 'qwen-image-3.0-pro', imageOptions: { size: '2048*2048' },
|
||||
videoProvider: 'seedance', videoModel: 'seedance', videoOptions: {}
|
||||
}
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('gallery-test')
|
||||
let wrapper: VueWrapper | undefined
|
||||
const projectId = 'capability-test'
|
||||
/** 从实际挂载的确认弹窗查找操作按钮。 */
|
||||
@@ -115,7 +102,7 @@ describe('形态正式提示词与批量配置', () => {
|
||||
new Response(JSON.stringify({ data: { id: 'form-db-1', subjectId: 'subject-db-1', generationPrompt: '' } }))
|
||||
)
|
||||
await service.generatePrompt('form-db-1', false)
|
||||
expect(getOperation(projectId).error).toContain('未确认正式提示词已保存')
|
||||
expect(getOperation(projectId).error).toContain('提示词保存结果未确认')
|
||||
})
|
||||
it('批量提示词保留部分失败回执,不覆盖图片回执且不传图片上限', async () => {
|
||||
const { service, posts } = await setup()
|
||||
@@ -178,7 +165,10 @@ describe('形态正式提示词与批量配置', () => {
|
||||
})
|
||||
it('正式提示词确认必须勾选,未确认不发送事件', async () => {
|
||||
const form = formFixture()
|
||||
wrapper = mount(FormPromptDialog, { attachTo: document.body, props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile } })
|
||||
wrapper = mount(FormPromptDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile }
|
||||
})
|
||||
await flushPromises()
|
||||
find('生成正式提示词').click()
|
||||
await flushPromises()
|
||||
@@ -194,7 +184,10 @@ describe('形态正式提示词与批量配置', () => {
|
||||
const form = formFixture()
|
||||
form.appearancePrompt = null
|
||||
form.generationPrompt = null
|
||||
wrapper = mount(GenerateImageDialog, { attachTo: document.body, props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile } })
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile }
|
||||
})
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
@@ -204,6 +197,8 @@ describe('形态正式提示词与批量配置', () => {
|
||||
expect(submit.disabled).toBe(false)
|
||||
submit.click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([['form-db-1', { setPrimary: false }]])
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
['form-db-1', { setPrimary: false, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,9 @@
|
||||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||||
import { computed, ref } from 'vue'
|
||||
import { NImage, NRadioGroup, NScrollbar } from 'naive-ui'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi, type Mock } from 'vitest'
|
||||
import CreateProjectDialog from '@/features/projects/components/CreateProjectDialog.vue'
|
||||
import BreakdownPage from '@/features/breakdown/BreakdownPage.vue'
|
||||
import CreateDramaPage from '@/features/create-drama/CreateDramaPage.vue'
|
||||
@@ -15,7 +16,6 @@ import ShotTools from '@/features/storyboard/components/ShotTools.vue'
|
||||
import {
|
||||
designedShot,
|
||||
directionsResult,
|
||||
episodeShots,
|
||||
storyboardCheckpoint,
|
||||
visualStatesResult
|
||||
} from '@/features/storyboard/testing/fixtures'
|
||||
@@ -53,6 +53,58 @@ function jsonResponse(data: unknown) {
|
||||
return new Response(JSON.stringify({ data }))
|
||||
}
|
||||
|
||||
/**
|
||||
* 为页面模拟请求补齐正式模型目录和配置,后台启动返回 202 句柄,结果只从任务 GET 读取;响应逐次复制避免消费同一正文。
|
||||
* @param fetcher 业务 API 模拟请求
|
||||
*/
|
||||
function stubFetch(fetcher: Mock<typeof fetch>) {
|
||||
const implementation = fetcher.getMockImplementation()!
|
||||
const executions = new Map<string, object>()
|
||||
let executionCount = 0
|
||||
fetcher.mockImplementation(async (url, init) => {
|
||||
const path = String(url)
|
||||
if (path.endsWith('/generation-models')) return jsonResponse(imageCatalog)
|
||||
if (path.endsWith('/creative-profile')) return jsonResponse(generationProfile(fixture.id))
|
||||
if (path.includes('/workflow-executions/')) return jsonResponse(executions.get(path.split('/').at(-1)!))
|
||||
const response = await implementation(url, init)
|
||||
const workflowName = path.endsWith('/storyboard-directions/generate')
|
||||
? 'storyboard-direction'
|
||||
: path.endsWith('/storyboard-visual-states/generate')
|
||||
? 'storyboard-visual-state'
|
||||
: path.endsWith('/storyboard-shots/regenerate')
|
||||
? 'breakdown'
|
||||
: ''
|
||||
if (init?.method === 'POST' && workflowName && response.ok) {
|
||||
const result = (await response.clone().json()).data
|
||||
const executionId = `page-execution-${++executionCount}`
|
||||
const body = JSON.parse(String(init.body))
|
||||
executions.set(executionId, {
|
||||
id: executionId,
|
||||
projectId: fixture.id,
|
||||
workflowName,
|
||||
status: 'completed',
|
||||
stage: 'finalize',
|
||||
current: 1,
|
||||
total: 1,
|
||||
currentResourceId: null,
|
||||
metadata:
|
||||
workflowName === 'breakdown'
|
||||
? { action: 'regenerate-storyboard-episode', episodeNo: body.episodeNo }
|
||||
: null,
|
||||
result,
|
||||
error: null,
|
||||
startedAt: '2026-10-08T00:00:00Z',
|
||||
completedAt: '2026-10-08T00:00:01Z',
|
||||
createdAt: '2026-10-08T00:00:00Z',
|
||||
updatedAt: '2026-10-08T00:00:01Z'
|
||||
})
|
||||
return new Response(JSON.stringify({ data: { executionId, status: 'pending' } }), { status: 202 })
|
||||
}
|
||||
return response.clone()
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
}
|
||||
|
||||
/** 模拟 API 响应仅用于测试,不会打包进生产页面。 */
|
||||
const fixture: ProjectDetail = {
|
||||
id: 'page-test-project',
|
||||
@@ -109,7 +161,9 @@ function button(label: string): HTMLButtonElement {
|
||||
async function confirmGeneration(label: string) {
|
||||
button(label).click()
|
||||
await flushPromises()
|
||||
const acknowledgement = document.querySelector<HTMLElement>('.app-dialog [role="checkbox"]')
|
||||
const acknowledgement = button('确认' + label)
|
||||
.closest('.app-dialog')!
|
||||
.querySelector<HTMLElement>('[role="checkbox"]')
|
||||
expect(button('确认' + label).disabled).toBe(true)
|
||||
acknowledgement!.click()
|
||||
await flushPromises()
|
||||
@@ -153,6 +207,7 @@ afterEach(() => {
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
vi.unstubAllGlobals()
|
||||
localStorage.clear()
|
||||
Object.assign(getStoryboardSession(fixture.id), { receipt: null, prompts: {}, regeneratedEpisodes: {} })
|
||||
getImageSession(fixture.id).receipt = null
|
||||
getImageSession(fixture.id).promptReceipt = null
|
||||
@@ -181,7 +236,7 @@ describe('内容级滚动下的生产反馈', () => {
|
||||
})
|
||||
return jsonResponse([])
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ProductionPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
@@ -207,7 +262,7 @@ describe('内容级滚动下的生产反馈', () => {
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
})
|
||||
it('默认折叠总览时查询错误仍显示在内容区外层', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn<typeof fetch>().mockRejectedValue(new Error('生产连接中断')))
|
||||
stubFetch(vi.fn<typeof fetch>().mockRejectedValue(new Error('生产连接中断')))
|
||||
wrapper = mount(ProductionPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
@@ -221,7 +276,7 @@ describe('内容级滚动下的生产反馈', () => {
|
||||
})
|
||||
|
||||
it('回执返回时自动展开总览,部分失败诊断不会留在折叠区内', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn<typeof fetch>().mockRejectedValue(new Error('离线测试')))
|
||||
stubFetch(vi.fn<typeof fetch>().mockRejectedValue(new Error('离线测试')))
|
||||
wrapper = mount(ProductionPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
@@ -255,17 +310,16 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockImplementation(async () => jsonResponse(locked === null ? null : styleFixture({ isLocked: locked })))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('style')
|
||||
const status = wrapper!.get('.visual-style-status')
|
||||
expect(status.attributes('role')).toBe('status')
|
||||
expect(status.get('strong').text()).toBe(label)
|
||||
expect(status.find('button').exists()).toBe(false)
|
||||
expect(wrapper!.find('.visual-style-toolbar .n-tag').exists()).toBe(false)
|
||||
expect(wrapper!.get('.visual-style-actions').findAll('button')).toHaveLength(2)
|
||||
expect(wrapper!.get('.visual-style-actions').findAll('button')).toHaveLength(1)
|
||||
expect(button(action).disabled).toBe(disabled)
|
||||
expect(button(action).style.getPropertyValue('--n-height')).toBe('34px')
|
||||
expect(button('刷新风格').style.getPropertyValue('--n-height')).toBe('34px')
|
||||
expect(fetcher.mock.calls.every(([, options]) => !options?.method || options.method === 'GET')).toBe(true)
|
||||
})
|
||||
|
||||
@@ -320,9 +374,9 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
await drawerPanel().get('[aria-label="关闭操作面板"]').trigger('click')
|
||||
await drawerPanel().get('.n-card-header__close').trigger('click')
|
||||
await flushPromises()
|
||||
const items = wrapper!.findAll('.identity-subject-item')
|
||||
expect(items).toHaveLength(3)
|
||||
@@ -337,7 +391,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
})
|
||||
|
||||
it('从形态深链接进入后,手动切换主体不会被目录刷新切回', async () => {
|
||||
it('从形态深链接进入后,手动选择其它主体保持当前选择', async () => {
|
||||
const form = formFixture()
|
||||
const second = {
|
||||
...form,
|
||||
@@ -346,8 +400,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
images: [],
|
||||
subject: { ...form.subject, id: 'subject-2', name: '陆川', ref: '@CH0002' }
|
||||
}
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
stubFetch(
|
||||
vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
if (String(url).endsWith('/subject-forms')) return jsonResponse([form, second])
|
||||
if (String(url).endsWith('/visual-style')) return jsonResponse(styleFixture())
|
||||
@@ -360,8 +413,6 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(sidebar.get('.identity-subject-list').findAll('.directory-item')).toHaveLength(2)
|
||||
await wrapper!.findAll('.identity-subject-item')[1]!.trigger('click')
|
||||
await flushPromises()
|
||||
await wrapper!.get('[aria-label="刷新主体目录"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper!.findAll('.identity-subject-item')[1]!.attributes('aria-pressed')).toBe('true')
|
||||
})
|
||||
|
||||
@@ -383,23 +434,27 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
if (init?.method === 'PUT') identity = { ...identity, ...JSON.parse(init.body as string) }
|
||||
return jsonResponse(identity)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
await wrapper!.get('#identity-description').setValue('人工稳定身份')
|
||||
await wrapper!.get('#identity-lock').trigger('click')
|
||||
await new DOMWrapper(document.body).get('#identity-description').setValue('人工稳定身份')
|
||||
await new DOMWrapper(document.body).get('#identity-lock').trigger('click')
|
||||
button('保存主体身份').click()
|
||||
await flushPromises()
|
||||
const put = fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')!
|
||||
expect(put[0]).toBe('/api/subjects/subject-db-1/identity')
|
||||
expect(JSON.parse(put[1]!.body as string)).toMatchObject({ description: '人工稳定身份', isLocked: true })
|
||||
expect(button('生成选角候选').disabled).toBe(false)
|
||||
await wrapper!.get('#identity-description').setValue('新的未保存草稿')
|
||||
await new DOMWrapper(document.body).get('#identity-description').setValue('新的未保存草稿')
|
||||
await wrapper!.findAll('.identity-subject-item')[1]!.trigger('click')
|
||||
expect(wrapper!.text()).toContain('切换会丢弃草稿')
|
||||
expect((wrapper!.get('#identity-description').element as HTMLTextAreaElement).value).toBe('新的未保存草稿')
|
||||
expect(document.body.textContent).toContain('切换会丢弃草稿')
|
||||
expect((new DOMWrapper(document.body).get('#identity-description').element as HTMLTextAreaElement).value).toBe(
|
||||
'新的未保存草稿'
|
||||
)
|
||||
button('放弃草稿并切换').click()
|
||||
await flushPromises()
|
||||
expect((wrapper!.get('#identity-description').element as HTMLTextAreaElement).value).toBe('')
|
||||
expect((new DOMWrapper(document.body).get('#identity-description').element as HTMLTextAreaElement).value).toBe(
|
||||
''
|
||||
)
|
||||
})
|
||||
|
||||
it('风格图拒绝危险 URL,登记只传已有地址及分类排序', async () => {
|
||||
@@ -407,7 +462,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockImplementation(async (_url, init) => jsonResponse(init?.method === 'POST' ? image : styleFixture()))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('style')
|
||||
await wrapper!.get('[aria-label="风格图片地址"]').setValue('javascript:alert(1)')
|
||||
button('登记参考图').click()
|
||||
@@ -431,7 +486,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
|
||||
it('AI 确认取消后重新打开必须再次确认,不能复用上次勾选', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async () => jsonResponse(styleFixture()))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('style')
|
||||
button('AI 重新生成风格').click()
|
||||
await flushPromises()
|
||||
@@ -451,7 +506,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
if (init?.method === 'PUT') style = styleFixture(JSON.parse(init.body as string))
|
||||
return jsonResponse(style)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('style')
|
||||
expect(wrapper!.text()).toContain('尚未创建')
|
||||
await expandSections()
|
||||
@@ -479,26 +534,19 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'POST')).toBe(false)
|
||||
})
|
||||
|
||||
it('刷新风格不覆盖未保存草稿,草稿存在时禁止 AI 重生成', async () => {
|
||||
it('未保存风格草稿保持人工输入并禁止 AI 重生成', async () => {
|
||||
let style = styleFixture()
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>().mockImplementation(async () => jsonResponse(style))
|
||||
)
|
||||
stubFetch(vi.fn<typeof fetch>().mockImplementation(async () => jsonResponse(style)))
|
||||
await mountAssets('style')
|
||||
await wrapper!.get('#style-prompt').setValue('人工草稿')
|
||||
style = styleFixture({ prompt: '后台新内容' })
|
||||
button('刷新风格').click()
|
||||
await flushPromises()
|
||||
expect((wrapper!.get('#style-prompt').element as HTMLTextAreaElement).value).toBe('人工草稿')
|
||||
expect(button('AI 重新生成风格').disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('风格接口 404 显示错误而不是当作空风格,禁止写入', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>().mockResolvedValue(new Response('{"message":"路由不存在"}', { status: 404 }))
|
||||
)
|
||||
stubFetch(vi.fn<typeof fetch>().mockResolvedValue(new Response('{"message":"路由不存在"}', { status: 404 })))
|
||||
await mountAssets('style')
|
||||
expect(wrapper!.text()).toContain('路由不存在')
|
||||
expect(button('AI 生成风格').disabled).toBe(true)
|
||||
@@ -520,7 +568,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(String(url)).toContain('/visual-style')
|
||||
return jsonResponse(styleFixture({ images: removed ? [] : [image] }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('style')
|
||||
button('停用').click()
|
||||
await flushPromises()
|
||||
@@ -546,13 +594,13 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
if (String(url).endsWith('/visual-style')) return jsonResponse(styleFixture())
|
||||
return jsonResponse(null)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
expect(wrapper!.findAll('.identity-subject-item')).toHaveLength(1)
|
||||
expect(wrapper!.text()).toContain('2 个形态')
|
||||
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/subjects/subject-db-1/identity'))).toBe(true)
|
||||
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/identity/images'))).toBe(false)
|
||||
expect(button('配置生成模型').disabled).toBe(false)
|
||||
expect(button('生成身份文本').disabled).toBe(false)
|
||||
})
|
||||
|
||||
it('锁定阻止身份 AI 覆盖但不阻止人工编辑,并按步骤进入后续操作', async () => {
|
||||
@@ -563,16 +611,16 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
if (String(url).endsWith('/identity/images')) return jsonResponse([identityImageFixture()])
|
||||
return jsonResponse(identityFixture({ isLocked: true }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
expect(wrapper!.text()).toContain('主体身份已完成')
|
||||
await new DOMWrapper(document.body).get('#identity-description').setValue('人工稳定身份草稿')
|
||||
expect(button('保存主体身份').disabled).toBe(false)
|
||||
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'POST')).toBe(false)
|
||||
})
|
||||
|
||||
it('无项目风格时禁止生成身份和图片,但仍可人工保存身份', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
stubFetch(
|
||||
vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
if (String(url).endsWith('/subject-forms')) return jsonResponse([formFixture()])
|
||||
if (String(url).endsWith('/visual-style')) return jsonResponse(null)
|
||||
@@ -582,6 +630,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
)
|
||||
await mountAssets('identity')
|
||||
expect(button('设置视觉风格').disabled).toBe(false)
|
||||
await new DOMWrapper(document.body).get('#identity-description').setValue('人工稳定身份草稿')
|
||||
expect(button('保存主体身份').disabled).toBe(false)
|
||||
})
|
||||
|
||||
@@ -601,7 +650,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
if (String(url).endsWith('/visual-style')) return jsonResponse(styleFixture())
|
||||
return jsonResponse(null)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
await confirmGeneration('补齐全部主体身份文本')
|
||||
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
|
||||
@@ -621,13 +670,18 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
if (String(url).endsWith('/visual-style')) return jsonResponse(styleFixture())
|
||||
if (init?.method === 'PUT') {
|
||||
selected = true
|
||||
return jsonResponse(identityImageFixture({ id: 'candidate' }))
|
||||
return jsonResponse({
|
||||
identityId: 'identity-db-1',
|
||||
subjectId: 'subject-db-1',
|
||||
isLocked: true,
|
||||
anchor: identityImageFixture({ id: 'candidate', isAnchor: true })
|
||||
})
|
||||
}
|
||||
if (String(url).endsWith('/identity/images'))
|
||||
return jsonResponse([identityImageFixture({ id: 'candidate', isAnchor: selected })])
|
||||
return jsonResponse(identityFixture())
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
button('设为身份母版').click()
|
||||
await flushPromises()
|
||||
@@ -635,7 +689,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
button('确认切换身份母版').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')?.[0]).toBe(
|
||||
'/api/subjects/subject-db-1/identity/images/candidate/anchor'
|
||||
'/api/subjects/subject-db-1/identity/images/candidate/stable-anchor'
|
||||
)
|
||||
expect(wrapper!.text()).toContain('当前身份母版')
|
||||
const anchorImage = wrapper!
|
||||
@@ -686,7 +740,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
expect(drawerPanel().get('.identity-tools-intro').text()).toContain('为同一个人物、场景或道具固定稳定特征')
|
||||
const cards = drawerPanel().get('[aria-label="角色选角进度"]').findAll('.casting-item')
|
||||
@@ -702,7 +756,9 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(cards[0]!.attributes('aria-pressed')).toBe('false')
|
||||
expect(cards[1]!.attributes('aria-pressed')).toBe('true')
|
||||
expect(cards[1]!.classes()).toContain('selected')
|
||||
expect(wrapper!.get<HTMLTextAreaElement>('#identity-description').element.value).toBe('老周的稳定身份')
|
||||
expect(new DOMWrapper(document.body).get<HTMLTextAreaElement>('#identity-description').element.value).toBe(
|
||||
'老周的稳定身份'
|
||||
)
|
||||
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/subjects/subject-db-2/identity'))).toBe(true)
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
})
|
||||
@@ -751,7 +807,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
}
|
||||
return jsonResponse(identityFixture({ isLocked: locked }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
expect(wrapper!.text()).toContain('等待确认演员')
|
||||
button('确认选角并锁定').click()
|
||||
@@ -788,7 +844,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
identityFixture({ id: 'identity-2', subjectId: 'subject-2', description: '陆川的稳定身份' })
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
await wrapper!.findAll('.identity-subject-item')[1]!.trigger('click')
|
||||
await flushPromises()
|
||||
@@ -797,7 +853,9 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
).toBe(true)
|
||||
finish(jsonResponse(identityFixture()))
|
||||
await flushPromises()
|
||||
expect((wrapper!.get('#identity-description').element as HTMLTextAreaElement).value).toBe('陆川的稳定身份')
|
||||
expect((new DOMWrapper(document.body).get('#identity-description').element as HTMLTextAreaElement).value).toBe(
|
||||
'陆川的稳定身份'
|
||||
)
|
||||
})
|
||||
|
||||
it('生成失败不自动重发,后端正在拆解时禁止身份写操作', async () => {
|
||||
@@ -809,7 +867,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
if (String(url).endsWith('/identity')) return jsonResponse(null)
|
||||
return jsonResponse(identityFixture())
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
const provided = await mountAssets('identity')
|
||||
button('生成身份文本').click()
|
||||
await flushPromises()
|
||||
@@ -817,7 +875,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(getOperation(fixture.id).error).toContain('无法连接后端')
|
||||
provided.data.value!.project = { ...fixture, status: 'generating' }
|
||||
await flushPromises()
|
||||
expect(button('保存主体身份').disabled).toBe(true)
|
||||
expect(new DOMWrapper(document.body).get('#identity-description').attributes('disabled')).toBeDefined()
|
||||
expect(button('生成身份文本').disabled).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -832,7 +890,7 @@ describe('工作台页面交互', () => {
|
||||
subject: { ...person.subject, id: 'scene-subject', ref: '@SC0001', name: '旧书店', module: 'scene' }
|
||||
}
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async () => jsonResponse([person, scene]))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountSubjectImages()
|
||||
const filters = wrapper!.get('.form-image-filters')
|
||||
expect(wrapper!.get('.form-image-toolbar').classes()).not.toContain('has-impact-picker')
|
||||
@@ -879,18 +937,23 @@ describe('工作台页面交互', () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockImplementation(async () => new Response(JSON.stringify({ data: [formFixture()] })))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountSubjectImages()
|
||||
expect(wrapper!.get('.form-image-card img').attributes('src')).toContain(
|
||||
'/storage/subjects/project/form/image.png'
|
||||
)
|
||||
expect(wrapper!.text()).toContain('林知夏')
|
||||
expect(wrapper!.text()).toContain('主参考图')
|
||||
expect(fetcher.mock.calls.map(([url, init]) => [url, init?.method])).toEqual([
|
||||
['/api/projects/page-test-project/subject-forms', 'GET'],
|
||||
['/api/projects/page-test-project/keyframes/readiness?force=false', 'GET'],
|
||||
['/api/projects/page-test-project/videos/readiness?force=false', 'GET']
|
||||
])
|
||||
expect(fetcher.mock.calls.map(([url, init]) => [url, init?.method])).toEqual(
|
||||
expect.arrayContaining([
|
||||
['/api/projects/page-test-project/subject-forms', 'GET'],
|
||||
['/api/generation-models', 'GET'],
|
||||
['/api/projects/page-test-project/creative-profile', 'GET'],
|
||||
['/api/projects/page-test-project/keyframes/readiness?force=false', 'GET'],
|
||||
['/api/projects/page-test-project/videos/readiness?force=false', 'GET']
|
||||
])
|
||||
)
|
||||
expect(fetcher).toHaveBeenCalledTimes(5)
|
||||
await wrapper!.get('[aria-label="搜索形态图片"]').setValue('不存在的形态')
|
||||
expect(wrapper!.text()).toContain('没有匹配的形态')
|
||||
button('清除筛选').click()
|
||||
@@ -905,9 +968,9 @@ describe('工作台页面交互', () => {
|
||||
.mockImplementation(async url =>
|
||||
jsonResponse(String(url).endsWith('/subject-forms') ? [form] : form.images)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountSubjectImages()
|
||||
await drawerPanel().get('[aria-label="关闭操作面板"]').trigger('click')
|
||||
await drawerPanel().get('.n-card-header__close').trigger('click')
|
||||
const card = wrapper!.get('.form-image-card')
|
||||
expect(card.getComponent(NImage).props()).toMatchObject({ objectFit: 'contain', previewDisabled: false })
|
||||
await card.get('img').trigger('click')
|
||||
@@ -916,7 +979,7 @@ describe('工作台页面交互', () => {
|
||||
'/storage/subjects/project/form/image.png'
|
||||
)
|
||||
expect(document.querySelector('.image-history')).toBeNull()
|
||||
expect(fetcher).toHaveBeenCalledTimes(3)
|
||||
expect(fetcher).toHaveBeenCalledTimes(5)
|
||||
document.querySelector<HTMLElement>('.n-image-preview-overlay')!.click()
|
||||
await flushPromises()
|
||||
button('查看图片与记录').click()
|
||||
@@ -930,25 +993,32 @@ describe('工作台页面交互', () => {
|
||||
const form = formFixture()
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (_url, init) => {
|
||||
if (init?.method === 'POST') {
|
||||
const candidate = imageFixture({ id: 'new-candidate', isPrimary: false, imageUrl: '/storage/new.png' })
|
||||
const candidate = imageFixture({
|
||||
id: 'new-candidate',
|
||||
isPrimary: false,
|
||||
status: 'pending',
|
||||
imageUrl: null
|
||||
})
|
||||
form.images.unshift(candidate)
|
||||
return new Response(JSON.stringify({ data: candidate }))
|
||||
}
|
||||
return new Response(JSON.stringify({ data: [form] }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountSubjectImages()
|
||||
button('再生成一张').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
document
|
||||
.querySelector('.app-dialog form')!
|
||||
.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }))
|
||||
button('确认生成图片').click()
|
||||
await flushPromises()
|
||||
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
|
||||
expect(post[0]).toBe('/api/subject-forms/form-db-1/images')
|
||||
expect(JSON.parse(post[1]!.body as string)).toEqual({ setPrimary: false })
|
||||
expect(JSON.parse(post[1]!.body as string)).toEqual({
|
||||
setPrimary: false,
|
||||
provider: 'qwen-image',
|
||||
generationOptions: { size: '2048*2048' }
|
||||
})
|
||||
expect(wrapper!.text()).toContain('2 条记录')
|
||||
expect(wrapper!.get('.form-image-card img').attributes('src')).not.toContain('/storage/new.png')
|
||||
expect(fetcher.mock.calls.some(([url]) => String(url).includes('production/start'))).toBe(false)
|
||||
@@ -973,7 +1043,7 @@ describe('工作台页面交互', () => {
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountSubjectImages()
|
||||
await wrapper!.get('[aria-label="搜索形态图片"]').setValue('@CH0001')
|
||||
await confirmGeneration('补齐项目主参考图')
|
||||
@@ -981,7 +1051,10 @@ describe('工作台页面交互', () => {
|
||||
expect(drawerPanel().text()).toContain('服务暂不可用')
|
||||
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
|
||||
expect(JSON.parse(post[1]!.body as string)).toEqual({ concurrency: 2, force: false })
|
||||
await drawerPanel().get('.n-collapse [role="checkbox"]').trigger('click')
|
||||
await drawerPanel()
|
||||
.findAll('[role="checkbox"]')
|
||||
.find(item => item.text().includes('已有主图也新增候选图'))!
|
||||
.trigger('click')
|
||||
await confirmGeneration('为全项目新增候选图')
|
||||
const lastPost = fetcher.mock.calls.filter(([, init]) => init?.method === 'POST').at(-1)!
|
||||
expect(JSON.parse(lastPost[1]!.body as string).force).toBe(true)
|
||||
@@ -998,15 +1071,17 @@ describe('工作台页面交互', () => {
|
||||
? new Response('{"message":"数据库异常"}', { status: 500 })
|
||||
: new Response(JSON.stringify({ data: [form] }))
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountSubjectImages()
|
||||
expect(button('再生成一张').disabled).toBe(true)
|
||||
expect(wrapper!.text()).toContain('数据库中仍有排队或生成中的图片')
|
||||
expect(wrapper!.text()).toContain('数据库中有形态图片正在后台生成')
|
||||
fail = true
|
||||
button('刷新图库').click()
|
||||
button('查看图片与记录').click()
|
||||
await flushPromises()
|
||||
expect(wrapper!.text()).toContain('数据库异常')
|
||||
expect(document.body.textContent).toContain('数据库异常')
|
||||
expect(wrapper!.find('.form-image-card img').exists()).toBe(true)
|
||||
await new DOMWrapper(button('刷新图片').closest('.app-dialog')!).get('.n-card-header__close').trigger('click')
|
||||
await flushPromises()
|
||||
expect(button('补齐项目主参考图').disabled).toBe(true)
|
||||
})
|
||||
it('分镜参考图使用 cover 和原生预览,查看图片不触发生成功能', async () => {
|
||||
@@ -1030,9 +1105,8 @@ describe('工作台页面交互', () => {
|
||||
missing: []
|
||||
})
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, { attachTo: document.body, props: { projectId: fixture.id, shot, disabled: false } })
|
||||
button('读取参考图').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.getComponent(NImage).props()).toMatchObject({ objectFit: 'cover', previewDisabled: false })
|
||||
const image = wrapper.get('.reference-card img')
|
||||
@@ -1097,9 +1171,8 @@ describe('工作台页面交互', () => {
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, { attachTo: document.body, props: { projectId: fixture.id, shot, disabled: false } })
|
||||
button('读取参考图').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('图片不可用')
|
||||
expect(wrapper.find('.reference-card a').exists()).toBe(false)
|
||||
@@ -1130,12 +1203,12 @@ describe('工作台页面交互', () => {
|
||||
)
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountStoryboard()
|
||||
await flushPromises()
|
||||
await confirmGeneration('补齐项目导演设计')
|
||||
expect(button('补齐项目导演设计').disabled).toBe(true)
|
||||
await drawerPanel().get('[aria-label="关闭操作面板"]').trigger('click')
|
||||
await drawerPanel().get('.n-card-header__close').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper!.get('[data-workspace-tools]').attributes('aria-expanded')).toBe('false')
|
||||
expect(getOperation(fixture.id).pending).toBe(true)
|
||||
@@ -1149,6 +1222,12 @@ describe('工作台页面交互', () => {
|
||||
)
|
||||
)
|
||||
await flushPromises()
|
||||
expect(getStoryboardSession(fixture.id).receipt).toBeNull()
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:page-test-project:storyboard-direction')).toBe(
|
||||
'page-execution-1'
|
||||
)
|
||||
await mountStoryboard()
|
||||
await flushPromises()
|
||||
expect(getStoryboardSession(fixture.id).receipt).toMatchObject({
|
||||
kind: 'batch',
|
||||
title: '项目导演设计'
|
||||
@@ -1191,7 +1270,7 @@ describe('工作台页面交互', () => {
|
||||
: visualStatesResult(fixture.id)
|
||||
return new Response(JSON.stringify({ data: result }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountStoryboard()
|
||||
await flushPromises()
|
||||
expect(wrapper!.text()).not.toContain('生成本集导演设计')
|
||||
@@ -1211,16 +1290,12 @@ describe('工作台页面交互', () => {
|
||||
expect(drawerPanel().text()).toContain('缺少主体状态')
|
||||
})
|
||||
|
||||
it('重生成当前集镜头后刷新正式设计,并用接口回执替换过期 Breakdown 文本', async () => {
|
||||
const regenerated = episodeShots()
|
||||
regenerated.beatShots[0]!.shots[0]!.title = '重生成后的开场镜头'
|
||||
regenerated.beatShots[0]!.shots[0]!.description = '新的镜头正文'
|
||||
it('重生成当前集镜头后读取后台终态,并废弃过期 Breakdown 文本', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
|
||||
if (init?.method === 'POST')
|
||||
return jsonResponse({
|
||||
projectId: fixture.id,
|
||||
episodeNo: 1,
|
||||
episodeShot: regenerated,
|
||||
storyboardShotSummary: {
|
||||
episodeCount: 1,
|
||||
beatCount: 2,
|
||||
@@ -1238,20 +1313,25 @@ describe('工作台页面交互', () => {
|
||||
: visualStatesResult(fixture.id)
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountStoryboard()
|
||||
await confirmGeneration('重生成第 1 集镜头')
|
||||
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
|
||||
expect(post[0]).toBe('/api/projects/page-test-project/storyboard-shots/regenerate')
|
||||
expect(JSON.parse(post[1]!.body as string)).toEqual({ episodeNo: 1 })
|
||||
expect(wrapper!.text()).toContain('重生成后的开场镜头')
|
||||
expect(wrapper!.text()).toContain('新的镜头正文')
|
||||
expect(wrapper!.text()).not.toContain('第1集镜头1')
|
||||
expect(wrapper!.text()).not.toContain('门口收到一封信')
|
||||
expect(getStoryboardSession(fixture.id).invalidatedEpisodeSources[1]).toBe(true)
|
||||
expect(wrapper!.text()).toContain('新标题和剧情详情尚未提供')
|
||||
expect(drawerPanel().text()).toContain('本集新镜头已保存')
|
||||
expect(drawerPanel().text()).toContain('2 个镜头')
|
||||
expect(fetcher.mock.calls.filter(([, init]) => !init?.method || init.method === 'GET')).toHaveLength(4)
|
||||
expect(fetcher.mock.calls.filter(([, init]) => !init?.method || init.method === 'GET')).toHaveLength(8)
|
||||
expect(fetcher.mock.calls.some(([url]) => String(url) === '/api/workflow-executions/page-execution-1')).toBe(
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('批量 200 部分失败不显示全成功,默认补齐与显式覆盖参数独立', async () => {
|
||||
it('后台终态部分失败不显示全成功,默认补齐与显式覆盖参数独立', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
|
||||
if (init?.method === 'POST')
|
||||
return new Response(
|
||||
@@ -1286,7 +1366,7 @@ describe('工作台页面交互', () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountStoryboard()
|
||||
await flushPromises()
|
||||
await confirmGeneration('补齐项目导演设计')
|
||||
@@ -1319,7 +1399,7 @@ describe('工作台页面交互', () => {
|
||||
)
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountStoryboard()
|
||||
await flushPromises()
|
||||
selectControl(wrapper!, 'aria-label', '选择分镜剧集').vm.$emit('update:value', 2)
|
||||
@@ -1341,8 +1421,8 @@ describe('工作台页面交互', () => {
|
||||
expect(fetcher.mock.calls).toHaveLength(4)
|
||||
})
|
||||
|
||||
it('查询失败保留已读取镜头并禁用生成,刷新恢复后才允许操作', async () => {
|
||||
let fail = false
|
||||
it('首次分镜读取失败时禁用生成,重试恢复后才允许操作', async () => {
|
||||
let fail = true
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
if (fail) return new Response('{"message":"数据库暂不可用"}', { status: 503 })
|
||||
return new Response(
|
||||
@@ -1353,19 +1433,16 @@ describe('工作台页面交互', () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
await mountStoryboard()
|
||||
await flushPromises()
|
||||
fail = true
|
||||
button('刷新分镜').click()
|
||||
await flushPromises()
|
||||
expect(wrapper!.text()).toContain('shot-db-1-1')
|
||||
expect(wrapper!.text()).toContain('数据库暂不可用')
|
||||
expect(button('补齐项目导演设计').disabled).toBe(true)
|
||||
fail = false
|
||||
button('重试查询').click()
|
||||
await flushPromises()
|
||||
expect(button('补齐项目导演设计').disabled).toBe(false)
|
||||
expect(wrapper!.text()).toContain('shot-db-1-1')
|
||||
})
|
||||
|
||||
it('镜头工具按需 GET,切换镜头会废弃旧参考图,未完成设计不能编译规格', async () => {
|
||||
@@ -1376,13 +1453,12 @@ describe('工作台页面交互', () => {
|
||||
finish = resolve
|
||||
})
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: fixture.id, shot: designedShot(), disabled: false }
|
||||
})
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
button('读取参考图').click()
|
||||
expect(fetcher).toHaveBeenCalledTimes(1)
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/storyboard-shots/shot-db-1-1/references')
|
||||
await wrapper.setProps({ shot: { ...designedShot('shot-db-1-2'), visualState: null } })
|
||||
@@ -1398,40 +1474,41 @@ describe('工作台页面交互', () => {
|
||||
})
|
||||
|
||||
it('提示词必须确认才 POST,使用正式 Shot ID,返回内容以纯文本显示', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
shotId: 'shot-db-1-1',
|
||||
updatedAt: '2026-09-10T00:00:00Z',
|
||||
videoPrompt: '<script>模型内容</script>',
|
||||
negativePrompt: '模糊',
|
||||
status: 'prompt_ready'
|
||||
}
|
||||
})
|
||||
)
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (_url, init) =>
|
||||
init?.method !== 'POST'
|
||||
? jsonResponse({ shotId: 'shot-db-1-1', references: [], missing: [] })
|
||||
: new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
shotId: 'shot-db-1-1',
|
||||
updatedAt: '2026-09-10T00:00:00Z',
|
||||
videoPrompt: '<script>模型内容</script>',
|
||||
negativePrompt: '模糊',
|
||||
status: 'prompt_ready'
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: fixture.id, shot: designedShot(), disabled: false }
|
||||
})
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
await confirmGeneration('读取/生成提示词')
|
||||
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/storyboard-shots/shot-db-1-1/video-prompt')
|
||||
expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string)).toEqual({ force: false })
|
||||
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
|
||||
expect(post[0]).toBe('/api/storyboard-shots/shot-db-1-1/video-prompt')
|
||||
expect(JSON.parse(post[1]!.body as string)).toEqual({ force: false })
|
||||
expect(wrapper.text()).toContain('<script>模型内容</script>')
|
||||
expect(wrapper.find('script').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('提示词生成缺少主首帧时保存当前剧集和镜头作为恢复位置', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
stubFetch(
|
||||
vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
message:
|
||||
'服务器内部错误 Shot 缺少可用于视频 0 秒起点校验的 Primary Keyframe: shot-db-1-1'
|
||||
message: '服务器内部错误 Shot 缺少可用于视频 0 秒起点校验的 Primary Keyframe: shot-db-1-1'
|
||||
}),
|
||||
{ status: 500 }
|
||||
)
|
||||
@@ -1451,8 +1528,7 @@ describe('工作台页面交互', () => {
|
||||
})
|
||||
})
|
||||
it('项目筛选无结果时可清除条件并返回真实列表', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
stubFetch(
|
||||
vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: [fixture] })))
|
||||
)
|
||||
const router = createRouter({
|
||||
@@ -1463,10 +1539,6 @@ describe('工作台页面交互', () => {
|
||||
wrapper = mount(ProjectsPage, { attachTo: document.body, global: { plugins: [router] } })
|
||||
await flushPromises()
|
||||
expect(wrapper.getComponent(NRadioGroup).props('size')).toBe('medium')
|
||||
const refresh = wrapper.get('[aria-label="刷新项目"]')
|
||||
expect(refresh.classes()).toContain('icon-button')
|
||||
expect(refresh.find('.n-button__icon svg').exists()).toBe(true)
|
||||
expect(refresh.text()).toBe('')
|
||||
expect(wrapper.text()).toContain('雨夜来信')
|
||||
await wrapper.get('input[aria-label="搜索项目"]').setValue('不存在的关键词')
|
||||
expect(wrapper.text()).toContain('没有匹配的剧本')
|
||||
@@ -1478,11 +1550,16 @@ describe('工作台页面交互', () => {
|
||||
it('新建弹窗提交真实参数并返回 202 的项目 ID', async () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(new Response('{"projectId":"created","status":"generating"}', { status: 202 }))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
.mockResolvedValue(
|
||||
new Response('{"projectId":"created","executionId":"create-1","status":"pending"}', { status: 202 })
|
||||
)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(CreateProjectDialog, { attachTo: document.body })
|
||||
button('新建剧本').click()
|
||||
await flushPromises()
|
||||
const title = document.querySelector<HTMLInputElement>('#title')!
|
||||
title.value = ' 雨夜来信标题 '
|
||||
title.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
const topic = document.querySelector<HTMLTextAreaElement>('#topic')!
|
||||
topic.value = ' 雨夜来信 '
|
||||
topic.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
@@ -1491,8 +1568,9 @@ describe('工作台页面交互', () => {
|
||||
count.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
document.querySelector('form')!.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }))
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('created')).toEqual([['created']])
|
||||
expect(wrapper.emitted('created')).toEqual([['created', 'create-1']])
|
||||
expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string)).toEqual({
|
||||
title: '雨夜来信标题',
|
||||
topic: '雨夜来信',
|
||||
style: '',
|
||||
episodeCount: 6
|
||||
@@ -1507,7 +1585,7 @@ describe('工作台页面交互', () => {
|
||||
)
|
||||
return new Response('{"data":{"workflowExecution":{"status":"completed"}}}')
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
stubFetch(fetcher)
|
||||
const provided = context()
|
||||
wrapper = mount(BreakdownPage, {
|
||||
attachTo: document.body,
|
||||
|
||||
Reference in new issue
Block a user