feat(short-drama-agent-front): 完善镜头定位与项目配置
This commit is contained in:
1 parent
470b52e26d
commit
5b134207b8
66 files changed
+2042
-984
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { defineComponent, h, reactive } from 'vue'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { NFormItem, NInput } from 'naive-ui'
|
||||
import { NFormItem, NInput, NSelect } from 'naive-ui'
|
||||
import AppForm from '@/components/ui/AppForm.vue'
|
||||
import CreateProjectDialog from '@/features/projects/components/CreateProjectDialog.vue'
|
||||
import GenerateImageDialog from '@/features/subject-images/components/GenerateImageDialog.vue'
|
||||
@@ -10,22 +11,8 @@ import StyleImages from '@/features/visual-style/components/StyleImages.vue'
|
||||
import { formFixture } from '@/features/subject-images/testing/fixtures'
|
||||
import { requiredTextRule } from '@/lib/form-rules'
|
||||
|
||||
const imageCatalog = {
|
||||
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
|
||||
images: [{
|
||||
type: 'image' as const, provider: 'qwen-image', providerLabel: 'Qwen', model: 'qwen-image-3.0-pro',
|
||||
modelLabel: 'Qwen Image', supported: true as const, enabled: true, isDefault: true, capabilities: {},
|
||||
generationOptions: [{ key: 'size', label: '图片尺寸', type: 'size' as const, required: true,
|
||||
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }] }],
|
||||
defaults: { size: '2048*2048' }, projectConstraints: []
|
||||
}],
|
||||
videos: []
|
||||
}
|
||||
const creativeProfile = {
|
||||
projectId: 'gallery-test', aspectRatio: '1:1' as const, imageProvider: 'qwen-image',
|
||||
imageModel: 'qwen-image-3.0-pro', imageOptions: { size: '2048*2048' },
|
||||
videoProvider: 'seedance', videoModel: 'seedance', videoOptions: {}
|
||||
}
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('gallery-test')
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
@@ -34,6 +21,11 @@ afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
/**
|
||||
* 查找真实弹窗的可见操作按钮。
|
||||
* @param text 按钮完整文案
|
||||
* @returns 实际按钮元素
|
||||
*/
|
||||
function button(text: string) {
|
||||
const result = [...document.querySelectorAll<HTMLButtonElement>('button')].find(
|
||||
el => el.textContent?.trim() === text
|
||||
@@ -41,15 +33,29 @@ function button(text: string) {
|
||||
if (!result) throw new Error(`找不到按钮:${text}`)
|
||||
return result
|
||||
}
|
||||
/**
|
||||
* 更新真实表单字段并等待 Vue 绑定同步。
|
||||
* @param selector 字段选择器
|
||||
* @param value 本次输入值
|
||||
* @returns 字段绑定同步完成
|
||||
*/
|
||||
async function input(selector: string, value: string) {
|
||||
const el = document.querySelector<HTMLInputElement | HTMLTextAreaElement>(selector)!
|
||||
el.value = value
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
await flushPromises()
|
||||
}
|
||||
/**
|
||||
* 汇总实际字段错误反馈。
|
||||
* @returns 当前全部校验错误文案
|
||||
*/
|
||||
function feedback() {
|
||||
return [...document.querySelectorAll('.n-form-item-feedback--error')].map(el => el.textContent).join(' ')
|
||||
}
|
||||
/**
|
||||
* 提交实际表单以执行统一字段校验。
|
||||
* @returns 表单校验与响应同步完成
|
||||
*/
|
||||
async function submit() {
|
||||
document.querySelector('form')!.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }))
|
||||
await flushPromises()
|
||||
@@ -57,25 +63,30 @@ async function submit() {
|
||||
|
||||
describe('统一的 Naive UI 表单校验', () => {
|
||||
it('新建剧本使用字段反馈拦截空白主题和小数集数,修正后只发送一次请求', async () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(new Response('{"projectId":"created","status":"generating"}', { status: 202 }))
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response('{"projectId":"created","executionId":"create-execution-1","status":"pending"}', {
|
||||
status: 202
|
||||
})
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(CreateProjectDialog, { attachTo: document.body })
|
||||
button('新建剧本').click()
|
||||
await flushPromises()
|
||||
expect(document.querySelector('form')!.noValidate).toBe(true)
|
||||
expect(document.querySelector('[required]')).toBeNull()
|
||||
await input('#title', ' 雨夜来信标题 ')
|
||||
await input('#topic', ' ')
|
||||
const focus = vi.spyOn(HTMLTextAreaElement.prototype, 'focus')
|
||||
await submit()
|
||||
button('开始生成').click()
|
||||
await flushPromises()
|
||||
expect(feedback()).toContain('请填写故事主题')
|
||||
// 无布局的 DOM 环境会被模态框焦点圈带回哨兵,检查实际聚焦目标。
|
||||
expect(focus.mock.contexts).toContain(document.querySelector('#topic'))
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
await input('#topic', ' 雨夜来信 ')
|
||||
await input('#episode-count', '1.5')
|
||||
await submit()
|
||||
button('开始生成').click()
|
||||
await flushPromises()
|
||||
expect(feedback()).toContain('计划集数须为正整数')
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
await input('#episode-count', '3')
|
||||
@@ -84,24 +95,34 @@ describe('统一的 Naive UI 表单校验', () => {
|
||||
button('开始生成').click()
|
||||
await flushPromises()
|
||||
expect(fetcher).toHaveBeenCalledTimes(1)
|
||||
expect(wrapper.emitted('created')).toEqual([['created']])
|
||||
expect(JSON.parse(String(fetcher.mock.calls[0]?.[1]?.body))).toEqual({
|
||||
title: '雨夜来信标题',
|
||||
topic: '雨夜来信',
|
||||
style: '',
|
||||
episodeCount: 3
|
||||
})
|
||||
expect(wrapper.emitted('created')).toEqual([['created', 'create-execution-1']])
|
||||
})
|
||||
|
||||
it('图片宽高错误显示在两侧字段,补全后同时消失,切换目标清除校验状态', async () => {
|
||||
it('图片尺寸采用目录必填枚举,切换目标清空提示词和费用确认', async () => {
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form: formFixture(), disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
})
|
||||
await flushPromises()
|
||||
await input('#image-width', '1024')
|
||||
expect(document.querySelectorAll('.n-form-item-feedback--error')).toHaveLength(2)
|
||||
expect(feedback()).toContain('宽高须同时填写正整数')
|
||||
await input('#image-height', '768')
|
||||
expect(feedback()).toBe('')
|
||||
await input('#image-height', '')
|
||||
expect(feedback()).not.toBe('')
|
||||
await wrapper.setProps({ form: formFixture('other') })
|
||||
const size = wrapper.findAllComponents(NSelect).find(select => select.props('value') === '2048*2048')!
|
||||
expect(size.props('clearable')).toBe(false)
|
||||
expect(size.props('options')).toEqual([{ label: '1:1 · 2048×2048', value: '2048*2048' }])
|
||||
expect(document.querySelector('#image-width')).toBeNull()
|
||||
expect(document.querySelector('#image-height')).toBeNull()
|
||||
await input('#image-prompt', '仅用于上一形态')
|
||||
document.querySelector<HTMLElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
expect(button('确认生成图片').disabled).toBe(false)
|
||||
await wrapper.setProps({ form: { ...formFixture(), id: 'other-form' } })
|
||||
await flushPromises()
|
||||
expect(document.querySelector<HTMLTextAreaElement>('#image-prompt')?.value).toBe('')
|
||||
expect(button('确认生成图片').disabled).toBe(true)
|
||||
expect(feedback()).toBe('')
|
||||
expect(wrapper.emitted('generate')).toBeUndefined()
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user