Files

70 lines
3.4 KiB
TypeScript

import { flushPromises, mount } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import BreakdownDurationDiagnostics from '@/features/breakdown/components/BreakdownDurationDiagnostics.vue'
afterEach(() => vi.unstubAllGlobals())
describe('时长冲突诊断', () => {
it('分开显示正式目标与失败候选预算,诊断只发出 GET', async () => {
const plan = {
episodeNo: 2,
targetDurationSeconds: 45,
beats: [{ beatNo: 3, title: '拆卸', estimatedDurationSeconds: 9 }]
}
const fetcher = vi.fn<typeof fetch>(
async url =>
new Response(
JSON.stringify({
data: String(url).endsWith('/duration-budget')
? {
projectId: 'duration-project',
episodes: [
{ episodeNo: 2, targetDurationSeconds: 60, shotCount: 0, shotSeconds: null }
]
}
: {
projectId: 'duration-project',
storyboardPlans: [plan],
storyboardEpisodeDurationBudgets: [
{
episodeNo: 2,
minimumRequiredSeconds: 10,
deficitSeconds: 1,
beatSuggestions: [
{ beatNo: 3, budgetSeconds: 9, requiredSeconds: 10, deficitSeconds: 1 }
]
}
],
failureDetails: {
details: [
{
kind: 'storyboard-duration-failure',
episodeNo: 2,
candidate: { episodeNo: 2, episodePlan: plan, beatShots: [] },
retryAutomatically: false
}
]
}
}
})
)
)
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(BreakdownDurationDiagnostics, { props: { projectId: 'duration-project' } })
try {
await flushPromises()
expect(wrapper.text()).toContain('正式目标 60 秒')
expect(wrapper.text()).toContain('正式镜头 未生成')
expect(wrapper.text()).toContain('完整失败候选')
await wrapper.get('.n-collapse-item__header-main').trigger('click')
await flushPromises()
expect(wrapper.text()).toMatch(/拆解时目标\s+45 秒/)
expect(wrapper.text()).toContain('正式目标已变化')
expect(wrapper.text()).toMatch(/最低需求 10 秒 · 缺口 1 秒/)
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
} finally {
wrapper.unmount()
}
})
})