import { describe, expect, it } from 'vitest' import { creativeProfileDraft, creativeProfileIssues } from '../../../src/features/generation-config/profile-draft' import type { CreativeProfileInput, GenerationModelCatalog } from '../../../src/features/generation-config/types' /** 后端已保存的竖屏自定义尺寸,不限于目录的尺寸预设。 */ const saved: CreativeProfileInput = { aspectRatio: '9:16', imageProvider: 'qwen-image', imageModel: 'qwen-image-3.0-pro', imageOptions: { size: '1080*1920', count: 1, promptExtend: false }, videoProvider: 'wan', videoModel: 'wan3.0-video', videoOptions: { aspectRatio: 'adaptive', resolution: '1080P', duration: 5, audio: false } } describe('项目配置编辑草稿', () => { it('读取与保存草稿保留真实自定义尺寸和未显示的供应方参数', () => { const draft = creativeProfileDraft(saved) expect(draft.imageOptions).toEqual({ size: '1080*1920', count: 1, promptExtend: false }) expect(draft.videoOptions).toEqual({ aspectRatio: 'adaptive', resolution: '1080P', duration: 5, audio: false }) }) it('未保存的图片和视频参数修改不会污染实际已保存对象', () => { const draft = creativeProfileDraft(saved) draft.imageOptions.size = '2048*2048' draft.videoOptions.duration = 10 expect(saved.imageOptions.size).toBe('1080*1920') expect(saved.videoOptions.duration).toBe(5) }) }) /** 模型目录枚举与数字限制以真实后端 schema 规则为准。 */ const catalog: GenerationModelCatalog = { defaults: { imageProvider: 'qwen-image', videoProvider: 'wan' }, images: [ { type: 'image', provider: 'qwen-image', providerLabel: 'Qwen', model: 'qwen-image-3.0-pro', modelLabel: 'Qwen', supported: true, enabled: true, isDefault: true, capabilities: {}, defaults: {}, projectConstraints: [], generationOptions: [ { key: 'size', label: '图片尺寸', type: 'size', required: true, options: [{ label: '竖屏', value: '1536*2688' }] }, { key: 'count', label: '数量', type: 'integer', required: true, min: 1, max: 1 } ] } ], videos: [ { type: 'video', provider: 'wan', providerLabel: 'Wan', model: 'wan3.0-video', modelLabel: 'Wan', supported: true, enabled: true, isDefault: true, capabilities: {}, defaults: {}, projectConstraints: [], generationOptions: [ { key: 'duration', label: '时长', type: 'integer', required: true, min: 2, max: 30, specialValues: [{ label: '自动', value: -1 }] }, { key: 'audio', label: '音轨', type: 'boolean', required: true } ] } ] } describe('项目配置保存前校验', () => { it('项目竖屏画布允许目录支持的方形参考图尺寸,不把两者强制绑定', () => { const draft = creativeProfileDraft(saved) const squareCatalog = structuredClone(catalog) squareCatalog.images[0]!.generationOptions[0]!.options = [{ label: '方形参考图', value: '2048*2048' }] draft.imageOptions.size = '2048*2048' expect(draft.aspectRatio).toBe('9:16') expect(creativeProfileIssues(draft, squareCatalog)).toEqual([]) }) it('保留但提示不再支持的历史尺寸,选择有效尺寸后可保存', () => { const draft = creativeProfileDraft(saved) expect(creativeProfileIssues(draft, catalog)).toHaveLength(1) expect(draft.imageOptions.size).toBe('1080*1920') draft.imageOptions.size = '1536*2688' expect(creativeProfileIssues(draft, catalog)).toEqual([]) }) it('拒绝无效数值与缺失必填参数,允许后端支持的特殊时长', () => { const draft = creativeProfileDraft(saved) draft.imageOptions.size = '1536*2688' draft.imageOptions.count = 2 delete draft.videoOptions.audio draft.videoOptions.duration = -1 expect(creativeProfileIssues(draft, catalog)).toHaveLength(2) draft.imageOptions.count = 1 draft.videoOptions.audio = false expect(creativeProfileIssues(draft, catalog)).toEqual([]) }) it('模型更新后拒绝目录中已不存在的旧模型', () => { const draft = creativeProfileDraft(saved) draft.imageOptions.size = '1536*2688' draft.imageModel = 'removed-image-model' expect(creativeProfileIssues(draft, catalog)).toHaveLength(1) }) })