fix(short-drama-agent-front): 优化拆解引导与质量规则配置
This commit is contained in:
1 parent
c6ef595a8e
commit
2db8549818
13 files changed
+626
-225
No files matched your search
@@ -2,7 +2,7 @@ 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 { NSelect, NSpin } from 'naive-ui'
|
||||
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'
|
||||
@@ -27,6 +27,32 @@ import { getOperation } from '@/features/workflows/operations'
|
||||
|
||||
let wrapper: VueWrapper | undefined
|
||||
|
||||
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', {
|
||||
@@ -233,6 +259,54 @@ afterEach(() => {
|
||||
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',
|
||||
@@ -594,6 +668,12 @@ describe('拆解页内容滚动', () => {
|
||||
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')
|
||||
@@ -607,6 +687,7 @@ describe('拆解页内容滚动', () => {
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { NTabs } from 'naive-ui'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import ProjectSettingsDialog from '@/features/generation-config/components/ProjectSettingsDialog.vue'
|
||||
import { projectsApi } from '@/features/projects/api'
|
||||
import { policyReceipt } from '../../fixtures/quality-policy'
|
||||
|
||||
/** 当前全屏配置抽屉。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
describe('配置入口定位到指定分类', () => {
|
||||
it('规则入口直接显示质量规则,关闭后从普通入口重开回到生成配置', async () => {
|
||||
const save = vi.spyOn(projectsApi, 'saveQualityPolicy')
|
||||
const confirm = vi.spyOn(projectsApi, 'confirmQualityPolicy')
|
||||
vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue(
|
||||
policyReceipt('settings-quality', {
|
||||
version: 1,
|
||||
physicsMode: 'realistic',
|
||||
allowExaggeratedMotion: false,
|
||||
allowNonPhysicalActions: false,
|
||||
allowSupernaturalAbilities: false,
|
||||
customRules: []
|
||||
})
|
||||
)
|
||||
wrapper = mount(ProjectSettingsDialog, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: 'settings-quality', disabled: false, open: true, initialTab: 'quality' },
|
||||
global: { stubs: { CreativeProfileSettings: true } }
|
||||
})
|
||||
await flushPromises()
|
||||
expect(wrapper.getComponent(NTabs).props('value')).toBe('quality')
|
||||
expect(wrapper.findComponent({ name: 'QualityPolicySettings' }).exists()).toBe(true)
|
||||
expect(save).not.toHaveBeenCalled()
|
||||
expect(confirm).not.toHaveBeenCalled()
|
||||
await wrapper.setProps({ open: false })
|
||||
await wrapper.setProps({ open: true, initialTab: 'generation' })
|
||||
await flushPromises()
|
||||
expect(wrapper.getComponent(NTabs).props('value')).toBe('generation')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,112 @@
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import StoryboardPreparation from '@/features/storyboard-preparation/StoryboardPreparation.vue'
|
||||
import AppDrawer from '@/components/ui/AppDrawer.vue'
|
||||
import { preparationApi } from '@/features/storyboard-preparation/api'
|
||||
import { projectsApi } from '@/features/projects/api'
|
||||
import { projectSettingsOpenKey } from '@/features/generation-config/context'
|
||||
import { preparationFixture } from './fixtures'
|
||||
|
||||
/** 当前挂载的检查入口,不连接模型或数据库写入。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
/**
|
||||
* 用实际响应结构打开首次拆解前的制作检查。
|
||||
* @param id 隔离项目编号
|
||||
* @returns 已打开抽屉、接口样例及配置入口
|
||||
*/
|
||||
async function openPreparation(id: string) {
|
||||
const data = preparationFixture(id)
|
||||
data.policy.confirmed = false
|
||||
data.policy.confirmedRevision = null
|
||||
data.policy.confirmedAt = null
|
||||
data.quality.coverage.shotCount = 0
|
||||
data.entry.derivedAssets.shotCount = 0
|
||||
vi.spyOn(preparationApi, 'recheck').mockImplementation(async () => structuredClone(data.quality))
|
||||
vi.spyOn(preparationApi, 'approval').mockImplementation(async () => structuredClone(data.approval))
|
||||
vi.spyOn(preparationApi, 'baseline').mockImplementation(async () => structuredClone(data.baseline))
|
||||
vi.spyOn(preparationApi, 'entry').mockImplementation(async () => structuredClone(data.entry))
|
||||
vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(async () => structuredClone(data.policy))
|
||||
const openSettings = vi.fn<(tab?: string) => void>()
|
||||
wrapper = mount(StoryboardPreparation, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: id },
|
||||
global: { provide: { [projectSettingsOpenKey as symbol]: openSettings } }
|
||||
})
|
||||
await wrapper.get('button[aria-label="制作前检查"]').trigger('click')
|
||||
await flushPromises()
|
||||
return { data, openSettings, drawer: new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer')!) }
|
||||
}
|
||||
|
||||
describe('制作检查与项目配置职责分离', () => {
|
||||
it('尚无正式分镜时说明后续步骤,只读核对规则,不再重复完整编辑表单', async () => {
|
||||
const { drawer } = await openPreparation('preparation-empty-first')
|
||||
expect(drawer.text()).toContain('尚无正式分镜')
|
||||
expect(drawer.find('.quality-policy-settings').exists()).toBe(false)
|
||||
expect(drawer.text()).not.toContain('人工确认整体分镜')
|
||||
expect(drawer.text()).toContain('风格化表现')
|
||||
expect(drawer.text()).toContain('前往项目质量规则')
|
||||
})
|
||||
it('前往质量配置先关闭检查抽屉,离场后才打开同项目的质量规则标签', async () => {
|
||||
const { drawer, openSettings } = await openPreparation('preparation-settings-handoff')
|
||||
const entry = drawer.findAll('button').find(button => button.text() === '前往项目质量规则')
|
||||
expect(entry).toBeDefined()
|
||||
await entry!.trigger('click')
|
||||
expect(wrapper!.getComponent(AppDrawer).props('open')).toBe(false)
|
||||
expect(openSettings).not.toHaveBeenCalled()
|
||||
wrapper!.getComponent(AppDrawer).vm.$emit('closed')
|
||||
await flushPromises()
|
||||
expect(openSettings).toHaveBeenCalledExactlyOnceWith('quality')
|
||||
})
|
||||
it('只读核对后明确确认现有规则,不在检查入口保存另一份草稿', async () => {
|
||||
const { data, drawer } = await openPreparation('preparation-confirm-readonly')
|
||||
const save = vi.spyOn(projectsApi, 'saveQualityPolicy')
|
||||
const confirm = vi.spyOn(projectsApi, 'confirmQualityPolicy').mockImplementation(async () => {
|
||||
data.policy.confirmed = true
|
||||
data.policy.confirmedRevision = data.policy.revision
|
||||
data.policy.confirmedAt = '2026-10-28T09:00:00Z'
|
||||
return structuredClone(data.policy)
|
||||
})
|
||||
const footer = drawer.get('.app-drawer-footer')
|
||||
const button = footer.findAll('button').find(item => item.text() === '确认项目质量规则')
|
||||
expect(button).toBeDefined()
|
||||
expect(button!.attributes('disabled')).toBeDefined()
|
||||
expect(confirm).not.toHaveBeenCalled()
|
||||
await footer.get('[role="checkbox"]').trigger('click')
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(save).not.toHaveBeenCalled()
|
||||
expect(confirm).toHaveBeenCalledExactlyOnceWith(data.policy.projectId, data.policy.revision)
|
||||
})
|
||||
it('规则在其他入口变化后不确认旧版本,保留重新核对入口', async () => {
|
||||
const { data, drawer } = await openPreparation('preparation-policy-stale')
|
||||
const confirm = vi.spyOn(projectsApi, 'confirmQualityPolicy')
|
||||
const footer = drawer.get('.app-drawer-footer')
|
||||
const button = footer.findAll('button').find(item => item.text() === '确认项目质量规则')
|
||||
expect(button).toBeDefined()
|
||||
await footer.get('[role="checkbox"]').trigger('click')
|
||||
data.policy.revision++
|
||||
data.policy.fingerprint = 'c'.repeat(64)
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirm).not.toHaveBeenCalled()
|
||||
expect(drawer.text()).toContain('已变化')
|
||||
})
|
||||
it('检查抽屉关闭期间切换项目,不回填旧项目的配置跳转', async () => {
|
||||
const { drawer, openSettings } = await openPreparation('preparation-old-project')
|
||||
await drawer
|
||||
.findAll('button')
|
||||
.find(button => button.text() === '前往项目质量规则')!
|
||||
.trigger('click')
|
||||
await wrapper!.setProps({ projectId: 'preparation-new-project' })
|
||||
wrapper!.getComponent(AppDrawer).vm.$emit('closed')
|
||||
await flushPromises()
|
||||
expect(openSettings).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -1396,19 +1396,15 @@ describe('工作台页面交互', () => {
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
})
|
||||
|
||||
it('拆解导出图标位于 Tabs suffix,空快照时禁用且不再提供执行记录', async () => {
|
||||
it('拆解初始空页面隐藏标题、分类和导出,仅保留中央设置引导', async () => {
|
||||
wrapper = mount(BreakdownPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: routerLinkStubs }
|
||||
})
|
||||
const toolbar = wrapper.get('.result-toolbar')
|
||||
expect(toolbar.find('[aria-label="拆解结果"]').exists()).toBe(true)
|
||||
expect(toolbar.find(':scope > button').exists()).toBe(false)
|
||||
const exportButton = toolbar.get<HTMLButtonElement>('.n-tabs-nav__suffix [aria-label="导出拆解结果"]')
|
||||
expect(exportButton.element.disabled).toBe(true)
|
||||
expect(exportButton.text()).toBe('')
|
||||
expect(exportButton.get('svg').attributes('width')).toBe('18')
|
||||
expect(toolbar.find('[aria-label="拆解更多操作"]').exists()).toBe(false)
|
||||
expect(wrapper.get('.workspace-heading-scroll').isVisible()).toBe(false)
|
||||
expect(wrapper.find('.result-toolbar').exists()).toBe(false)
|
||||
expect(wrapper.find('[aria-label="导出拆解结果"]').exists()).toBe(false)
|
||||
expect(wrapper.get('.breakdown-initial-empty').text()).toContain('拆解设置')
|
||||
expect(wrapper.find('.history-panel').exists()).toBe(false)
|
||||
expect(wrapper.text()).not.toContain('执行记录')
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user