perf(short-drama-agent-front): 优化记录加载与工作区体验

This commit is contained in:
GJ committed 2026-11-06 20:56:25 +08:00
1 parent d0264c08ce
commit db9aea1694
111 files changed
+1680 -1290

No files matched your search

+21 -37
View File
@@ -1,9 +1,10 @@
import { testProjectContextFrom } from '@/testing/project-context'
import { approvedCharacter } from '../../fixtures/image-preview'
import { imagePreviewFixture } from '../../fixtures/image-preview'
import { preparationFixture } from '../storyboard-preparation/fixtures'
import { generationProfile, imageCatalog } from '../../fixtures/generation'
import { routerLinkStubs } from '../../fixtures/router'
import { computed, ref } from 'vue'
import { ref } from 'vue'
import { NDrawer, NImage, NRadioGroup, NScrollbar } from 'naive-ui'
import { createMemoryHistory, createRouter, type RouteRecordRaw } from 'vue-router'
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
@@ -12,7 +13,7 @@ import CreateProjectDialog from '@/features/projects/components/CreateProjectDia
import BreakdownPage from '@/features/breakdown/BreakdownPage.vue'
import CreateDramaPage from '@/features/create-drama/CreateDramaPage.vue'
import ProjectsPage from '@/features/projects/ProjectsPage.vue'
import { projectContextKey, type useProjectData } from '@/features/projects/context'
import { projectContextKey } from '@/features/projects/context'
import type { ProjectDetail } from '@/features/projects/types'
import type { Checkpoint } from '@/features/workflows/types'
import StoryboardPage from '@/features/storyboard/StoryboardPage.vue'
@@ -222,7 +223,7 @@ const fixture: ProjectDetail = {
let wrapper: VueWrapper | undefined
/** 使用真实上下文形状,不绕过页面内的异步操作与按钮守卫。 */
function context(): ReturnType<typeof useProjectData> {
function context(): ReturnType<typeof testProjectContextFrom> {
const data = ref({
project: fixture,
checkpoints: [] as Checkpoint[],
@@ -237,17 +238,7 @@ function context(): ReturnType<typeof useProjectData> {
storyboard: { ready: true, reason: null }
}
})
return {
data,
project: computed(() => data.value.project),
checkpoints: computed(() => data.value.checkpoints),
stageReadiness: computed(() => data.value.stageReadiness),
loading: ref(false),
error: ref(''),
updatedAt: ref(''),
refresh: vi.fn<() => Promise<void>>().mockResolvedValue(),
refreshStageReadiness: vi.fn<() => Promise<void>>().mockResolvedValue()
}
return testProjectContextFrom(data)
}
/** 找到挂载到 body 的 Naive 弹窗按钮。 */
@@ -481,7 +472,7 @@ describe('视觉风格与主体身份工作区', () => {
const provided = await mountAssets('identity')
provided.data.value!.stageReadiness.identity = { ready: false, reason: '还有角色身份需要确认' }
await flushPromises()
expect(wrapper!.get('.identity-next-action').text()).toContain('可以继续生成此主体的形态图片')
expect(wrapper!.get('.identity-next-action').text()).toContain('可生成形态图片')
expect(button('查看形态图片').disabled).toBe(false)
expect(wrapper!.get('.identity-subject-forms').text()).toContain('查看此主体形态图片')
expect(wrapper!.find('a[href*="/subject-images"]').exists()).toBe(true)
@@ -1146,7 +1137,7 @@ describe('视觉风格与主体身份工作区', () => {
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
expect(post[0]).toBe('/api/projects/page-test-project/subject-identities/generate')
expect(JSON.parse(post[1]!.body as string)).toEqual({ force: false, concurrency: 3 })
expect(drawerPanel().text()).toContain('部分生成未完成')
expect(drawerPanel().text()).toContain('部分未完成')
expect(drawerPanel().text()).toContain('含锁定 1')
expect(drawerPanel().text()).toContain('文本模型超时')
})
@@ -1288,7 +1279,7 @@ describe('视觉风格与主体身份工作区', () => {
})
stubFetch(fetcher)
await mountAssets('identity')
expect(drawerPanel().text()).toContain('先保存人物、场景或道具的固定特征')
expect(drawerPanel().text()).toContain('保存固定特征后生成参考图')
expect(wrapper!.getComponent(NDrawer).props('width')).toBe('100vw')
const cards = drawerPanel().get('[aria-label="角色选角进度"]').findAll('.casting-item')
expect(cards).toHaveLength(2)
@@ -1548,12 +1539,10 @@ describe('工作台页面交互', () => {
expect.arrayContaining([
['/api/projects/page-test-project/subject-forms', 'GET'],
['/api/generation-models', 'GET'],
['/api/projects/page-test-project/creative-profile', 'GET'],
['/api/projects/page-test-project/keyframes/readiness?force=false', 'GET'],
['/api/projects/page-test-project/videos/readiness?force=false', 'GET']
['/api/projects/page-test-project/creative-profile', 'GET']
])
)
expect(fetcher).toHaveBeenCalledTimes(5)
expect(fetcher).toHaveBeenCalledTimes(3)
await wrapper!.get('[aria-label="搜索形态图片"]').setValue('不存在的形态')
expect(wrapper!.text()).toContain('没有匹配的形态')
button('清除筛选').click()
@@ -1570,7 +1559,7 @@ describe('工作台页面交互', () => {
)
stubFetch(fetcher)
await mountSubjectImages()
await drawerPanel().get('.n-card-header__close').trigger('click')
await drawerPanel().get('.app-drawer-footer button').trigger('click')
const card = wrapper!.get('.form-image-card')
expect(card.getComponent(NImage).props()).toMatchObject({ objectFit: 'contain', previewDisabled: false })
await card.get('img').trigger('click')
@@ -1579,7 +1568,7 @@ describe('工作台页面交互', () => {
'/storage/subjects/project/form/image.png'
)
expect(document.querySelector('.image-history')).toBeNull()
expect(fetcher).toHaveBeenCalledTimes(5)
expect(fetcher).toHaveBeenCalledTimes(3)
document.querySelector<HTMLElement>('.n-image-preview-overlay')!.click()
await flushPromises()
button('查看图片与记录').click()
@@ -1680,7 +1669,7 @@ describe('工作台页面交互', () => {
stubFetch(fetcher)
await mountSubjectImages()
expect(button('再生成一张').disabled).toBe(true)
expect(wrapper!.text()).toContain('数据库中有形态图片正在后台生成')
expect(wrapper!.text()).toContain('部分形态正在生成')
fail = true
button('查看图片与记录').click()
await flushPromises()
@@ -1833,7 +1822,7 @@ describe('工作台页面交互', () => {
await flushPromises()
await confirmGeneration('补齐项目导演设计')
expect(button('补齐项目导演设计').disabled).toBe(true)
await drawerPanel().get('.n-card-header__close').trigger('click')
await drawerPanel().get('.app-drawer-footer button').trigger('click')
await flushPromises()
expect(wrapper!.get('[data-workspace-tools]').attributes('aria-expanded')).toBe('false')
expect(getOperation(fixture.id).pending).toBe(true)
@@ -1911,7 +1900,7 @@ describe('工作台页面交互', () => {
force: false,
maxRepairAttempts: 0
})
expect(drawerPanel().text()).toContain('本次存在失败')
expect(drawerPanel().text()).toContain('本次有未完成项')
expect(drawerPanel().text()).toContain('缺少主体状态')
})
@@ -1947,17 +1936,12 @@ describe('工作台页面交互', () => {
expect(wrapper!.text()).not.toContain('第1集镜头1')
expect(wrapper!.text()).not.toContain('门口收到一封信')
expect(getStoryboardSession(fixture.id).invalidatedEpisodeSources[1]).toBe(true)
expect(wrapper!.text()).toContain('新标题和剧情详情尚未提供')
expect(drawerPanel().text()).toContain('本集新镜头已保存')
expect(wrapper!.text()).toContain('标题和剧情详情待补齐')
expect(drawerPanel().text()).toContain('新镜头已保存')
expect(drawerPanel().text()).toContain('2 个镜头')
/** Duration Budget 新增一次只读 GET;镜头重生成不应增加额外写入。 */
expect(
fetcher.mock.calls.filter(
([url, init]) =>
(!init?.method || init.method === 'GET') &&
!String(url).endsWith('/storyboard-quality-confirmation')
)
).toHaveLength(12)
/** 重生成仅刷新对应分镜和时长,写入只发生一次。 */
for (const route of ['storyboard-directions', 'storyboard-visual-states'])
expect(fetcher.mock.calls.filter(([url]) => String(url).includes('/' + route + '?'))).toHaveLength(2)
expect(fetcher.mock.calls.filter(([url]) => String(url).endsWith('/duration-budget'))).toHaveLength(2)
expect(fetcher.mock.calls.some(([url]) => String(url) === '/api/workflow-executions/page-execution-1')).toBe(
true
@@ -2003,7 +1987,7 @@ describe('工作台页面交互', () => {
await mountStoryboard()
await flushPromises()
await confirmGeneration('补齐项目导演设计')
expect(drawerPanel().get('[aria-label="生成回执"] [role="alert"]').text()).toContain('存在失败')
expect(drawerPanel().get('[aria-label="生成回执"] [role="alert"]').text()).toContain('本次有未完成项')
expect(drawerPanel().text()).toContain('模型校验失败')
await drawerPanel().get('[role="checkbox"]').trigger('click')
await confirmGeneration('重生成全部导演设计')