fix(short-drama-agent-front): 修复测试警告与请求模拟
This commit is contained in:
1 parent
46f54548c7
commit
a9370cdf50
8 files changed
+67
-18
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { mediaAssetUrl } from '@/lib/assets'
|
||||
@@ -197,6 +198,15 @@ describe('镜头生产数据契约', () => {
|
||||
})
|
||||
|
||||
it('所有首帧生成都先成为候选,并要求费用确认', async () => {
|
||||
/** 弹窗打开时只读取模型目录和项目配置,测试不依赖真实后端。 */
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
const path = String(url)
|
||||
if (path === '/api/generation-models') return new Response(JSON.stringify({ data: imageCatalog }))
|
||||
if (path === '/api/projects/project-1/creative-profile')
|
||||
return new Response(JSON.stringify({ data: generationProfile('project-1') }))
|
||||
throw new Error(`首帧弹窗出现未预期请求:${path}`)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(KeyframeDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, shotId: 'shot-1', shotTitle: '开场', projectId: 'project-1', disabled: false }
|
||||
@@ -208,7 +218,7 @@ describe('镜头生产数据契约', () => {
|
||||
button('确认生成首帧').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
[{ provider: undefined, generationOptions: {}, setPrimary: false }]
|
||||
[{ provider: 'qwen-image', generationOptions: { size: '2048*2048' }, setPrimary: false }]
|
||||
])
|
||||
|
||||
await wrapper.setProps({ open: false })
|
||||
@@ -221,8 +231,10 @@ describe('镜头生产数据契约', () => {
|
||||
button('确认生成首帧').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')?.at(-1)).toEqual([
|
||||
{ provider: undefined, generationOptions: {}, setPrimary: false }
|
||||
{ provider: 'qwen-image', generationOptions: { size: '2048*2048' }, setPrimary: false }
|
||||
])
|
||||
expect(fetcher).toHaveBeenCalledTimes(4)
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
})
|
||||
|
||||
it('首帧生成前可预览后端最终选图规划和 Prompt', async () => {
|
||||
|
||||
@@ -167,7 +167,7 @@ describe('形态正式提示词与批量配置', () => {
|
||||
const form = formFixture()
|
||||
wrapper = mount(FormPromptDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile }
|
||||
props: { open: true, disabled: false, form }
|
||||
})
|
||||
await flushPromises()
|
||||
find('生成正式提示词').click()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||||
import { routerLinkStubs } from '../../fixtures/router'
|
||||
import { computed, ref } from 'vue'
|
||||
import { NImage, NRadioGroup, NScrollbar } from 'naive-ui'
|
||||
import { createMemoryHistory, createRouter, type RouteRecordRaw } from 'vue-router'
|
||||
import { DOMWrapper, flushPromises, mount, RouterLinkStub, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi, type Mock } 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'
|
||||
@@ -38,9 +39,6 @@ import { drawerPanel, expandSections, selectControl } from '@/testing/naive'
|
||||
import ProductionPage from '@/features/production/ProductionPage.vue'
|
||||
import { getProductionSession } from '@/features/production/model'
|
||||
|
||||
/** 单独挂载的页面和组件只替换导航链接,保留链接插槽和目标参数。 */
|
||||
const routerLinkStubs = { RouterLink: RouterLinkStub }
|
||||
|
||||
/**
|
||||
* 为内存路由补齐页面链接使用的正式项目工作区,避免链接解析时缺少目标路由。
|
||||
* @param routes 当前测试页面的入口路由
|
||||
@@ -259,13 +257,8 @@ async function mountSubjectImages() {
|
||||
await expandSections()
|
||||
}
|
||||
|
||||
/** 保留警告的原始输出,并在每例结束时检查页面挂载和清理过程是否出现警告。 */
|
||||
beforeEach(() => {
|
||||
vi.spyOn(console, 'warn')
|
||||
})
|
||||
|
||||
/** 释放页面与会话状态,并检查当前用例没有产生 Vue 或路由警告。 */
|
||||
afterEach(testContext => {
|
||||
/** 释放页面与会话状态;警告和未模拟请求由全局测试配置统一检查。 */
|
||||
afterEach(() => {
|
||||
getProductionSession(fixture.id).receipt = null
|
||||
getProductionSession(fixture.id).pipelineReceipt = null
|
||||
getIdentitySession(fixture.id).receipt = null
|
||||
@@ -278,7 +271,6 @@ afterEach(testContext => {
|
||||
getImageSession(fixture.id).receipt = null
|
||||
getImageSession(fixture.id).promptReceipt = null
|
||||
Object.assign(getOperation(fixture.id), { pending: false, label: '', error: '', notice: '', noticeType: null })
|
||||
testContext.expect(console.warn).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
describe('内容级滚动下的生产反馈', () => {
|
||||
|
||||
Reference in new issue
Block a user