1200 lines
55 KiB
TypeScript
1200 lines
55 KiB
TypeScript
import { policyReceipt } from '../../fixtures/quality-policy'
|
||
import { computed, ref } from 'vue'
|
||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||
import { NButton, NSelect, NSpin } from 'naive-ui'
|
||
import { readFileSync } from 'node:fs'
|
||
import BreakdownPage from '@/features/breakdown/BreakdownPage.vue'
|
||
import { projectContextKey, type useProjectData } from '@/features/projects/context'
|
||
import type { ProjectDetail } from '@/features/projects/types'
|
||
import type { Checkpoint } from '@/features/workflows/types'
|
||
import type { BreakdownModule, EpisodePlan } from '@/features/breakdown/types'
|
||
import { drawerPanel } from '@/testing/naive'
|
||
import { readAllStyles } from '@/testing/styles'
|
||
import { effectScope } from 'vue'
|
||
import { useWorkflowExecution } from '@/features/workflows/execution'
|
||
import { workflowExecutionApi } from '@/features/workflows/execution-api'
|
||
import { breakdownApi } from '@/features/breakdown/api'
|
||
import {
|
||
candidateCheckpoint,
|
||
candidateReview,
|
||
candidateState,
|
||
resourceConflictState
|
||
} from '../../fixtures/breakdown-candidate'
|
||
import { projectsApi } from '@/features/projects/api'
|
||
import type { ProjectQualityPolicy } from '@/features/projects/types'
|
||
import { getOperation } from '@/features/workflows/operations'
|
||
import { WorkspaceTools } from '@/components/ui'
|
||
import BreakdownCandidatePanel from '@/features/breakdown/components/BreakdownCandidatePanel.vue'
|
||
import { commitPreview } from '../../fixtures/breakdown-candidate'
|
||
|
||
let wrapper: VueWrapper | undefined
|
||
|
||
it('候选预检可从工具栏直达,从设置进入先关闭原抽屉再预检,成功后刷新全部阶段', async () => {
|
||
vi.spyOn(breakdownApi, 'revalidateCandidate').mockResolvedValue(
|
||
candidateReview({ projectId: 'breakdown-scroll-test' })
|
||
)
|
||
const preview = vi
|
||
.spyOn(breakdownApi, 'candidateCommitPreview')
|
||
.mockResolvedValue(commitPreview({ projectId: 'breakdown-scroll-test' }))
|
||
const context = mountPage([candidateCheckpoint(candidateState({ projectId: 'breakdown-scroll-test' }))])
|
||
await flushPromises()
|
||
expect(wrapper!.find('[aria-label="候选安全预检"]').exists()).toBe(true)
|
||
await wrapper!.get('[data-workspace-tools]').trigger('click')
|
||
await flushPromises()
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '候选安全预检')!
|
||
.trigger('click')
|
||
expect(wrapper!.getComponent(WorkspaceTools).props('open')).toBe(false)
|
||
expect(wrapper!.getComponent(BreakdownCandidatePanel).props('open')).toBe(false)
|
||
expect(preview).not.toHaveBeenCalled()
|
||
wrapper!.getComponent(WorkspaceTools).vm.$emit('closed')
|
||
await flushPromises()
|
||
expect(wrapper!.getComponent(BreakdownCandidatePanel).props('open')).toBe(true)
|
||
expect(preview).toHaveBeenCalledOnce()
|
||
wrapper!.getComponent(BreakdownCandidatePanel).vm.$emit('refresh')
|
||
await flushPromises()
|
||
expect(context.refresh).toHaveBeenCalled()
|
||
expect(context.refreshStageReadiness).toHaveBeenCalled()
|
||
})
|
||
|
||
it('没有拆解数据时提供居中的主设置入口,只打开现有抽屉,不预览或生成', async () => {
|
||
const preview = vi.spyOn(breakdownApi, 'preview')
|
||
const run = vi.spyOn(breakdownApi, 'run')
|
||
mountPage([])
|
||
await flushPromises()
|
||
const empty = wrapper!.find('.breakdown-initial-empty')
|
||
expect(empty.exists()).toBe(true)
|
||
expect(wrapper!.get('.workspace-heading-scroll').isVisible()).toBe(false)
|
||
expect(wrapper!.find('.result-toolbar').exists()).toBe(false)
|
||
const entry = empty.get('button[aria-label="拆解设置"]')
|
||
expect(
|
||
wrapper!
|
||
.findAllComponents(NButton)
|
||
.find(button => button.element === entry.element)!
|
||
.props('type')
|
||
).toBe('primary')
|
||
await entry.trigger('click')
|
||
await flushPromises()
|
||
expect(document.querySelectorAll('.app-drawer')).toHaveLength(1)
|
||
expect(drawerPanel().isVisible()).toBe(true)
|
||
expect(wrapper!.get('[data-workspace-tools]').attributes('aria-expanded')).toBe('true')
|
||
expect(drawerPanel().text()).toContain('拆解设置')
|
||
expect(preview).not.toHaveBeenCalled()
|
||
expect(run).not.toHaveBeenCalled()
|
||
})
|
||
|
||
it('首次点击生成先读取并确认质量规则,不直接打开模型启动确认', async () => {
|
||
const readPolicy = vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue(
|
||
policyReceipt('breakdown-scroll-test', {
|
||
version: 1,
|
||
physicsMode: 'realistic',
|
||
allowExaggeratedMotion: false,
|
||
allowNonPhysicalActions: false,
|
||
allowSupernaturalAbilities: false,
|
||
customRules: []
|
||
})
|
||
)
|
||
vi.spyOn(breakdownApi, 'preview').mockResolvedValue({
|
||
episodeCount: 1,
|
||
groupCount: 1,
|
||
estimatedTaskCount: 3,
|
||
tasks: [],
|
||
modules: ['character', 'scene', 'prop'],
|
||
groupSize: 3,
|
||
groups: [{ groupId: 'preview-group', groupNo: 1, startEpisodeNo: 1, endEpisodeNo: 1, episodes: [] }]
|
||
})
|
||
const start = vi.spyOn(breakdownApi, 'run')
|
||
mountPage()
|
||
await wrapper!.get('[data-workspace-tools]').trigger('click')
|
||
await flushPromises()
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '预览分组')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '生成拆解候选')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(readPolicy).toHaveBeenCalledTimes(1)
|
||
expect(drawerPanel().text()).toContain('拆解前确认质量规则')
|
||
expect(document.querySelector('.app-dialog')).toBeNull()
|
||
expect(start).not.toHaveBeenCalled()
|
||
})
|
||
|
||
it('规则确认保留分组预览,隐藏空白例外,确认不调用模型,未变规则不重复打开表单', async () => {
|
||
const result = policyReceipt('breakdown-scroll-test', {
|
||
version: 1,
|
||
physicsMode: 'realistic',
|
||
allowExaggeratedMotion: false,
|
||
allowNonPhysicalActions: false,
|
||
allowSupernaturalAbilities: false,
|
||
customRules: []
|
||
})
|
||
vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(async () => structuredClone(result))
|
||
vi.spyOn(projectsApi, 'confirmQualityPolicy').mockImplementation(async () => {
|
||
Object.assign(result, { confirmed: true, confirmedRevision: 2, confirmedAt: '2026-10-17T15:00:00Z' })
|
||
return structuredClone(result)
|
||
})
|
||
vi.spyOn(breakdownApi, 'preview').mockResolvedValue({
|
||
episodeCount: 1,
|
||
groupCount: 1,
|
||
estimatedTaskCount: 3,
|
||
tasks: [],
|
||
modules: ['character', 'scene', 'prop'],
|
||
groupSize: 3,
|
||
groups: [{ groupId: 'preview-group', groupNo: 1, startEpisodeNo: 1, endEpisodeNo: 1, episodes: [] }]
|
||
})
|
||
const save = vi.spyOn(projectsApi, 'saveQualityPolicy')
|
||
const start = vi.spyOn(breakdownApi, 'run')
|
||
mountPage()
|
||
await wrapper!.get('[data-workspace-tools]').trigger('click')
|
||
await flushPromises()
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '预览分组')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '生成拆解候选')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '取消')!
|
||
.trigger('click')
|
||
expect(drawerPanel().text()).toContain('第 1–1 集')
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '生成拆解候选')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(
|
||
drawerPanel()
|
||
.findAll('button')
|
||
.some(button => button.text() === '添加例外')
|
||
).toBe(false)
|
||
await drawerPanel()
|
||
.findAll('[role="checkbox"]')
|
||
.find(box => box.text().includes('我已核对'))!
|
||
.trigger('click')
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '确认规则并继续')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(document.querySelector('.app-dialog')?.textContent).toContain('可能产生模型费用')
|
||
expect(save).not.toHaveBeenCalled()
|
||
expect(start).not.toHaveBeenCalled()
|
||
await new DOMWrapper(document.querySelector('.app-dialog')!)
|
||
.findAll('button')
|
||
.find(button => button.text() === '取消')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
await drawerPanel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '生成拆解候选')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(drawerPanel().text()).not.toContain('拆解前确认质量规则')
|
||
expect(document.querySelector('.app-dialog')?.textContent).toContain('可能产生模型费用')
|
||
expect(start).not.toHaveBeenCalled()
|
||
})
|
||
|
||
it('当前动作问题在问题抽屉中提供例外修订,保存期间锁定关闭且保存后仍需审核', async () => {
|
||
let policy: ProjectQualityPolicy = {
|
||
version: 1,
|
||
physicsMode: 'realistic',
|
||
allowExaggeratedMotion: false,
|
||
allowNonPhysicalActions: false,
|
||
allowSupernaturalAbilities: false,
|
||
customRules: []
|
||
}
|
||
vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(async () =>
|
||
policyReceipt('breakdown-scroll-test', policy)
|
||
)
|
||
let finish!: () => void
|
||
const save = vi.spyOn(projectsApi, 'saveQualityPolicy').mockImplementation(async (id, input) => {
|
||
await new Promise<void>(resolve => {
|
||
finish = resolve
|
||
})
|
||
policy = input
|
||
return policyReceipt(id, input)
|
||
})
|
||
vi.spyOn(breakdownApi, 'revalidateCandidate').mockResolvedValue(
|
||
candidateReview({
|
||
projectId: 'breakdown-scroll-test',
|
||
actionQualityBlocks: [
|
||
{
|
||
episodeNo: 1,
|
||
beatNo: 1,
|
||
shotNo: 1,
|
||
status: 'blocked',
|
||
blockingCodes: ['action_resource_conflict'],
|
||
warningCodes: [],
|
||
isPendingEpisode: true
|
||
}
|
||
],
|
||
pendingQualityEpisodeNos: [1]
|
||
})
|
||
)
|
||
mountPage([candidateCheckpoint(resourceConflictState({ projectId: 'breakdown-scroll-test' }))])
|
||
await flushPromises()
|
||
await wrapper!.get('.breakdown-desktop-issues').trigger('click')
|
||
await flushPromises()
|
||
const drawer = new DOMWrapper(document.querySelector('.breakdown-issues-drawer')!)
|
||
const panel = () => drawer.get('[aria-label="动作例外修订"]')
|
||
expect(panel().text()).toContain('左手握住铜铃')
|
||
await panel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '添加例外')!
|
||
.trigger('click')
|
||
await panel().get('textarea').setValue('剧本中的明确允许设定')
|
||
await panel()
|
||
.findAll('button')
|
||
.find(button => button.text() === '保存动作例外')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(
|
||
drawer
|
||
.findAll('button')
|
||
.find(button => button.text() === '关闭')!
|
||
.attributes('disabled')
|
||
).toBeDefined()
|
||
expect(save).toHaveBeenCalledOnce()
|
||
finish()
|
||
await flushPromises()
|
||
expect(drawer.text()).toContain('动作质量阻断')
|
||
expect(panel().text()).toContain('已有例外')
|
||
expect(
|
||
drawer
|
||
.findAll('button')
|
||
.find(button => button.text() === '关闭')!
|
||
.attributes('disabled')
|
||
).toBeUndefined()
|
||
Object.assign(getOperation('breakdown-scroll-test'), { error: '', notice: '', label: '' })
|
||
})
|
||
/** 跨组件后台任务观察器,验证结束时释放。 */
|
||
let taskScope: ReturnType<typeof effectScope> | undefined
|
||
afterEach(() => {
|
||
taskScope?.stop()
|
||
taskScope = undefined
|
||
wrapper?.unmount()
|
||
wrapper = undefined
|
||
document.body.innerHTML = ''
|
||
vi.unstubAllGlobals()
|
||
vi.restoreAllMocks()
|
||
localStorage.clear()
|
||
})
|
||
|
||
it.each(['pending', 'running'] as const)(
|
||
'已有 %s 拆解任务但尚无结果时恢复分类空状态,刷新后也不显示首次引导',
|
||
async status => {
|
||
mountPage([])
|
||
const record = {
|
||
id: `empty-result-${status}`,
|
||
projectId: 'breakdown-scroll-test',
|
||
workflowName: 'breakdown',
|
||
status: status as 'pending' | 'running' | 'completed',
|
||
stage: 'breakdown',
|
||
current: 0,
|
||
total: 0,
|
||
currentResourceId: null,
|
||
metadata: {},
|
||
result: null,
|
||
error: null,
|
||
startedAt: '2026-10-28T00:00:00Z',
|
||
completedAt: null,
|
||
createdAt: '2026-10-28T00:00:00Z',
|
||
updatedAt: '2026-10-28T00:01:00Z'
|
||
}
|
||
vi.spyOn(workflowExecutionApi, 'get').mockImplementation(async () => ({ ...record }))
|
||
taskScope = effectScope()
|
||
const tracker = taskScope.run(() => useWorkflowExecution(ref(record.projectId), 'breakdown'))!
|
||
await tracker.track(record.id)
|
||
await flushPromises()
|
||
try {
|
||
expect(wrapper!.find('.breakdown-initial-empty').exists()).toBe(false)
|
||
expect(wrapper!.get('.workspace-heading-scroll').isVisible()).toBe(true)
|
||
expect(wrapper!.find('.result-toolbar').exists()).toBe(true)
|
||
expect(wrapper!.text()).toContain('尚无主体结果')
|
||
await selectTab('分镜')
|
||
expect(wrapper!.text()).toContain('分镜规划尚未生成')
|
||
wrapper!.unmount()
|
||
wrapper = undefined
|
||
mountPage([])
|
||
await flushPromises()
|
||
expect(wrapper!.find('.breakdown-initial-empty').exists()).toBe(false)
|
||
expect(wrapper!.text()).toContain('尚无主体结果')
|
||
} finally {
|
||
record.status = 'completed'
|
||
record.updatedAt = '2026-10-28T00:02:00Z'
|
||
await tracker.query.refresh()
|
||
tracker.dismiss()
|
||
}
|
||
}
|
||
)
|
||
|
||
it('后台重新拆解时显示真实运行状态并隐藏所有诊断入口,终态后恢复', async () => {
|
||
vi.stubGlobal(
|
||
'fetch',
|
||
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
|
||
)
|
||
const provided = mountPage()
|
||
await selectTab('分镜')
|
||
const record = {
|
||
id: 'external-breakdown-ui',
|
||
projectId: 'breakdown-scroll-test',
|
||
workflowName: 'breakdown',
|
||
status: 'running' as 'running' | 'completed',
|
||
stage: 'storyboard_plan_ready',
|
||
current: 1,
|
||
total: 3,
|
||
currentResourceId: null,
|
||
metadata: { progressUnit: 'storyboard_episodes' },
|
||
result: null,
|
||
error: null,
|
||
startedAt: '2026-10-17T00:00:00Z',
|
||
completedAt: null,
|
||
createdAt: '2026-10-17T00:00:00Z',
|
||
updatedAt: '2026-10-17T00:01:00Z'
|
||
}
|
||
vi.spyOn(workflowExecutionApi, 'get').mockImplementation(async () => ({ ...record }))
|
||
taskScope = effectScope()
|
||
const tracker = taskScope.run(() => useWorkflowExecution(ref(record.projectId), 'breakdown'))!
|
||
await tracker.track(record.id)
|
||
await flushPromises()
|
||
expect(wrapper!.text()).toContain('拆解进行中')
|
||
expect(wrapper!.find('.storyboard-diagnosis-summary').exists()).toBe(false)
|
||
expect(wrapper!.find('.diagnose-hover-action').exists()).toBe(false)
|
||
record.status = 'completed'
|
||
await tracker.query.refresh()
|
||
await flushPromises()
|
||
expect(wrapper!.find('.storyboard-diagnosis-summary').exists()).toBe(true)
|
||
expect(provided.refresh).toHaveBeenCalled()
|
||
tracker.dismiss()
|
||
})
|
||
|
||
it('候选审核通过后只展示候选,修复后的正式结果不再被嵌套历史五个错误污染', async () => {
|
||
const old = Array.from({ length: 5 }, (_, index) => ({ episodeNo: 1, message: `历史错误 ${index}` }))
|
||
const current = candidateCheckpoint(
|
||
candidateState({
|
||
projectId: 'breakdown-scroll-test',
|
||
breakdownResult: { storyboardShotValidation: { valid: false, issues: old } }
|
||
})
|
||
)
|
||
const read = vi
|
||
.spyOn(breakdownApi, 'revalidateCandidate')
|
||
.mockResolvedValue(candidateReview({ projectId: 'breakdown-scroll-test', previousIssues: old }))
|
||
const provided = mountPage([current])
|
||
expect(wrapper!.text()).not.toContain('分镜校验未通过')
|
||
await flushPromises()
|
||
expect(wrapper!.text()).toContain('拆解候选 · 尚未提交正式结果')
|
||
expect(wrapper!.find('button.breakdown-desktop-issues').exists()).toBe(false)
|
||
expect(wrapper!.find('.subject-record-actions router-link-stub').exists()).toBe(false)
|
||
await selectTab('分镜')
|
||
expect(wrapper!.find('.storyboard-diagnosis-summary').exists()).toBe(false)
|
||
expect(read).toHaveBeenCalledTimes(1)
|
||
provided.data.value!.checkpoints = [
|
||
{ ...current, state: { ...current.state, storyboardPersisted: true, candidateCommitted: true } }
|
||
]
|
||
await selectTab('人物')
|
||
await flushPromises()
|
||
expect(wrapper!.text()).toContain('正式拆解结果')
|
||
expect(wrapper!.text()).toContain('已提交正式结果')
|
||
expect(wrapper!.text()).not.toContain('分镜校验未通过')
|
||
expect(read).toHaveBeenCalledTimes(1)
|
||
})
|
||
|
||
it('历史修复元数据不能掩盖之后新任务的真实失败', async () => {
|
||
const current = candidateCheckpoint(
|
||
candidateState({ projectId: 'breakdown-scroll-test', storyboardPersisted: true, candidateCommitted: true })
|
||
)
|
||
mountPage([current])
|
||
const record = {
|
||
id: 'new-failed-breakdown',
|
||
projectId: 'breakdown-scroll-test',
|
||
workflowName: 'breakdown',
|
||
status: 'failed' as const,
|
||
stage: 'failed',
|
||
current: 0,
|
||
total: 3,
|
||
currentResourceId: null,
|
||
metadata: null,
|
||
result: null,
|
||
error: '新任务执行失败',
|
||
startedAt: '2026-10-17T10:00:00Z',
|
||
completedAt: '2026-10-17T10:01:00Z',
|
||
createdAt: '2026-10-17T10:00:00Z',
|
||
updatedAt: '2026-10-17T10:01:00Z'
|
||
}
|
||
vi.spyOn(workflowExecutionApi, 'get').mockResolvedValue(record)
|
||
taskScope = effectScope()
|
||
const tracker = taskScope.run(() => useWorkflowExecution(ref(record.projectId), 'breakdown'))!
|
||
await tracker.track(record.id)
|
||
await flushPromises()
|
||
expect(wrapper!.text()).toContain('工作流失败')
|
||
expect(wrapper!.find('button.breakdown-desktop-issues').exists()).toBe(true)
|
||
tracker.dismiss()
|
||
})
|
||
|
||
/** 长主体、长分镜与长任务列表,用真实 Naive 滚动组件验证内容边界。 */
|
||
function checkpoint(): Checkpoint {
|
||
const plan: EpisodePlan = {
|
||
episodeNo: 1,
|
||
episodeTitle: '长剧集',
|
||
storyGoal: '',
|
||
centralConflict: '',
|
||
emotionalArc: '',
|
||
pacing: '',
|
||
endingHook: '',
|
||
beats: Array.from({ length: 25 }, (_, i) => ({
|
||
beatNo: i + 1,
|
||
title: `节拍 ${i + 1}`,
|
||
purpose: 'action',
|
||
description: '节拍内容'.repeat(100),
|
||
visualFocus: '',
|
||
narrativeGoal: '',
|
||
emotionalTone: '',
|
||
estimatedDurationSeconds: 5,
|
||
subjectRefs: [],
|
||
isKeyBeat: false
|
||
}))
|
||
}
|
||
return {
|
||
checkpointId: 'long-breakdown',
|
||
workflowName: 'breakdown',
|
||
createdAt: '2026-08-28T00:00:00Z',
|
||
state: {
|
||
workflowExecution: { executionId: 'run', status: 'completed', startedAt: '2026-08-28T00:00:00Z' },
|
||
breakdownResult: {
|
||
subjectCandidates: (['character', 'scene', 'prop'] as BreakdownModule[]).flatMap(module =>
|
||
Array.from({ length: 30 }, (_, i) => ({
|
||
profileId: `${module}-${i}`,
|
||
name: `${module} 主体 ${i + 1}`,
|
||
ref: `@${module}${i}`,
|
||
description: '很长的主体描述。'.repeat(100),
|
||
module,
|
||
appearance_prompt: '外观描述'
|
||
}))
|
||
),
|
||
subjectForms: [],
|
||
storyboardPlans: [plan],
|
||
storyboardEpisodeShots: [
|
||
{
|
||
episodeNo: 1,
|
||
episodePlan: plan,
|
||
beatShots: plan.beats.map(beat => ({
|
||
beatNo: beat.beatNo,
|
||
shots: [
|
||
{
|
||
shotNo: 1,
|
||
title: `镜头 ${beat.beatNo}`,
|
||
description: '镜头内容',
|
||
visualFocus: '',
|
||
subjectRefs: [],
|
||
durationSeconds: 5
|
||
}
|
||
]
|
||
}))
|
||
}
|
||
]
|
||
},
|
||
tasks: Array.from({ length: 50 }, (_, i) => ({
|
||
taskId: `task-${i}`,
|
||
module: 'character',
|
||
group: {
|
||
groupId: `group-${i}`,
|
||
groupNo: i + 1,
|
||
startEpisodeNo: i + 1,
|
||
endEpisodeNo: i + 1,
|
||
episodes: []
|
||
},
|
||
status: 'failed',
|
||
attempt: 1,
|
||
errorMessage: `任务错误 ${i + 1}`
|
||
}))
|
||
}
|
||
}
|
||
}
|
||
|
||
/** 提供响应式 checkpoint,模拟轮询更新但不连接后端或启动模型任务。 */
|
||
function mountPage(records = [checkpoint()], episodes = 1): ReturnType<typeof useProjectData> {
|
||
const project: ProjectDetail = {
|
||
id: 'breakdown-scroll-test',
|
||
title: '滚动回归',
|
||
topic: '',
|
||
style: '',
|
||
status: 'completed',
|
||
durationMode: 'auto',
|
||
episodeCount: 1,
|
||
targetDurationSeconds: null,
|
||
episodeMinSeconds: null,
|
||
episodeMaxSeconds: null,
|
||
createdAt: '',
|
||
updatedAt: '',
|
||
characters: [],
|
||
world: null,
|
||
|
||
episodes: episodes ? [{ episode: 1, targetDurationSeconds: null, title: '第一集', content: '正文' }] : []
|
||
}
|
||
const data = ref({
|
||
project,
|
||
checkpoints: records,
|
||
stageReadiness: {
|
||
projectId: project.id,
|
||
script: { ready: true, reason: null },
|
||
breakdown: { ready: true, reason: null },
|
||
preparation: { ready: true, reason: null },
|
||
visualStyle: { ready: true, reason: null },
|
||
identity: { ready: true, reason: null },
|
||
subjectAssets: { ready: true, reason: null },
|
||
storyboard: { ready: true, reason: null }
|
||
}
|
||
})
|
||
const provided: ReturnType<typeof useProjectData> = {
|
||
data,
|
||
project: computed(() => data.value.project),
|
||
checkpoints: computed(() => data.value.checkpoints),
|
||
stageReadiness: computed(() => data.value.stageReadiness),
|
||
loading: ref(false),
|
||
error: ref(''),
|
||
updatedAt: ref(''),
|
||
refresh: vi.fn<() => Promise<void>>().mockResolvedValue(),
|
||
refreshStageReadiness: vi.fn<() => Promise<void>>().mockResolvedValue()
|
||
}
|
||
wrapper = mount(BreakdownPage, {
|
||
attachTo: document.body,
|
||
global: { provide: { [projectContextKey as symbol]: provided }, stubs: { RouterLink: true } }
|
||
})
|
||
return provided
|
||
}
|
||
|
||
/** 切换真实标签,不直接修改组件内部状态。 */
|
||
async function selectTab(label: string) {
|
||
await wrapper!
|
||
.findAll('.result-toolbar .n-tabs-tab')
|
||
.find(tab => tab.text().startsWith(label))!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
}
|
||
|
||
/**
|
||
* 提供完整的空诊断记录,用于只验证分镜列表的用例隔离只读摘要请求。
|
||
* @returns 后端诊断结果响应
|
||
*/
|
||
function diagnosisResultsResponse() {
|
||
return new Response(
|
||
JSON.stringify({
|
||
data: {
|
||
projectId: 'breakdown-scroll-test',
|
||
episodeNo: 1,
|
||
counts: { total: 0, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 0, pending: 0 },
|
||
shots: []
|
||
}
|
||
}),
|
||
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 提供完整结构化校验响应,通过证据数量区分当前与迟到结果。
|
||
* @param evidenceShotCount 具有手部记录覆盖的镜头数量
|
||
* @returns 后端结构化校验响应
|
||
*/
|
||
function handDiagnosticsResponse(evidenceShotCount: number) {
|
||
return new Response(
|
||
JSON.stringify({
|
||
data: {
|
||
projectId: 'breakdown-scroll-test',
|
||
episodeCount: 1,
|
||
shotCount: 25,
|
||
validSnapshotCount: 25,
|
||
evidenceShotCount,
|
||
invalidEvidenceShotCount: 0,
|
||
missingEvidenceShotCount: 25 - evidenceShotCount,
|
||
evidenceCoverage: evidenceShotCount / 25,
|
||
assessment: evidenceShotCount ? 'complete_evidence' : 'insufficient_evidence',
|
||
warningCount: 0,
|
||
diagnostics: [],
|
||
willCallModel: false,
|
||
willModifyAssets: false
|
||
}
|
||
}),
|
||
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 从真实挂载的动作诊断弹窗读取内容,避免误取拆解设置弹窗。
|
||
* @returns 当前动作诊断弹窗
|
||
*/
|
||
function qualityDialog() {
|
||
const panel = document.querySelector<HTMLElement>('.app-drawer[aria-label="动作诊断"]')
|
||
if (!panel) throw new Error('动作诊断弹窗未打开')
|
||
return new DOMWrapper(panel)
|
||
}
|
||
|
||
describe('拆解页内容滚动', () => {
|
||
it('拆解设置保留输入标签、单行单位与模块说明,改版后仍校验模块和剧本状态', async () => {
|
||
const fetcher = vi.fn<typeof fetch>()
|
||
vi.stubGlobal('fetch', fetcher)
|
||
const provided = mountPage()
|
||
await wrapper!.get('[data-workspace-tools]').trigger('click')
|
||
await flushPromises()
|
||
const config = drawerPanel().get('.breakdown-config')
|
||
expect(config.get('label[for="group-size"]').text()).toContain('每组集数')
|
||
expect(config.get<HTMLInputElement>('#group-size').element.value).toBe('3')
|
||
expect(config.get('.breakdown-group-unit').text()).toBe('集 / 组')
|
||
expect(config.get('.breakdown-modules-field .n-form-item-label').text()).toContain('抽取模块')
|
||
const options = config.findAll('.breakdown-module-option')
|
||
expect(options).toHaveLength(3)
|
||
const preview = config.get<HTMLButtonElement>('.breakdown-preview-button')
|
||
expect(preview.element.disabled).toBe(false)
|
||
for (const option of options) {
|
||
const checkbox = option.get('[role="checkbox"]')
|
||
const description = option.get('.breakdown-module-description')
|
||
expect(checkbox.attributes('aria-describedby')).toBe(description.attributes('id'))
|
||
expect(checkbox.find('.breakdown-module-description').exists()).toBe(false)
|
||
expect(description.text()).not.toBe('')
|
||
await checkbox.trigger('click')
|
||
}
|
||
await preview.trigger('click')
|
||
await flushPromises()
|
||
expect(config.get('.n-form-item-feedback--error').text()).toContain('至少选择一个抽取模块')
|
||
expect(fetcher).not.toHaveBeenCalled()
|
||
await options[1]!.get('[role="checkbox"]').trigger('click')
|
||
expect(preview.element.disabled).toBe(false)
|
||
provided.data.value!.project.status = 'generating'
|
||
await flushPromises()
|
||
expect(preview.element.disabled).toBe(true)
|
||
expect(fetcher).not.toHaveBeenCalled()
|
||
})
|
||
|
||
it('拆解配置按抽屉宽度换行,单位不收缩,三类控件对齐且说明位于控件下方', () => {
|
||
// DOM 环境不计算坐标,检查统一标题偏移、34px 控件行和容器断点契约。
|
||
const css = readAllStyles()
|
||
expect(css).toMatch(/\.breakdown-settings-panel\s*\{\s*container:\s*breakdown-settings \/ inline-size;/)
|
||
expect(css).toMatch(/\.breakdown-config\s*\{[^}]*--breakdown-label-offset:\s*29px;/)
|
||
expect(css).toMatch(/\.breakdown-group-unit\s*\{[^}]*flex-shrink:\s*0;[^}]*white-space:\s*nowrap;/)
|
||
expect(css).toMatch(
|
||
/\.n-checkbox\.control-row-checkbox\s*\{[^}]*align-items:\s*center;[^}]*min-height:\s*34px;/
|
||
)
|
||
expect(css).toMatch(
|
||
/\.breakdown-preview-button\.n-button\s*\{[^}]*align-self:\s*start;[^}]*margin-top:\s*var\(--breakdown-label-offset\);/
|
||
)
|
||
expect(css).toContain('@container breakdown-settings (max-width: 780px)')
|
||
expect(css).toContain('@container breakdown-settings (max-width: 560px)')
|
||
expect(css).toContain('repeat(auto-fit, minmax(min(100%, 160px), 1fr))')
|
||
expect(readFileSync('src/styles/styles.css', 'utf8')).not.toContain('.breakdown-config')
|
||
})
|
||
|
||
it.each(['人物', '场景', '道具'])('%s 使用共用固定斑马纹样式,搜索后保持列表条目结构', async label => {
|
||
mountPage()
|
||
await selectTab(label)
|
||
expect(wrapper!.find('.history-panel').exists()).toBe(false)
|
||
const list = wrapper!.get('.subject-record-list')
|
||
expect(list.classes()).toContain('record-list')
|
||
expect(list.findAll(':scope > article')).toHaveLength(30)
|
||
const toolbar = wrapper!.get('.subject-list-toolbar')
|
||
const exportButton = wrapper!.get<HTMLButtonElement>(
|
||
'.result-toolbar .n-tabs-nav__suffix [aria-label="导出拆解结果"]'
|
||
)
|
||
expect(exportButton.element.disabled).toBe(false)
|
||
expect(exportButton.text()).toBe('')
|
||
expect(exportButton.get('svg').attributes('width')).toBe('18')
|
||
expect(toolbar.element.firstElementChild).toBe(toolbar.get('.subject-list-search').element)
|
||
expect(toolbar.element.lastElementChild).toBe(toolbar.get('.subject-list-count').element)
|
||
expect(toolbar.get('.n-input__prefix svg').attributes('aria-hidden')).toBe('true')
|
||
expect(toolbar.find(':scope > svg').exists()).toBe(false)
|
||
expect(toolbar.get('[role="status"]').text()).toBe('共 30 个主体')
|
||
const input = toolbar.get('input[aria-label="搜索主体"]')
|
||
await input.setValue('主体 30')
|
||
expect(list.findAll(':scope > article')).toHaveLength(1)
|
||
expect(list.get(':scope > article h3').text()).toContain('主体 30')
|
||
expect(toolbar.get('[role="status"]').text()).toBe('匹配 1 / 30 个主体')
|
||
await input.setValue('不存在的主体')
|
||
expect(toolbar.get('[role="status"]').text()).toBe('匹配 0 / 30 个主体')
|
||
expect(wrapper!.text()).toContain('没有匹配的主体')
|
||
expect(wrapper!.find('.breakdown-initial-empty').exists()).toBe(false)
|
||
await input.setValue('')
|
||
expect(toolbar.get('[role="status"]').text()).toBe('共 30 个主体')
|
||
expect(wrapper!.findAll('.subject-record-list > article')).toHaveLength(30)
|
||
})
|
||
|
||
it('主体搜索与统计靠左居中,窄屏搜索拉满同一行,输入框不再使用外置图标容器', () => {
|
||
// DOM 环境不计算布局,保护输入框宽度、主题统计色与窄屏单行搜索的样式契约。
|
||
const css = readAllStyles()
|
||
expect(css).toMatch(
|
||
/\.subject-list-toolbar\s*\{[^}]*display:\s*flex;[^}]*flex-wrap:\s*wrap;[^}]*align-items:\s*center;[^}]*justify-content:\s*flex-start;/
|
||
)
|
||
expect(css).toMatch(
|
||
/\.subject-list-search\.n-input\s*\{[^}]*flex:\s*0 1 260px;[^}]*min-width:\s*0;[^}]*max-width:\s*100%;/
|
||
)
|
||
expect(css).toMatch(/\.subject-list-count\s*\{[^}]*color:\s*var\(--app-muted\);/)
|
||
expect(css).toMatch(/@media \(max-width: 800px\)[\s\S]*?\.subject-list-search\.n-input\s*\{[^}]*flex:\s*1/)
|
||
expect(css + readFileSync('src/styles/styles.css', 'utf8')).not.toContain('.search-field')
|
||
})
|
||
|
||
it('窄屏收口拆解顶栏并隐藏重复标题,设置按钮保留图标', () => {
|
||
const css = readAllStyles()
|
||
expect(css).toMatch(/@media \(max-width: 800px\)[\s\S]*?\.workspace-toolbar h2\s*\{[^}]*display:\s*none/)
|
||
expect(css).toMatch(/@media \(max-width: 800px\)[\s\S]*?\.workspace-tools-label\s*\{[^}]*display:\s*none/)
|
||
expect(css).toMatch(
|
||
/@media \(max-width: 800px\)[\s\S]*?\.workspace-tools-trigger\s*\{[^}]*height:\s*32px;[^}]*width:\s*32px/
|
||
)
|
||
})
|
||
|
||
it.each([
|
||
['人物', 'character'],
|
||
['场景', 'scene'],
|
||
['道具', 'prop']
|
||
] as const)('%s 的奇偶主体默认收起形态块,展开和搜索不影响形态归属', async (label, module) => {
|
||
const record = checkpoint()
|
||
// 前两个主体各准备两种形态,覆盖奇偶条纹和默认标签,不调用模型接口。
|
||
record.state.breakdownResult!.subjectForms = [0, 1].flatMap(subjectIndex =>
|
||
[0, 1].map(formIndex => ({
|
||
formId: `${module}-${subjectIndex}-form-${formIndex}`,
|
||
profileId: `${module}-${subjectIndex}`,
|
||
type: module,
|
||
name: `主体 ${subjectIndex + 1} 形态 ${formIndex + 1}`,
|
||
isDefault: formIndex === 0,
|
||
description: '形态描述',
|
||
appearancePrompt: '形态提示词'
|
||
}))
|
||
)
|
||
mountPage([record])
|
||
await selectTab(label)
|
||
const articles = wrapper!.findAll('.subject-record-list > article')
|
||
for (const index of [0, 1]) {
|
||
const article = articles[index]!
|
||
expect(article.findAll('.subject-form-card')).toHaveLength(0)
|
||
await article.get('.n-collapse-item__header-main').trigger('click')
|
||
await flushPromises()
|
||
const cards = article.findAll('.subject-form-card')
|
||
expect(cards).toHaveLength(2)
|
||
expect(cards[0]!.get('.n-tag').text()).toBe('默认')
|
||
for (const card of cards) {
|
||
expect(card.classes()).not.toContain('surface-inset')
|
||
expect(card.text()).toContain(`主体 ${index + 1} 形态`)
|
||
expect(card.text()).toContain('形态描述')
|
||
expect(card.text()).toContain('形态提示词')
|
||
}
|
||
}
|
||
// 原偶数主体过滤后成为首项,仍由当前 DOM 的奇偶选择器决定内外层底色。
|
||
await wrapper!.get('input[aria-label="搜索主体"]').setValue(`@${module}1`)
|
||
const first = wrapper!.get('.subject-record-list > article')
|
||
expect(first.findAll('.subject-form-card')).toHaveLength(2)
|
||
expect(first.get('.subject-form-card').text()).toContain('主体 2 形态 1')
|
||
})
|
||
|
||
it('形态块在两种主体条纹上采用相反灰阶,以间距分组且没有整块悬停态', () => {
|
||
// DOM 环境不提供真实主题绘制,检查奇偶行底色、内边距和状态选择器契约。
|
||
const css = readAllStyles()
|
||
expect(css).toMatch(
|
||
/\.subject-form-card\s*\{[^}]*margin-top:\s*12px;[^}]*padding:\s*16px;[^}]*background:\s*var\(--app-subtle\);/
|
||
)
|
||
expect(css).toMatch(
|
||
/\.subject-record-list > article:nth-child\(even\) \.subject-form-card\s*\{\s*background:\s*var\(--app-control\);/
|
||
)
|
||
expect(css).not.toMatch(/\.subject-form-card[^{}]*(?::hover|:focus-within)/)
|
||
})
|
||
|
||
it('主体奇数行常驻原悬停底色,偶数行不变,整行不再随鼠标或焦点变色', () => {
|
||
// DOM 环境无法模拟浏览器 :hover 命中;检查静态底色与无整行交互选择器的契约。
|
||
const css = readAllStyles()
|
||
expect(css).toMatch(/\.record-list > article:nth-child\(even\)\s*\{\s*background:\s*var\(--app-subtle\);/)
|
||
expect(css).toMatch(
|
||
/\.subject-record-list > article:nth-child\(odd\)\s*\{\s*background:\s*var\(--app-control\);/
|
||
)
|
||
expect(css + readFileSync('src/styles/admin.css', 'utf8')).not.toMatch(
|
||
/\.subject-record-list[^{}]*(?::hover|:focus-within)/
|
||
)
|
||
// 仅移除整行变色,不影响内部链接、折叠等控件的键盘焦点提示。
|
||
expect(css).toMatch(/:focus-visible\s*\{[^}]*outline:\s*2px solid var\(--color-accent\);/)
|
||
})
|
||
|
||
it('分镜选择与计数同排且没有阶段快捷入口,切换后内容和统计同步', async () => {
|
||
vi.stubGlobal(
|
||
'fetch',
|
||
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
|
||
)
|
||
const record = checkpoint()
|
||
const result = record.state.breakdownResult!
|
||
const first = result.storyboardPlans![0]!
|
||
const second = { ...first, episodeNo: 2, episodeTitle: '第二集', beats: first.beats.slice(0, 2) }
|
||
result.storyboardPlans!.push(second)
|
||
result.storyboardEpisodeShots!.push({
|
||
episodeNo: 2,
|
||
episodePlan: second,
|
||
beatShots: result.storyboardEpisodeShots![0]!.beatShots.slice(0, 2)
|
||
})
|
||
const provided = mountPage([record])
|
||
await selectTab('分镜')
|
||
const toolbar = wrapper!.get('.breakdown-storyboard-toolbar')
|
||
expect(toolbar.find('.breakdown-episode-picker > span').exists()).toBe(false)
|
||
const select = toolbar.getComponent(NSelect)
|
||
expect(select.attributes('aria-label')).toBe('选择分镜剧集')
|
||
expect(select.props('value')).toBe(1)
|
||
expect(toolbar.text()).toContain('长剧集')
|
||
expect(toolbar.get('.breakdown-storyboard-summary').text()).toContain('25 个节拍 · 25 个镜头')
|
||
expect(toolbar.find('router-link-stub').exists()).toBe(false)
|
||
expect(wrapper!.find('.breakdown-storyboard > .surface-inset').exists()).toBe(false)
|
||
select.vm.$emit('update:value', 2)
|
||
await flushPromises()
|
||
expect(select.props('value')).toBe(2)
|
||
expect(toolbar.text()).toContain('第二集')
|
||
expect(toolbar.get('.breakdown-storyboard-summary').text()).toContain('2 个节拍 · 2 个镜头')
|
||
expect(wrapper!.findAll('.beat-section')).toHaveLength(2)
|
||
// 轮询删除当前选项时,输入框与正文一起回到仍存在的第一集。
|
||
provided.data.value!.checkpoints = [checkpoint()]
|
||
await flushPromises()
|
||
expect(select.props('value')).toBe(1)
|
||
expect(wrapper!.findAll('.beat-section')).toHaveLength(25)
|
||
})
|
||
|
||
it('分镜为空时仅保留空提示,不显示空选择器或阶段快捷入口', async () => {
|
||
const record = checkpoint()
|
||
record.state.breakdownResult!.storyboardPlans = []
|
||
record.state.breakdownResult!.storyboardEpisodeShots = []
|
||
mountPage([record])
|
||
await selectTab('分镜')
|
||
expect(wrapper!.get('.breakdown-storyboard').text()).toContain('分镜规划尚未生成')
|
||
expect(wrapper!.find('.breakdown-episode-picker').exists()).toBe(false)
|
||
expect(wrapper!.find('.breakdown-storyboard-toolbar').exists()).toBe(false)
|
||
expect(wrapper!.find('.breakdown-storyboard router-link-stub').exists()).toBe(false)
|
||
})
|
||
|
||
it('分镜顶部无叠加操作行,下拉框可收缩且统计操作垂直居中', () => {
|
||
// 仅保护样式契约,DOM 环境不提供真实布局坐标。
|
||
const css = readAllStyles()
|
||
expect(css).toMatch(/\.breakdown-result-pad\s*\{[^}]*padding:\s*0(?:px)?/)
|
||
expect(css).toMatch(/\.breakdown-episode-picker\s*\{[^}]*min-width:\s*0(?:px)?;/)
|
||
expect(css).toMatch(/\.breakdown-storyboard-summary\s*\{[^}]*align-items:\s*center;/)
|
||
})
|
||
|
||
it.each([
|
||
['人物', 'character 主体 30'],
|
||
['场景', 'scene 主体 30'],
|
||
['道具', 'prop 主体 30'],
|
||
['分镜', '镜头 25'],
|
||
['任务明细', '任务错误 50']
|
||
])('%s 的末项始终放在独立结果滚动容器内', async (label, lastItem) => {
|
||
if (label === '分镜')
|
||
vi.stubGlobal(
|
||
'fetch',
|
||
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
|
||
)
|
||
mountPage()
|
||
await selectTab(label)
|
||
expect(wrapper!.find('.workspace-scroll').exists()).toBe(false)
|
||
const results = wrapper!.get('.breakdown-results-scroll .n-scrollbar-container')
|
||
expect(results.text()).toContain(lastItem)
|
||
expect(results.find('.result-toolbar').exists()).toBe(false)
|
||
expect(results.find('.history-panel').exists()).toBe(false)
|
||
expect(wrapper!.find('.history-panel').exists()).toBe(false)
|
||
expect(wrapper!.get('[data-workspace-tools]').attributes('aria-expanded')).toBe('false')
|
||
expect(results.find('.table-scroll').exists()).toBe(label === '任务明细')
|
||
})
|
||
|
||
it('刷新和开关配置保留阅读位置,切换标签只重置结果区', async () => {
|
||
const fetcher = vi.fn<typeof fetch>()
|
||
vi.stubGlobal('fetch', fetcher)
|
||
const provided = mountPage()
|
||
const results = wrapper!.get<HTMLElement>('.breakdown-results-scroll .n-scrollbar-container').element
|
||
results.scrollTop = 900
|
||
await wrapper!.get('[data-workspace-tools]').trigger('click')
|
||
await flushPromises()
|
||
expect(drawerPanel().element.closest('.workspace-split')).toBeNull()
|
||
await drawerPanel().get('#group-size').setValue('2')
|
||
await drawerPanel().get('.n-drawer-header__close').trigger('click')
|
||
provided.data.value!.checkpoints = [checkpoint()]
|
||
await flushPromises()
|
||
expect(wrapper!.get('.breakdown-results-scroll .n-scrollbar-container').element).toBe(results)
|
||
expect(results.scrollTop).toBe(900)
|
||
await selectTab('场景')
|
||
const next = wrapper!.get<HTMLElement>('.breakdown-results-scroll .n-scrollbar-container').element
|
||
expect(next).not.toBe(results)
|
||
expect(next.scrollTop).toBe(0)
|
||
expect(wrapper!.find('.history-panel').exists()).toBe(false)
|
||
await wrapper!.get('[data-workspace-tools]').trigger('click')
|
||
await flushPromises()
|
||
expect(drawerPanel().get<HTMLInputElement>('#group-size').element.value).toBe('2')
|
||
expect(fetcher).not.toHaveBeenCalled()
|
||
})
|
||
|
||
it('问题窗口集中查看、修订和恢复,拆解设置只保留生成与候选流程', async () => {
|
||
const record = checkpoint()
|
||
record.state.workflowExecution!.status = 'failed'
|
||
record.state.workflowExecution!.errorMessage = '工作流中断'
|
||
record.state.breakdownResult!.storyboardShotValidation = {
|
||
valid: false,
|
||
issues: [{ episodeNo: 1, message: '缺少形态绑定' }]
|
||
}
|
||
mountPage([record])
|
||
expect(wrapper!.find('.workspace-feedback').exists()).toBe(false)
|
||
expect(wrapper!.text()).not.toContain('缺少形态绑定')
|
||
const action = wrapper!.get('button.breakdown-desktop-issues')
|
||
await action.trigger('click')
|
||
await flushPromises()
|
||
const issues = document.querySelector<HTMLElement>('.app-drawer[aria-label="拆解问题"]')
|
||
expect(issues?.textContent).toContain('缺少形态绑定')
|
||
expect(issues?.textContent).toContain('工作流中断')
|
||
expect(issues?.textContent).toContain('重试失败抽取')
|
||
expect(issues?.textContent).toContain('读取修复清单')
|
||
expect(issues?.textContent).not.toContain('预览分组')
|
||
expect(issues?.textContent).not.toContain('提交候选为正式结果')
|
||
await new DOMWrapper(issues!).get('.n-drawer-header__close').trigger('click')
|
||
await flushPromises()
|
||
await wrapper!.get('[data-workspace-tools]').trigger('click')
|
||
await flushPromises()
|
||
expect(drawerPanel().text()).not.toContain('缺少形态绑定')
|
||
expect(drawerPanel().text()).not.toContain('工作流中断')
|
||
expect(drawerPanel().text()).toContain('预览分组')
|
||
expect(drawerPanel().text()).not.toContain('查看问题')
|
||
expect(drawerPanel().text()).not.toContain('重试失败抽取')
|
||
expect(drawerPanel().text()).not.toContain('读取修复清单')
|
||
})
|
||
|
||
it('问题窗口在任务执行期间仅可查看,修订与恢复继续受活动锁保护', async () => {
|
||
const record = checkpoint()
|
||
record.state.workflowExecution!.status = 'running'
|
||
record.state.breakdownResult!.storyboardShotValidation = {
|
||
valid: false,
|
||
issues: [{ episodeNo: 1, message: '待修复问题' }]
|
||
}
|
||
mountPage([record])
|
||
await wrapper!.get('button.breakdown-desktop-issues').trigger('click')
|
||
await flushPromises()
|
||
const issues = new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer[aria-label="拆解问题"]')!)
|
||
expect(issues.text()).toContain('待修复问题')
|
||
for (const label of ['读取修复清单', '重试失败抽取', '继续整理镜头', '修复分镜绑定']) {
|
||
const action = issues.findAll('button').find(button => button.text() === label)!
|
||
expect((action.element as HTMLButtonElement).disabled).toBe(true)
|
||
}
|
||
})
|
||
|
||
it('质量待审核但没有结构错误时仍可进入问题窗口读取修复清单', async () => {
|
||
const record = checkpoint()
|
||
record.state.storyboardPendingQualityEpisodeNos = [1]
|
||
record.state.breakdownResult!.storyboardShotValidation = { valid: true, issues: [] }
|
||
mountPage([record])
|
||
await wrapper!.get('button.breakdown-desktop-issues').trigger('click')
|
||
await flushPromises()
|
||
const issues = document.querySelector<HTMLElement>('.app-drawer[aria-label="拆解问题"]')
|
||
expect(issues?.textContent).toContain('读取修复清单')
|
||
})
|
||
|
||
it('诊断摘要与弹窗按需读取,保留通用检查但不展示旧手部统计', async () => {
|
||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
|
||
const url = String(input)
|
||
if (url.includes('storyboard-legacy-action-diagnosis-results')) return diagnosisResultsResponse()
|
||
if (url.endsWith('storyboard-action-resource-diagnostics')) return handDiagnosticsResponse(0)
|
||
throw new Error(`未预期的诊断请求:${url}`)
|
||
})
|
||
vi.stubGlobal('fetch', fetcher)
|
||
mountPage()
|
||
expect(fetcher).not.toHaveBeenCalled()
|
||
await selectTab('分镜')
|
||
expect(fetcher).toHaveBeenCalledTimes(1)
|
||
expect(String(fetcher.mock.calls[0]?.[0])).toContain('diagnosis-results?episodeNo=1')
|
||
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
|
||
await flushPromises()
|
||
const panel = qualityDialog()
|
||
expect(panel.findAll('button').some(button => button.text() === '刷新校验')).toBe(false)
|
||
expect(panel.get('.storyboard-diagnosis-dialog').attributes('aria-busy')).toBe('false')
|
||
const footer = panel.get('.n-drawer-footer')
|
||
expect(footer.text()).toContain('预览诊断范围')
|
||
expect(footer.text()).toContain('启动 AI 复查')
|
||
expect(footer.text()).toContain('关闭')
|
||
await panel.get('.n-collapse-item__header-main').trigger('click')
|
||
await flushPromises()
|
||
expect(panel.text()).not.toContain('手部记录覆盖')
|
||
expect(panel.text()).toContain('未填写记录不代表镜头有误')
|
||
expect(panel.get('.n-collapse-item__header-extra button').text()).toBe('刷新校验')
|
||
await panel.get('.n-collapse-item__header-main').trigger('click')
|
||
await flushPromises()
|
||
expect(panel.findAll('button').some(button => button.text() === '刷新校验')).toBe(false)
|
||
expect(
|
||
fetcher.mock.calls.filter(([input]) => String(input).endsWith('storyboard-action-resource-diagnostics'))
|
||
).toHaveLength(1)
|
||
})
|
||
|
||
it('刷新已加载的诊断结果只显示按钮加载,保留正文节点、折叠展开和滚动位置', async () => {
|
||
let resultRequests = 0
|
||
let resolveRefresh: ((value: Response) => void) | undefined
|
||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
|
||
const url = String(input)
|
||
if (url.includes('storyboard-legacy-action-diagnosis-results')) {
|
||
resultRequests++
|
||
if (resultRequests > 2)
|
||
return new Promise<Response>(resolve => {
|
||
resolveRefresh = resolve
|
||
})
|
||
return diagnosisResultsResponse()
|
||
}
|
||
if (url.endsWith('storyboard-action-resource-diagnostics')) return handDiagnosticsResponse(0)
|
||
throw new Error(`未预期的诊断请求:${url}`)
|
||
})
|
||
vi.stubGlobal('fetch', fetcher)
|
||
mountPage()
|
||
await selectTab('分镜')
|
||
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
|
||
await flushPromises()
|
||
const panel = qualityDialog()
|
||
await panel.findAll('.n-collapse-item__header-main')[1]!.trigger('click')
|
||
await flushPromises()
|
||
const content = panel.get('.diagnosis-dialog-content').element
|
||
const scroll = panel.get<HTMLElement>('.n-drawer-body .n-scrollbar-container').element
|
||
scroll.scrollTop = 80
|
||
const refreshButton = panel.findAll('button').find(button => button.text() === '刷新结果')!
|
||
const refreshIcon = refreshButton.get('.n-button__icon').element
|
||
await refreshButton.trigger('click')
|
||
await flushPromises()
|
||
try {
|
||
const spin = wrapper!
|
||
.findAllComponents(NSpin)
|
||
.find(item => item.classes().includes('storyboard-diagnosis-dialog'))!
|
||
expect(spin.props('show')).toBe(false)
|
||
expect(refreshButton.classes()).toContain('n-button--loading')
|
||
expect(refreshButton.get('.n-button__icon').element).toBe(refreshIcon)
|
||
expect(panel.get('.diagnosis-dialog-content').element).toBe(content)
|
||
expect(panel.find('.diagnosis-concurrency').isVisible()).toBe(true)
|
||
expect(scroll.scrollTop).toBe(80)
|
||
expect(panel.text()).toContain('当前范围尚无镜头')
|
||
} finally {
|
||
resolveRefresh!(diagnosisResultsResponse())
|
||
await flushPromises()
|
||
}
|
||
expect(refreshButton.classes()).not.toContain('n-button--loading')
|
||
expect(panel.get('.diagnosis-dialog-content').element).toBe(content)
|
||
})
|
||
|
||
it('刷新通用动作检查保留高级摘要和图标占位,不触发整窗遮罩', async () => {
|
||
let handRequests = 0
|
||
let resolveRefresh: ((value: Response) => void) | undefined
|
||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
|
||
const url = String(input)
|
||
if (url.includes('storyboard-legacy-action-diagnosis-results')) return diagnosisResultsResponse()
|
||
if (url.endsWith('storyboard-action-resource-diagnostics')) {
|
||
handRequests++
|
||
if (handRequests > 1)
|
||
return new Promise<Response>(resolve => {
|
||
resolveRefresh = resolve
|
||
})
|
||
return handDiagnosticsResponse(0)
|
||
}
|
||
throw new Error(`未预期的诊断请求:${url}`)
|
||
})
|
||
vi.stubGlobal('fetch', fetcher)
|
||
mountPage()
|
||
await selectTab('分镜')
|
||
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
|
||
await flushPromises()
|
||
const panel = qualityDialog()
|
||
await panel.get('.n-collapse-item__header-main').trigger('click')
|
||
await flushPromises()
|
||
const evidence = panel.get('.diagnosis-inspection-details').element
|
||
const refreshButton = panel.findAll('button').find(button => button.text() === '刷新校验')!
|
||
const refreshIcon = refreshButton.find('.n-button__icon')
|
||
await refreshButton.trigger('click')
|
||
await flushPromises()
|
||
try {
|
||
expect(panel.text()).not.toContain('手部记录覆盖')
|
||
expect(panel.get('.diagnosis-inspection-details').element).toBe(evidence)
|
||
const spin = wrapper!
|
||
.findAllComponents(NSpin)
|
||
.find(item => item.classes().includes('storyboard-diagnosis-dialog'))!
|
||
expect(spin.props('show')).toBe(false)
|
||
expect(refreshButton.classes()).toContain('n-button--loading')
|
||
expect(refreshIcon.exists()).toBe(true)
|
||
expect(refreshButton.get('.n-button__icon').element).toBe(refreshIcon.element)
|
||
} finally {
|
||
resolveRefresh!(handDiagnosticsResponse(0))
|
||
await flushPromises()
|
||
}
|
||
expect(refreshButton.classes()).not.toContain('n-button--loading')
|
||
expect(panel.get('.diagnosis-inspection-details').element).toBe(evidence)
|
||
expect(panel.get('.n-collapse-item__header-extra button').element).toBe(refreshButton.element)
|
||
})
|
||
|
||
it('打开诊断弹窗时展示加载态,关闭后的迟到校验响应不污染新状态', async () => {
|
||
let resolveFirst: ((value: Response) => void) | undefined
|
||
let handRequests = 0
|
||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
|
||
const url = String(input)
|
||
if (url.includes('storyboard-legacy-action-diagnosis-results')) return diagnosisResultsResponse()
|
||
if (url.endsWith('storyboard-action-resource-diagnostics')) {
|
||
handRequests++
|
||
if (handRequests === 1)
|
||
return new Promise<Response>(resolve => {
|
||
resolveFirst = resolve
|
||
})
|
||
return handDiagnosticsResponse(0)
|
||
}
|
||
throw new Error(`未预期的诊断请求:${url}`)
|
||
})
|
||
vi.stubGlobal('fetch', fetcher)
|
||
mountPage()
|
||
await selectTab('分镜')
|
||
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
|
||
await flushPromises()
|
||
expect(handRequests).toBe(1)
|
||
expect(qualityDialog().get('.storyboard-diagnosis-dialog').attributes('aria-busy')).toBe('true')
|
||
expect(qualityDialog().text()).not.toContain('诊断结果')
|
||
expect(
|
||
qualityDialog()
|
||
.get('.n-drawer-footer')
|
||
.findAll('button')
|
||
.filter(button => button.text() !== '关闭')
|
||
.every(button => (button.element as HTMLButtonElement).disabled)
|
||
).toBe(true)
|
||
const close = qualityDialog()
|
||
.get('.n-drawer-footer')
|
||
.findAll('button')
|
||
.find(button => button.text() === '关闭')!
|
||
expect((close.element as HTMLButtonElement).disabled).toBe(false)
|
||
await close.trigger('click')
|
||
await flushPromises()
|
||
const late = await handDiagnosticsResponse(25).json()
|
||
late.data.warningCount = 1
|
||
late.data.diagnostics = [
|
||
{
|
||
episodeNo: 1,
|
||
beatNo: 1,
|
||
shotNo: 1,
|
||
phaseNo: 1,
|
||
characterRef: '@CH0001',
|
||
actionIds: ['a1', 'a2'],
|
||
code: 'hand_occupancy_conflict',
|
||
severity: 'warning',
|
||
suggestion: '已失效的动作检查问题'
|
||
}
|
||
]
|
||
resolveFirst!(
|
||
new Response(JSON.stringify(late), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
||
)
|
||
await flushPromises()
|
||
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
|
||
await flushPromises()
|
||
const panel = qualityDialog()
|
||
expect(panel.get('.storyboard-diagnosis-dialog').attributes('aria-busy')).toBe('false')
|
||
await panel.get('.n-collapse-item__header-main').trigger('click')
|
||
await flushPromises()
|
||
expect(panel.text()).not.toContain('已失效的动作检查问题')
|
||
expect(panel.text()).not.toContain('手部记录覆盖')
|
||
expect(handRequests).toBe(2)
|
||
})
|
||
|
||
it('没有正式剧集时保留可滚动的空状态,不显示拆解设置与结果', () => {
|
||
mountPage([], 0)
|
||
expect(wrapper!.get('.panel-scroll .n-scrollbar-container').text()).toContain('还没有可拆解的剧集')
|
||
expect(wrapper!.find('.breakdown-results-section').exists()).toBe(false)
|
||
expect(wrapper!.find('[data-workspace-tools]').exists()).toBe(false)
|
||
})
|
||
})
|