feat(short-drama-agent-front): 新增视觉风格骨架屏并优化参考图添加
This commit is contained in:
1 parent
3cc65aa056
commit
519b956808
11 files changed
+621
-242
No files matched your search
@@ -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 () => {
|
||||
|
||||
Reference in new issue
Block a user