feat(short-drama-agent-front): 新增视觉风格骨架屏并优化参考图添加

This commit is contained in:
GJ committed 2026-10-11 00:01:24 +08:00
1 parent 3cc65aa056
commit 519b956808
11 files changed
+621 -242

No files matched your search

+3 -2
View File
@@ -48,14 +48,15 @@ describe('精简入口保留功能', () => {
expect(wrapper.text()).toContain('完整规则仍然保留')
})
it('风格高级字段收起不丢失保存值,展开后仍可修改', async () => {
it('风格分类始终显示,保存保留人工补充与硬约束', async () => {
wrapper = mount(StyleEditor, { props: { visualStyle: null, disabled: false } })
expect(wrapper.find('#style-constraints').exists()).toBe(true)
await wrapper.get('#style-constraints').setValue('["保留硬约束"]')
const fields = wrapper.findAllComponents(NInput)
fields.find(item => item.props('placeholder')?.includes('人物质感'))!.vm.$emit('update:value', '人物风格')
await flushPromises()
await wrapper.get('.n-collapse-item__header-main').trigger('click')
expect(wrapper.find('.n-collapse').exists()).toBe(false)
expect(wrapper.findAll('.style-category-fields .n-form-item')).toHaveLength(3)
await wrapper.get('form').trigger('submit')
await flushPromises()
expect(wrapper.emitted('save')).toMatchObject([
+5 -2
View File
@@ -17,6 +17,7 @@ import {
import { readFileSync, readdirSync } from 'node:fs'
import { useTheme } from '@/composables/useTheme'
import { readAllStyles } from '@/testing/styles'
import StyleImages from '@/features/visual-style/components/StyleImages.vue'
let wrapper: VueWrapper | undefined
afterEach(() => {
@@ -277,9 +278,11 @@ describe('全站平面主题', () => {
expect(projects).not.toMatch(/<NButton\b[^>]*\bcircle\b/)
})
it('风格参考图操作按钮与输入行对齐,缩略图在宽屏下保持紧凑', () => {
it('风格参考图页内只保留添加入口,缩略图在宽屏下保持紧凑', () => {
const css = readAllStyles()
expect(css).toMatch(/\.style-image-submit\s*\{[^}]*margin-top:\s*29px;/)
wrapper = mount(StyleImages, { props: { projectId: 'theme-test-project', images: [], disabled: false } })
expect(wrapper.find('form').exists()).toBe(false)
expect(wrapper.findAll('button').map(button => button.text())).toEqual(['从资产库添加', '通过链接添加'])
expect(css).toMatch(
/\.style-image-list\s*\{[^}]*display:\s*grid;[^}]*grid-template-columns:\s*repeat\(auto-fill, minmax\(min\(220px, 100%\), 260px\)\);[^}]*gap:\s*16px;/
)
+41 -8
View File
@@ -127,18 +127,18 @@ describe('统一的 Naive UI 表单校验', () => {
expect(wrapper.emitted('generate')).toBeUndefined()
})
it('折叠后的非法 JSON 仍拦截保存并展开错误,修正后保留草稿正常提交', async () => {
it('分类风格始终显示,非法 JSON 拦截保存,修正后保留草稿正常提交', async () => {
wrapper = mount(StyleEditor, { attachTo: document.body, props: { visualStyle: null, disabled: false } })
await flushPromises()
expect(button('分类风格与硬约束').getAttribute('aria-expanded')).toBe('true')
expect(wrapper.find('button[aria-expanded]').exists()).toBe(false)
expect(wrapper.get('.style-category-section h3').text()).toBe('分类风格与硬约束')
expect(wrapper.findAll('.style-category-fields .n-form-item')).toHaveLength(3)
await input('#style-name', '手工风格')
await input('#style-constraints', '{"invalid":true}')
button('分类风格与硬约束').click()
await flushPromises()
await submit()
expect(wrapper.emitted('save')).toBeUndefined()
expect(feedback()).toContain('请输入 JSON 字符串数组')
expect(button('分类风格与硬约束').getAttribute('aria-expanded')).toBe('true')
expect(wrapper.get('#style-constraints').isVisible()).toBe(true)
await input('#style-constraints', '["真人写实"]')
await submit()
expect(wrapper.emitted('save')?.[0]?.[0]).toMatchObject({ name: '手工风格', hardConstraints: ['真人写实'] })
@@ -149,6 +149,10 @@ describe('统一的 Naive UI 表单校验', () => {
attachTo: document.body,
props: { projectId: 'form-test-project', images: [], disabled: false }
})
expect(document.querySelector('[aria-label="风格图片地址"]')).toBeNull()
expect(wrapper.text()).not.toContain('先保存视觉风格')
button('通过链接添加').click()
await flushPromises()
await input('[aria-label="风格图片地址"]', 'javascript:alert(1)')
await input('[aria-label="风格图片排序"]', '1.5')
await submit()
@@ -191,7 +195,7 @@ describe('统一的 Naive UI 表单校验', () => {
})
expect(fetcher).not.toHaveBeenCalled()
button('从资产库选择').click()
button('从资产库添加').click()
await flushPromises()
expect(fetcher).toHaveBeenCalledWith(
'/api/projects/form-test-project/assets',
@@ -201,8 +205,13 @@ describe('统一的 Naive UI 表单校验', () => {
expect(option.textContent).toContain('人物质感参考')
option.click()
await flushPromises()
button('登记为整体参考图').click()
await flushPromises()
await input('[aria-label="风格图片排序"]', '1.5')
await submit()
expect(feedback()).toContain('排序须为整数')
expect(wrapper.emitted('add')).toBeUndefined()
await input('[aria-label="风格图片排序"]', '-1')
await submit()
expect(document.querySelector('[aria-label="风格图片地址"]')).toBeNull()
expect(wrapper.emitted('add')?.[0]?.[0]).toMatchObject({
projectAssetId: 'asset-db-1',
category: 'overall',
@@ -210,6 +219,30 @@ describe('统一的 Naive UI 表单校验', () => {
})
})
it('未保存风格时禁用两个入口,资产读取失败可在弹窗重试', async () => {
const fetcher = vi
.fn<typeof fetch>()
.mockResolvedValueOnce(new Response('{"message":"素材读取失败"}', { status: 500 }))
.mockResolvedValue(new Response('{"data":[]}'))
vi.stubGlobal('fetch', fetcher)
wrapper = mount(StyleImages, {
attachTo: document.body,
props: { projectId: 'form-test-project', images: [], disabled: true, hasStyle: false }
})
expect(wrapper.text()).toContain('先保存视觉风格')
expect(button('从资产库添加').disabled).toBe(true)
expect(button('通过链接添加').disabled).toBe(true)
await wrapper.setProps({ disabled: false, hasStyle: true })
button('从资产库添加').click()
await flushPromises()
expect(document.querySelector('.app-dialog')?.textContent).toContain('素材读取失败')
expect(button('添加参考图').disabled).toBe(true)
button('重试读取素材').click()
await flushPromises()
expect(document.querySelector('.app-dialog')?.textContent).toContain('资产库暂无图片')
expect(fetcher).toHaveBeenCalledTimes(2)
})
it('异步验证期间切换对象或重复提交不会执行旧动作', async () => {
let finish: (() => void) | undefined
const model = reactive({ text: '有效输入' })
+8 -2
View File
@@ -44,11 +44,17 @@ describe('管理后台组件边界', () => {
expect(adminCss).toMatch(/html,\s*body,\s*#app,\s*\.app-provider\s*\{[^}]*overflow:\s*hidden/)
expect(adminCss).toMatch(/\.workspace-page\s*\{[^}]*min-height:\s*0;[^}]*overflow:\s*hidden/)
})
it('仅手机阅读工作区允许项目内容整体滚动,其余面板保持独立滚动', () => {
it('项目整体滚动仅用于手机阅读,弹窗素材选择保留有界滚动', () => {
const css = readAllStyles()
const mobileReading = /\.project-view:has\(\.mobile-reading-workspace\)\s*\{[^}]*\}/
expect(css.match(mobileReading)?.[0]).toContain('overflow-y: auto;')
expect(css.replace(mobileReading, '')).not.toMatch(/overflow(?:-[xy])?\s*:\s*(?:auto|scroll)\b/)
/** 素材列表是弹窗内的局部滚动容器,不改变项目工作区滚动边界。 */
const assetPicker = /\.style-asset-picker\s*\{[^}]*\}/
expect(css.match(assetPicker)?.[0]).toContain('max-height: 280px;')
expect(css.match(assetPicker)?.[0]).toContain('overflow-y: auto;')
expect(css.replace(mobileReading, '').replace(assetPicker, '')).not.toMatch(
/overflow(?:-[xy])?\s*:\s*(?:auto|scroll)\b/
)
})
it('历史缩略图尺寸在非分层样式中覆盖 Naive 按钮,原图不能撑大预览或横向条目', () => {
// happy-dom 不计算几何;专门保护此前失效的层叠和固定尺寸约束。