fix(short-drama-agent-front): 修复页面测试路由警告
This commit is contained in:
1 parent
ddc9468bc4
commit
46f54548c7
1 file changed
+81
-30
@@ -1,9 +1,9 @@
|
||||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||||
import { computed, ref } from 'vue'
|
||||
import { NImage, NRadioGroup, NScrollbar } from 'naive-ui'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi, type Mock } from 'vitest'
|
||||
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 CreateProjectDialog from '@/features/projects/components/CreateProjectDialog.vue'
|
||||
import BreakdownPage from '@/features/breakdown/BreakdownPage.vue'
|
||||
import CreateDramaPage from '@/features/create-drama/CreateDramaPage.vue'
|
||||
@@ -38,10 +38,42 @@ 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 当前测试页面的入口路由
|
||||
* @returns 独立的内存路由实例
|
||||
*/
|
||||
function createPageRouter(routes: RouteRecordRaw[]) {
|
||||
return createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
...routes,
|
||||
...[
|
||||
'create-drama',
|
||||
'breakdown',
|
||||
'visual-style',
|
||||
'subject-identity',
|
||||
'subject-images',
|
||||
'assets',
|
||||
'storyboard',
|
||||
'production'
|
||||
].map(workspace => ({ path: `/projects/:projectId/${workspace}`, component: {} }))
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 新资产页面复用已有项目上下文和内存路由,不接入真实模型。
|
||||
* @param page 要挂载的风格或主体身份页面
|
||||
* @param query 初始地址的查询参数
|
||||
* @returns 当前页面注入的项目上下文
|
||||
*/
|
||||
async function mountAssets(page: 'style' | 'identity', query = '') {
|
||||
const component = page === 'style' ? VisualStylePage : SubjectIdentityPage
|
||||
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/assets', component }] })
|
||||
const router = createPageRouter([{ path: '/assets', component }])
|
||||
await router.push('/assets' + query)
|
||||
const provided = context()
|
||||
wrapper = mount(component, {
|
||||
@@ -97,11 +129,11 @@ function stubFetch(fetcher: Mock<typeof fetch>) {
|
||||
projectId: fixture.id,
|
||||
workflowName,
|
||||
status: 'completed',
|
||||
durationMode: 'auto',
|
||||
episodeCount: 1,
|
||||
targetDurationSeconds: null,
|
||||
episodeMinSeconds: null,
|
||||
episodeMaxSeconds: null,
|
||||
durationMode: 'auto',
|
||||
episodeCount: 1,
|
||||
targetDurationSeconds: null,
|
||||
episodeMinSeconds: null,
|
||||
episodeMaxSeconds: null,
|
||||
stage: 'finalize',
|
||||
current: 1,
|
||||
total: 1,
|
||||
@@ -138,7 +170,14 @@ const fixture: ProjectDetail = {
|
||||
episodeMaxSeconds: null,
|
||||
createdAt: '2026-08-27T00:00:00Z',
|
||||
updatedAt: '2026-08-27T00:00:00Z',
|
||||
episodes: [{ episode: 1, targetDurationSeconds: null, title: '来信', content: '<script>不要执行模型内容</script>\n第一场:旧书店。' }],
|
||||
episodes: [
|
||||
{
|
||||
episode: 1,
|
||||
targetDurationSeconds: null,
|
||||
title: '来信',
|
||||
content: '<script>不要执行模型内容</script>\n第一场:旧书店。'
|
||||
}
|
||||
],
|
||||
characters: [{ id: 'character', name: '林知夏' }],
|
||||
world: { era: '当代' }
|
||||
}
|
||||
@@ -201,7 +240,7 @@ async function mountStoryboard() {
|
||||
provided.data.value!.checkpoints = [storyboardCheckpoint()]
|
||||
wrapper = mount(StoryboardPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: provided }, stubs: { RouterLink: true } }
|
||||
global: { provide: { [projectContextKey as symbol]: provided }, stubs: routerLinkStubs }
|
||||
})
|
||||
await flushPromises()
|
||||
await expandSections()
|
||||
@@ -210,10 +249,7 @@ async function mountStoryboard() {
|
||||
|
||||
/** 形态图库使用真实路由解析来自主体列表的筛选参数。 */
|
||||
async function mountSubjectImages() {
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [{ path: '/projects/:projectId/:workspace', component: SubjectImagesPage }]
|
||||
})
|
||||
const router = createPageRouter([{ path: '/projects/:projectId/:workspace', component: SubjectImagesPage }])
|
||||
await router.push(`/projects/${fixture.id}/subject-images`)
|
||||
wrapper = mount(SubjectImagesPage, {
|
||||
attachTo: document.body,
|
||||
@@ -223,7 +259,13 @@ async function mountSubjectImages() {
|
||||
await expandSections()
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
/** 保留警告的原始输出,并在每例结束时检查页面挂载和清理过程是否出现警告。 */
|
||||
beforeEach(() => {
|
||||
vi.spyOn(console, 'warn')
|
||||
})
|
||||
|
||||
/** 释放页面与会话状态,并检查当前用例没有产生 Vue 或路由警告。 */
|
||||
afterEach(testContext => {
|
||||
getProductionSession(fixture.id).receipt = null
|
||||
getProductionSession(fixture.id).pipelineReceipt = null
|
||||
getIdentitySession(fixture.id).receipt = null
|
||||
@@ -236,6 +278,7 @@ afterEach(() => {
|
||||
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('内容级滚动下的生产反馈', () => {
|
||||
@@ -263,7 +306,7 @@ describe('内容级滚动下的生产反馈', () => {
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ProductionPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: routerLinkStubs }
|
||||
})
|
||||
await flushPromises()
|
||||
const directory = wrapper.get('.production-shot-list')
|
||||
@@ -289,7 +332,7 @@ describe('内容级滚动下的生产反馈', () => {
|
||||
stubFetch(vi.fn<typeof fetch>().mockRejectedValue(new Error('生产连接中断')))
|
||||
wrapper = mount(ProductionPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: routerLinkStubs }
|
||||
})
|
||||
await flushPromises()
|
||||
expect(wrapper.get('[data-workspace-tools]').attributes('aria-expanded')).toBe('false')
|
||||
@@ -303,7 +346,7 @@ describe('内容级滚动下的生产反馈', () => {
|
||||
stubFetch(vi.fn<typeof fetch>().mockRejectedValue(new Error('离线测试')))
|
||||
wrapper = mount(ProductionPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: routerLinkStubs }
|
||||
})
|
||||
await flushPromises()
|
||||
getProductionSession(fixture.id).receipt = {
|
||||
@@ -1337,7 +1380,7 @@ describe('工作台页面交互', () => {
|
||||
it('拆解导出图标位于 Tabs suffix,空快照时禁用且不再提供执行记录', async () => {
|
||||
wrapper = mount(BreakdownPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: routerLinkStubs }
|
||||
})
|
||||
const toolbar = wrapper.get('.result-toolbar')
|
||||
expect(toolbar.find('[aria-label="拆解结果"]').exists()).toBe(true)
|
||||
@@ -1524,7 +1567,11 @@ describe('工作台页面交互', () => {
|
||||
})
|
||||
)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, { attachTo: document.body, props: { projectId: fixture.id, shot, disabled: false } })
|
||||
wrapper = mount(ShotTools, {
|
||||
attachTo: document.body,
|
||||
global: { stubs: routerLinkStubs },
|
||||
props: { projectId: fixture.id, shot, disabled: false }
|
||||
})
|
||||
await flushPromises()
|
||||
expect(wrapper.getComponent(NImage).props()).toMatchObject({ objectFit: 'cover', previewDisabled: false })
|
||||
const image = wrapper.get('.reference-card img')
|
||||
@@ -1599,7 +1646,11 @@ describe('工作台页面交互', () => {
|
||||
)
|
||||
)
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, { attachTo: document.body, props: { projectId: fixture.id, shot, disabled: false } })
|
||||
wrapper = mount(ShotTools, {
|
||||
attachTo: document.body,
|
||||
global: { stubs: routerLinkStubs },
|
||||
props: { projectId: fixture.id, shot, disabled: false }
|
||||
})
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('图片不可用')
|
||||
expect(wrapper.find('.reference-card a').exists()).toBe(false)
|
||||
@@ -1887,6 +1938,7 @@ describe('工作台页面交互', () => {
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, {
|
||||
attachTo: document.body,
|
||||
global: { stubs: routerLinkStubs },
|
||||
props: { projectId: fixture.id, shot: designedShot(), disabled: false }
|
||||
})
|
||||
expect(fetcher).toHaveBeenCalledTimes(2)
|
||||
@@ -1923,6 +1975,7 @@ describe('工作台页面交互', () => {
|
||||
stubFetch(fetcher)
|
||||
wrapper = mount(ShotTools, {
|
||||
attachTo: document.body,
|
||||
global: { stubs: routerLinkStubs },
|
||||
props: { projectId: fixture.id, shot: designedShot(), disabled: false }
|
||||
})
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
@@ -1947,6 +2000,7 @@ describe('工作台页面交互', () => {
|
||||
)
|
||||
wrapper = mount(ShotTools, {
|
||||
attachTo: document.body,
|
||||
global: { stubs: routerLinkStubs },
|
||||
props: { projectId: fixture.id, episodeNo: 1, shot: designedShot(), disabled: false }
|
||||
})
|
||||
|
||||
@@ -1962,10 +2016,7 @@ describe('工作台页面交互', () => {
|
||||
stubFetch(
|
||||
vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: [fixture] })))
|
||||
)
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [{ path: '/', component: ProjectsPage }]
|
||||
})
|
||||
const router = createPageRouter([{ path: '/', component: ProjectsPage }])
|
||||
await router.push('/')
|
||||
wrapper = mount(ProjectsPage, { attachTo: document.body, global: { plugins: [router] } })
|
||||
await flushPromises()
|
||||
@@ -2020,7 +2071,7 @@ describe('工作台页面交互', () => {
|
||||
const provided = context()
|
||||
wrapper = mount(BreakdownPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: provided } }
|
||||
global: { provide: { [projectContextKey as symbol]: provided }, stubs: routerLinkStubs }
|
||||
})
|
||||
await expandSections()
|
||||
button('预览分组').click()
|
||||
@@ -2043,7 +2094,7 @@ describe('工作台页面交互', () => {
|
||||
it('切换剧本标签保留阅读容器和位置,右侧只保留直接导出', async () => {
|
||||
wrapper = mount(CreateDramaPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: routerLinkStubs }
|
||||
})
|
||||
const suffix = wrapper.get('.script-section .n-tabs-nav__suffix')
|
||||
expect(suffix.findAll('button').map(item => item.text())).toEqual([''])
|
||||
@@ -2075,7 +2126,7 @@ describe('工作台页面交互', () => {
|
||||
it('剧本文本按纯文本显示,不执行模型输出的 HTML', () => {
|
||||
wrapper = mount(CreateDramaPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: { RouterLink: true } }
|
||||
global: { provide: { [projectContextKey as symbol]: context() }, stubs: routerLinkStubs }
|
||||
})
|
||||
expect(wrapper.find('.script-body').text()).toContain('<script>不要执行模型内容</script>')
|
||||
expect(wrapper.find('.script-body script').exists()).toBe(false)
|
||||
|
||||
Reference in new issue
Block a user