feat(short-drama-agent-front): 接入素材预览审核并完善创作流程

This commit is contained in:
GJ committed 2026-11-02 10:16:10 +08:00
1 parent f8b0fbb8ca
commit dc8bb17a23
66 files changed
+2864 -632

No files matched your search

+77 -12
View File
@@ -1,6 +1,7 @@
import { imagePreviewFixture } from '../../fixtures/image-preview'
import { imageCatalog, generationProfile } from '../../fixtures/generation'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { AssetImage } from '@/components/ui'
import { getOperation } from '@/features/workflows/operations'
import GenerateImageDialog from '@/features/subject-images/components/GenerateImageDialog.vue'
@@ -11,6 +12,8 @@ import { expandSections } from '@/testing/naive'
/** 当前测试使用真实目录契约构造项目模型配置。 */
const creativeProfile = generationProfile('gallery-test')
/** 生成提交由测试替身接收,绝不调用真实模型。 */
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
let wrapper: VueWrapper | undefined
/** Naive 将弹窗挂载到 body,需要从实际弹窗找到按钮。 */
function button(label: string): HTMLButtonElement {
@@ -18,7 +21,18 @@ function button(label: string): HTMLButtonElement {
if (!element) throw new Error('找不到按钮:' + label)
return element
}
/** 每次生成用例只返回无副作用的预览夹具。 */
beforeEach(() =>
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async url => {
const formId = String(url).match(/subject-forms\/([^/]+)/)?.[1] ?? 'form-db-1'
return new Response(JSON.stringify({ data: imagePreviewFixture(formId) }))
})
)
)
afterEach(() => {
submitGeneration.mockClear()
wrapper?.unmount()
wrapper = undefined
document.body.innerHTML = ''
@@ -70,10 +84,17 @@ describe('形态图片选择与操作', () => {
form.subject.module = module
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
props: {
submitGeneration,
open: true,
form,
disabled: false,
catalog: imageCatalog,
profile: creativeProfile
}
})
await flushPromises()
expect(document.body.textContent).toContain('母版')
expect(document.body.textContent).toContain('质量审核')
expect(document.body.textContent).not.toContain('道具形态生图暂不自动引用')
})
it('按需预览正式形态的实际参考图和 Provider Prompt,不触发生图事件', async () => {
@@ -81,6 +102,7 @@ describe('形态图片选择与操作', () => {
new Response(
JSON.stringify({
data: {
...imagePreviewFixture(),
subjectFormId: 'form-db-1',
provider: 'seedream',
model: 'image-model',
@@ -101,7 +123,14 @@ describe('形态图片选择与操作', () => {
vi.stubGlobal('fetch', fetcher)
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, form: formFixture(), disabled: false, catalog: imageCatalog, profile: creativeProfile }
props: {
submitGeneration,
open: true,
form: formFixture(),
disabled: false,
catalog: imageCatalog,
profile: creativeProfile
}
})
await flushPromises()
button('预览实际生成输入').click()
@@ -142,30 +171,56 @@ describe('形态图片选择与操作', () => {
it('生图确认发送正式形态 ID 和项目模型参数,默认不替换已有主图', async () => {
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, form: formFixture(), disabled: false, catalog: imageCatalog, profile: creativeProfile }
props: {
submitGeneration,
open: true,
form: formFixture(),
disabled: false,
catalog: imageCatalog,
profile: creativeProfile
}
})
await flushPromises()
expect(button('确认生成图片').disabled).toBe(true)
button('预览实际生成输入').click()
await flushPromises()
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
await flushPromises()
button('确认生成图片').click()
await flushPromises()
expect(wrapper.emitted('generate')).toEqual([
['form-db-1', { setPrimary: false, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
expect(submitGeneration.mock.calls).toEqual([
[
'form-db-1',
{
setPrimary: false,
expectedPreviewFingerprint: 'a'.repeat(64),
provider: 'qwen-image',
generationOptions: { size: '2048*2048' }
}
]
])
})
it('新形态默认设主图并继承目录尺寸,切换形态清空提示词和费用确认', async () => {
it('新形态默认保留候选并继承目录尺寸,切换形态清空提示词和确认', async () => {
const form = formFixture()
form.images = []
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
props: {
submitGeneration,
open: true,
form,
disabled: false,
catalog: imageCatalog,
profile: creativeProfile
}
})
await flushPromises()
const prompt = document.querySelector<HTMLTextAreaElement>('#image-prompt')!
prompt.value = '上一形态自定义提示词'
prompt.dispatchEvent(new Event('input', { bubbles: true }))
button('预览实际生成输入').click()
await flushPromises()
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
await flushPromises()
expect(button('确认生成图片').disabled).toBe(false)
@@ -176,12 +231,22 @@ describe('形态图片选择与操作', () => {
expect(document.querySelector('#image-width')).toBeNull()
expect(document.querySelector('#image-height')).toBeNull()
expect(document.querySelector('#confirm-image-cost')!.getAttribute('aria-checked')).toBe('false')
button('预览实际生成输入').click()
await flushPromises()
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
await flushPromises()
button('确认生成图片').click()
await flushPromises()
expect(wrapper.emitted('generate')).toEqual([
['form-db-2', { setPrimary: true, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
expect(submitGeneration.mock.calls).toEqual([
[
'form-db-2',
{
setPrimary: false,
expectedPreviewFingerprint: 'a'.repeat(64),
provider: 'qwen-image',
generationOptions: { size: '2048*2048' }
}
]
])
})
@@ -223,7 +288,7 @@ describe('形态图片选择与操作', () => {
button('设为主参考图').click()
await flushPromises()
expect(fetcher.mock.calls).toHaveLength(1)
button('确认切换主图').click()
button('确认费用并设为主图').click()
await flushPromises()
expect(fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')?.[0]).toBe(
'/api/subject-forms/form-db-1/images/image-db-1/primary'