67 lines
2.8 KiB
TypeScript
67 lines
2.8 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import { NSelect } from 'naive-ui'
|
|
import { readFileSync } from 'node:fs'
|
|
import { describe, expect, it } from 'vitest'
|
|
import GenerationModelControls from '../../../src/features/generation-config/components/GenerationModelControls.vue'
|
|
import type { GenerationModelCatalog } from '../../../src/features/generation-config/types'
|
|
|
|
const catalog: GenerationModelCatalog = {
|
|
defaults: { imageProvider: 'seedream', videoProvider: 'seedance' },
|
|
images: [
|
|
{
|
|
type: 'image',
|
|
provider: 'seedream',
|
|
providerLabel: 'Seedream',
|
|
model: 'seedream-model',
|
|
modelLabel: 'Seedream Model',
|
|
supported: true,
|
|
enabled: true,
|
|
isDefault: true,
|
|
capabilities: {},
|
|
generationOptions: [{ key: 'size', label: '尺寸', type: 'size', required: true }],
|
|
defaults: { size: '2K', watermark: false },
|
|
projectConstraints: []
|
|
},
|
|
{
|
|
type: 'image',
|
|
provider: 'qwen',
|
|
providerLabel: 'Qwen',
|
|
model: 'qwen-model',
|
|
modelLabel: 'Qwen Model',
|
|
supported: true,
|
|
enabled: true,
|
|
isDefault: false,
|
|
capabilities: {},
|
|
generationOptions: [{ key: 'size', label: '尺寸', type: 'size', required: true }],
|
|
defaults: { size: '1536*2560' },
|
|
projectConstraints: []
|
|
}
|
|
],
|
|
videos: []
|
|
}
|
|
|
|
describe('单次生成模型控件', () => {
|
|
it('字段采用双列栅格,控件与说明文字纵向排列并在移动端回落单列', () => {
|
|
const source = readFileSync('src/features/generation-config/components/GenerationModelControls.vue', 'utf8')
|
|
expect(source).toContain('class="generation-model-field-control"')
|
|
expect(source).toMatch(/\.generation-model-controls\s*\{[^}]*grid-cols-\[repeat\(2,_minmax\(0,_1fr\)\)\]/)
|
|
expect(source).toMatch(/\.generation-model-field-control\s*\{[^}]*flex-col[^}]*gap-1\.5/)
|
|
expect(source).toMatch(/@media \(max-width: 760px\)[\s\S]*?grid-cols-\[minmax\(0,_1fr\)\]/)
|
|
})
|
|
|
|
it('切换图片模型时只使用目标模型 defaults,不保留上一个模型参数', async () => {
|
|
const wrapper = mount(GenerationModelControls, {
|
|
props: {
|
|
type: 'image',
|
|
catalog,
|
|
provider: 'seedream',
|
|
options: { size: '2K', watermark: false },
|
|
aspectRatio: '9:16'
|
|
}
|
|
})
|
|
await wrapper.findComponent(NSelect).vm.$emit('update:value', 'qwen')
|
|
expect(wrapper.emitted('update:provider')?.at(-1)).toEqual(['qwen'])
|
|
expect(wrapper.emitted('update:options')?.at(-1)).toEqual([{ size: '1536*2560' }])
|
|
})
|
|
})
|