Files

113 lines
5.9 KiB
TypeScript

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<InstanceType<typeof StoryboardPreparation>> | 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.setProps({ open: true })
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()
})
})