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 不计算几何;专门保护此前失效的层叠和固定尺寸约束。
+43 -39
View File
@@ -106,48 +106,52 @@ async function openProject(initialPath: string) {
}
describe('剧本完成前的下游访问限制', () => {
it('拆解首次读取显示骨架,刷新保留已有内容,切换项目完成后仍遵守访问限制', async () => {
/** 延迟真实查询入口,覆盖初次读取、后台刷新和跨项目读取三个阶段。 */
let resolveDetail!: (value: ProjectDetail) => void
let pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
vi.spyOn(projectsApi, 'detail').mockImplementation(() => pending)
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, id === 'skeleton-first'))
const { router, mounted } = await openProject('/projects/skeleton-first/breakdown')
expect(wrapper!.get('.breakdown-skeleton').attributes('aria-busy')).toBe('true')
expect(wrapper!.find('.workspace-loading').exists()).toBe(false)
expect(wrapper!.get('.project-title').text()).toBe('')
expect(mounted).not.toHaveBeenCalled()
it.each(['breakdown', 'visual-style'] as const)(
'%s 首次读取显示骨架,刷新保留已有内容,切换项目完成后仍遵守访问限制',
async section => {
/** 延迟真实查询入口,覆盖初次读取、后台刷新和跨项目读取三个阶段。 */
let resolveDetail!: (value: ProjectDetail) => void
let pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
vi.spyOn(projectsApi, 'detail').mockImplementation(() => pending)
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, id === 'skeleton-first'))
const { router, mounted } = await openProject(`/projects/skeleton-first/${section}`)
const skeleton = section === 'breakdown' ? '.breakdown-skeleton' : '.visual-style-skeleton'
expect(wrapper!.get(skeleton).attributes('aria-busy')).toBe('true')
expect(wrapper!.find('.workspace-loading').exists()).toBe(false)
expect(wrapper!.get('.project-title').text()).toBe('')
expect(mounted).not.toHaveBeenCalled()
resolveDetail(project('skeleton-first', 'completed'))
await flushPromises()
expect(wrapper!.find('.breakdown-skeleton').exists()).toBe(false)
expect(wrapper!.get('.workspace-probe').text()).toBe('breakdown')
resolveDetail(project('skeleton-first', 'completed'))
await flushPromises()
expect(wrapper!.find(skeleton).exists()).toBe(false)
expect(wrapper!.get('.workspace-probe').text()).toBe(section)
pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
await wrapper!.get('.probe-refresh').trigger('click')
expect(wrapper!.find('.breakdown-skeleton').exists()).toBe(false)
expect(wrapper!.get('.workspace-probe').text()).toBe('breakdown')
resolveDetail(project('skeleton-first', 'completed'))
await flushPromises()
pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
await wrapper!.get('.probe-refresh').trigger('click')
expect(wrapper!.find(skeleton).exists()).toBe(false)
expect(wrapper!.get('.workspace-probe').text()).toBe(section)
resolveDetail(project('skeleton-first', 'completed'))
await flushPromises()
pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
await router.push('/projects/skeleton-second/breakdown')
await flushPromises()
expect(wrapper!.find('.breakdown-skeleton').exists()).toBe(true)
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
resolveDetail(project('skeleton-second', 'draft'))
await flushPromises()
expect(wrapper!.find('.breakdown-skeleton').exists()).toBe(false)
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本创作')
expect(mounted).toHaveBeenCalledExactlyOnceWith('breakdown')
})
pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
await router.push(`/projects/skeleton-second/${section}`)
await flushPromises()
expect(wrapper!.find(skeleton).exists()).toBe(true)
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
resolveDetail(project('skeleton-second', 'draft'))
await flushPromises()
expect(wrapper!.find(skeleton).exists()).toBe(false)
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本创作')
expect(mounted).toHaveBeenCalledExactlyOnceWith(section)
}
)
it('切换图库与其他工作区不自动重复读取项目状态', async () => {
vi.useFakeTimers()
+102 -6
View File
@@ -26,6 +26,7 @@ import SubjectImagesPage from '@/features/subject-images/SubjectImagesPage.vue'
import { formFixture, imageFixture } from '@/features/subject-images/testing/fixtures'
import { getImageSession } from '@/features/subject-images/model'
import VisualStylePage from '@/features/visual-style/VisualStylePage.vue'
import { visualStyleApi } from '@/features/visual-style/api'
import SubjectIdentityPage from '@/features/subject-identity/SubjectIdentityPage.vue'
import { styleFixture, styleImageFixture } from '@/features/visual-style/testing/fixtures'
import { identityFixture, identityImageFixture } from '@/features/subject-identity/testing/fixtures'
@@ -303,6 +304,64 @@ describe('内容级滚动下的生产反馈', () => {
})
describe('视觉风格与主体身份工作区', () => {
it('风格首读显示骨架,失败后展示重试,恢复后分类与规则始终可见', async () => {
/** 延迟首次响应,确认骨架不会混入尚未创建或空参考图提示。 */
let rejectStyle!: (error: Error) => void
vi.spyOn(visualStyleApi, 'get')
.mockImplementationOnce(
() =>
new Promise((_resolve, reject) => {
rejectStyle = reject
})
)
.mockResolvedValue(styleFixture())
await mountAssets('style')
expect(wrapper!.get('.visual-style-skeleton').attributes('aria-busy')).toBe('true')
expect(wrapper!.find('#style-prompt').exists()).toBe(false)
expect(wrapper!.text()).not.toContain('尚无风格参考图')
rejectStyle(new Error('风格读取失败'))
await flushPromises()
expect(wrapper!.find('.visual-style-skeleton').exists()).toBe(false)
expect(wrapper!.get('[role="alert"]').text()).toContain('风格读取失败')
expect(wrapper!.text()).not.toContain('视觉风格已准备好')
expect(wrapper!.find('.style-images-panel').exists()).toBe(false)
button('重试读取').click()
await flushPromises()
expect(wrapper!.find('#style-prompt').exists()).toBe(true)
expect(wrapper!.get('.visual-style-rules').text()).toContain('中国人物选角基线')
expect(wrapper!.find('.n-collapse').exists()).toBe(false)
expect(wrapper!.findAll('.style-category-fields textarea')).toHaveLength(3)
})
it('刷新已有风格时保留编辑器、参考图和未保存的分类草稿', async () => {
const image = styleImageFixture()
/** 图片启停后的刷新延迟返回,保护现有内容与人工草稿。 */
let resolveStyle!: (value: ReturnType<typeof styleFixture>) => void
vi.spyOn(visualStyleApi, 'get')
.mockResolvedValueOnce(styleFixture({ images: [image] }))
.mockImplementationOnce(
() =>
new Promise(resolve => {
resolveStyle = resolve
})
)
vi.spyOn(visualStyleApi, 'setImageEnabled').mockResolvedValue({ ...image, enabled: false })
await mountAssets('style')
const editor = wrapper!.get('.style-category-section').element
await wrapper!.get('textarea[aria-label="人物风格与选角背景"]').setValue('人物风格人工草稿')
button('停用').click()
await flushPromises()
expect(wrapper!.find('.visual-style-skeleton').exists()).toBe(false)
expect(wrapper!.get('.style-category-section').element).toBe(editor)
resolveStyle(styleFixture({ images: [{ ...image, enabled: false }] }))
await flushPromises()
expect((wrapper!.get('textarea[aria-label="人物风格与选角背景"]').element as HTMLTextAreaElement).value).toBe(
'人物风格人工草稿'
)
expect(button('AI 重新生成风格').disabled).toBe(true)
expect(button('启用').disabled).toBe(false)
})
it.each([
{ locked: null, label: '尚未创建', action: 'AI 生成风格', disabled: false },
{ locked: false, label: '未锁定', action: 'AI 重新生成风格', disabled: false },
@@ -458,20 +517,23 @@ describe('视觉风格与主体身份工作区', () => {
)
})
it('风格图拒绝危险 URL,登记只传已有地址及分类排序', async () => {
it('链接添加拒绝危险 URL,只传已有地址及分类排序,成功后关闭并清空弹窗', async () => {
const image = styleImageFixture()
const fetcher = vi
.fn<typeof fetch>()
.mockImplementation(async (_url, init) => jsonResponse(init?.method === 'POST' ? image : styleFixture()))
stubFetch(fetcher)
await mountAssets('style')
await wrapper!.get('[aria-label="风格图片地址"]').setValue('javascript:alert(1)')
button('登记参考图').click()
expect(wrapper!.find('[aria-label="风格图片地址"]').exists()).toBe(false)
button('通过链接添加').click()
await flushPromises()
await new DOMWrapper(document.body).get('[aria-label="风格图片地址"]').setValue('javascript:alert(1)')
button('添加参考图').click()
await flushPromises()
expect(document.querySelector('.n-form-item-feedback--error')?.textContent).toContain('请填写有效的')
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'POST')).toBe(false)
await wrapper!.get('[aria-label="风格图片地址"]').setValue('/storage/style.png')
button('登记参考图').click()
await new DOMWrapper(document.body).get('[aria-label="风格图片地址"]').setValue('/storage/style.png')
button('添加参考图').click()
await flushPromises()
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
expect(post[0]).toBe('/api/projects/page-test-project/visual-style/images')
@@ -482,7 +544,41 @@ describe('视觉风格与主体身份工作区', () => {
enabled: true,
sortOrder: 0
})
expect((wrapper!.get('[aria-label="风格图片地址"]').element as HTMLInputElement).value).toBe('')
expect(document.querySelector('.app-dialog')).toBeNull()
button('通过链接添加').click()
await flushPromises()
expect(document.querySelector<HTMLInputElement>('[aria-label="风格图片地址"]')!.value).toBe('')
})
it('参考图添加失败保留弹窗、来源与设置,显式重试成功才关闭', async () => {
let rejectAdd = true
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (_url, init) => {
if (init?.method === 'POST')
return rejectAdd
? new Response('{"message":"参考图保存失败"}', { status: 500 })
: jsonResponse(styleImageFixture())
return jsonResponse(styleFixture())
})
stubFetch(fetcher)
await mountAssets('style')
button('通过链接添加').click()
await flushPromises()
const body = new DOMWrapper(document.body)
await body.get('[aria-label="风格图片地址"]').setValue('/storage/draft.png')
await body.get('[aria-label="风格图片排序"]').setValue('-2')
button('添加参考图').click()
await flushPromises()
expect(document.querySelector('.app-dialog')?.textContent).toContain('参考图保存失败')
expect(document.querySelector<HTMLInputElement>('[aria-label="风格图片地址"]')!.value).toBe(
'/storage/draft.png'
)
expect(document.querySelector<HTMLInputElement>('[aria-label="风格图片排序"]')!.value).toBe('-2')
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1)
rejectAdd = false
button('添加参考图').click()
await flushPromises()
expect(document.querySelector('.app-dialog')).toBeNull()
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(2)
})
it('AI 确认取消后重新打开必须再次确认,不能复用上次勾选', async () => {