feat(short-drama-agent-front): 完善主体身份骨架屏与交互反馈

This commit is contained in:
GJ committed 2026-10-11 17:23:14 +08:00
1 parent 5fa1c251a9
commit dd0bd79a35
19 files changed
+1552 -419

No files matched your search

+66 -2
View File
@@ -106,7 +106,66 @@ async function openProject(initialPath: string) {
}
describe('剧本完成前的下游访问限制', () => {
it.each(['breakdown', 'visual-style'] as const)(
it('身份请求加载、成功和失败均使用临时消息,切换主体不遗留横幅', async () => {
vi.useFakeTimers()
const id = 'identity-message-test'
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
const operation = getOperation(id)
Object.assign(operation, { pending: false, label: 'AI 生成主体身份', error: '', notice: '旧成功提示' })
const { router } = await openProject(`/projects/${id}/subject-identity`)
expect(wrapper!.text()).not.toContain('旧成功提示')
expect(document.querySelector('.n-message')).toBeNull()
Object.assign(operation, { pending: true, notice: '' })
await flushPromises()
expect(wrapper!.find('.project-notices').exists()).toBe(false)
expect(document.querySelector('.n-message--loading-type')!.textContent).toContain('AI 生成主体身份,请稍候')
await router.replace({ query: { subjectId: 'second-subject' } })
Object.assign(operation, {
pending: false,
notice: '请求已返回,正在重新读取后端状态;最终结果以下方记录为准。'
})
await flushPromises()
expect(document.querySelector('.n-message--success-type')!.textContent).toContain('身份文本已生成并保存')
expect(wrapper!.find('.project-notices').exists()).toBe(false)
expect(operation.notice).toBe('')
await vi.advanceTimersByTimeAsync(4000)
await flushPromises()
expect(document.querySelector('.n-message')).toBeNull()
await router.replace({ query: { subjectId: 'third-subject' } })
await flushPromises()
expect(document.querySelector('.n-message')).toBeNull()
expect(wrapper!.find('.project-notices').exists()).toBe(false)
operation.error = '模型不可用,请稍后重试'
await flushPromises()
expect(wrapper!.find('.operation-guide').exists()).toBe(false)
expect(document.querySelector('.n-message--error-type')!.textContent).toContain('模型不可用')
Object.assign(operation, { error: '', notice: '', pending: false })
})
it('图片校验未通过显示警告而非成功,关闭消息后不遗留校验结果块', async () => {
vi.useFakeTimers()
const id = 'identity-warning-test'
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
await openProject(`/projects/${id}/subject-identity`)
const operation = getOperation(id)
Object.assign(operation, {
label: '校验林夏身份图片',
noticeType: 'warning',
notice: '林夏的身份图片校验未通过:面部模糊'
})
await flushPromises()
expect(document.querySelector('.n-message--warning-type')!.textContent).toContain('校验未通过:面部模糊')
expect(document.querySelector('.n-message--success-type')).toBeNull()
expect(wrapper!.find('.project-notices').exists()).toBe(false)
expect(operation).toMatchObject({ notice: '', noticeType: null })
await vi.advanceTimersByTimeAsync(9000)
await flushPromises()
expect(document.querySelector('.n-message')).toBeNull()
})
it.each(['breakdown', 'visual-style', 'subject-identity'] as const)(
'%s 首次读取显示骨架,刷新保留已有内容,切换项目完成后仍遵守访问限制',
async section => {
/** 延迟真实查询入口,覆盖初次读取、后台刷新和跨项目读取三个阶段。 */
@@ -118,7 +177,12 @@ describe('剧本完成前的下游访问限制', () => {
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'
const skeleton =
section === 'subject-identity'
? '.subject-identity-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('')
@@ -0,0 +1,43 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import IdentityEditor from '@/features/subject-identity/components/IdentityEditor.vue'
import { identityFixture } from '@/features/subject-identity/testing/fixtures'
describe('主体身份保存状态', () => {
it.each([
{ name: '未创建身份', identity: null },
{ name: '空身份记录', identity: identityFixture({ description: null, generationPrompt: '' }) },
{ name: '仅空白字符', identity: identityFixture({ description: ' ', generationPrompt: '\n' }) }
])('$name 不显示已保存,输入后可保存,撤销输入后禁止空提交', async ({ identity }) => {
const wrapper = mount(IdentityEditor, { props: { identity, disabled: false, module: 'prop' } })
try {
const actions = wrapper.get('.page-form-actions')
expect(actions.text()).toBe('保存主体身份')
expect(actions.text()).not.toContain('已保存')
expect(actions.get('button').attributes('disabled')).toBeDefined()
await wrapper.get('#identity-description').setValue('竹编鱼篓,固定圆筒结构')
expect(actions.text()).toBe('保存主体身份')
expect(actions.get('button').attributes('disabled')).toBeUndefined()
await wrapper.get('#identity-description').setValue(identity?.description ?? '')
expect(actions.text()).toBe('保存主体身份')
expect(actions.text()).not.toContain('已保存')
} finally {
wrapper.unmount()
}
})
it('后端已有身份文本才显示已保存,修改后的草稿显示保存操作', async () => {
const wrapper = mount(IdentityEditor, {
props: { identity: identityFixture(), disabled: false, module: 'character' }
})
try {
expect(wrapper.get('.page-form-actions').text()).toBe('已保存')
expect(wrapper.get('.page-form-actions button').text()).toBe('已保存')
await wrapper.get('#identity-prompt').setValue('修改中的核心提示词')
expect(wrapper.get('.page-form-actions').text()).toBe('保存主体身份')
expect(wrapper.get('.page-form-actions button').text()).toBe('保存主体身份')
} finally {
wrapper.unmount()
}
})
})
@@ -1,8 +1,8 @@
import { imageCatalog, generationProfile } from '../../fixtures/generation'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { NImage, NScrollbar } from 'naive-ui'
import { AssetImage } from '@/components/ui'
import { NButton, NImage, NScrollbar } from 'naive-ui'
import { AppDialog, AssetImage } from '@/components/ui'
import IdentityImageDialog from '@/features/subject-identity/components/IdentityImageDialog.vue'
import IdentityGallery from '@/features/subject-identity/components/IdentityGallery.vue'
import CastingCandidateDialog from '@/features/subject-identity/components/CastingCandidateDialog.vue'
@@ -71,6 +71,8 @@ describe('身份图与母版契约', () => {
expect(images).toHaveLength(3)
expect(images.map(image => image.props('objectFit'))).toEqual(['contain', 'cover', 'cover'])
expect(images.map(image => image.props('previewDisabled'))).toEqual([false, true, true])
expect(wrapper.find('a[target="_blank"]').exists()).toBe(false)
expect(wrapper.text()).not.toContain('打开原图')
await wrapper.get('[aria-label="查看身份图片 front"] img').trigger('click')
await flushPromises()
expect(wrapper.get('[aria-label="查看身份图片 front"]').attributes('aria-pressed')).toBe('true')
@@ -86,19 +88,21 @@ describe('身份图与母版契约', () => {
expect(wrapper.emitted('anchor')).toBeUndefined()
})
it('身份图库使用精简资产,不展示已移除的提示词和启停状态', () => {
it('身份图库使用精简资产,不展示已移除的提示词、模型信息和启停状态', () => {
wrapper = mount(IdentityGallery, {
props: {
subjectName: '林夏',
module: 'character',
identityLocked: true,
disabled: false,
images: [identityImageFixture()]
images: [identityImageFixture({ provider: 'qwen-image', model: 'qwen-image-3.0-pro' })]
}
})
expect(wrapper.text()).toContain('当前身份母版')
expect(wrapper.text()).not.toContain('本次实际提示词')
expect(wrapper.text()).not.toContain('停用')
expect(wrapper.text()).not.toContain('qwen-image')
expect(wrapper.text()).toContain('创建于')
})
it('全部历史记录显示在预览下方,候选、辅助、失败和进行中图片均可切换查看', async () => {
@@ -200,9 +204,10 @@ describe('身份图与母版契约', () => {
})
button('确认选角并锁定').click()
await flushPromises()
expect(document.querySelector('[role="dialog"][aria-label="确认选角并锁定"]')).not.toBeNull()
expect(button('确认演员选择').disabled).toBe(false)
await wrapper.get('[aria-label="查看身份图片 candidate-b"]').trigger('click')
expect(wrapper.text()).not.toContain('确认选择这张图片作为正式演员')
expect(wrapper.findComponent(AppDialog).props('open')).toBe(false)
expect(wrapper.emitted('anchor')).toBeUndefined()
button('确认选角并锁定').click()
await flushPromises()
@@ -373,11 +378,42 @@ describe('身份图与母版契约', () => {
})
button('确认选角并锁定').click()
await flushPromises()
expect(document.body.textContent).toContain('同一事务中切换身份母版并锁定 Identity')
expect(document.body.textContent).toContain('作为 林夏 的角色母版并锁定身份')
button('确认演员选择').click()
expect(wrapper.emitted('anchor')).toEqual([['identity-image-1']])
})
it('图片操作加载只对应提交目标,不能重复确认,切换图片不会错误显示加载', async () => {
wrapper = mount(IdentityGallery, {
attachTo: document.body,
props: {
subjectName: '林夏',
module: 'character',
identityLocked: false,
disabled: false,
images: ['first', 'second'].map(id => identityImageFixture({ id, isAnchor: false }))
}
})
await wrapper.setProps({
pendingOperation: { projectId: 'project-1', subjectId: 'subject-1', imageId: 'first', kind: 'confirm' }
})
const confirm = wrapper.findAllComponents(NButton).find(item => item.text() === '确认选角并锁定')!
expect(confirm.props('loading')).toBe(true)
expect(button('确认选角并锁定').disabled).toBe(true)
button('确认选角并锁定').click()
expect(wrapper.emitted('anchor')).toBeUndefined()
await wrapper.get('[aria-label="查看身份图片 second"]').trigger('click')
expect(confirm.props('loading')).toBe(false)
await wrapper.setProps({
pendingOperation: { projectId: 'project-1', subjectId: 'subject-1', imageId: 'second', kind: 'validate' }
})
const validate = wrapper.findAllComponents(NButton).find(item => item.text() === '校验此身份图片')!
expect(validate.props('loading')).toBe(true)
expect(button('校验此身份图片').disabled).toBe(true)
await wrapper.setProps({ pendingOperation: null })
expect(validate.props('loading')).toBe(false)
})
it('选角候选发送当前图片 Provider 与动态参数,不携带旧宽高字段', async () => {
wrapper = mount(CastingCandidateDialog, {
attachTo: document.body,
@@ -422,7 +458,7 @@ describe('身份图与母版契约', () => {
expect(document.body.textContent).toContain('不会复用当前身份母版')
document.querySelector<HTMLInputElement>('#casting-candidate-cost')!.click()
await flushPromises()
button('确认生成候选').click()
button('AI 生成角色候选图').click()
await flushPromises()
expect(wrapper.emitted('generate')).toEqual([
[{ provider: 'qwen-image', generationOptions: { size: '1536*2688' } }]
@@ -1,6 +1,18 @@
import { describe, expect, it, vi } from 'vitest'
import { getOperation, runOperation } from '@/features/workflows/operations'
/**
* 根据真实校验值决定消息,不能只依据 Promise 成功。
* @param result 后端业务校验结果
* @returns 与通过状态相符的临时反馈
*/
function validationFeedback(result: { passed: boolean }) {
return {
type: result.passed ? ('success' as const) : ('warning' as const),
content: result.passed ? '身份图片校验通过' : '身份图片校验未通过'
}
}
describe('项目级长请求互斥', () => {
it('同一项目不同时执行两个 graph,错误不伪装成功', async () => {
let fail!: (reason: Error) => void
@@ -17,4 +29,36 @@ describe('项目级长请求互斥', () => {
expect(await first).toBe(false)
expect(getOperation('operation-test')).toMatchObject({ pending: false, error: '连接中断', notice: '' })
})
it('HTTP 成功但业务校验未通过时保留警告语义,再次通过时更新结果', async () => {
const projectId = 'operation-validation-test'
expect(await runOperation(projectId, '校验', async () => ({ passed: false }), validationFeedback)).toBe(true)
expect(getOperation(projectId)).toMatchObject({
noticeType: 'warning',
notice: '身份图片校验未通过',
pending: false
})
expect(await runOperation(projectId, '校验', async () => ({ passed: true }), validationFeedback)).toBe(true)
expect(getOperation(projectId)).toMatchObject({ noticeType: 'success', notice: '身份图片校验通过' })
expect(
await runOperation(
projectId,
'校验',
async () => {
throw new Error('服务不可用')
},
validationFeedback
)
).toBe(false)
expect(getOperation(projectId)).toMatchObject({ noticeType: null, notice: '', error: '服务不可用' })
})
it('异步任务提交只提示已提交,不提前提示生成完成', async () => {
const projectId = 'operation-submission-test'
await runOperation(projectId, '提交图片生成', async () => ({ status: 'pending' }), {
type: 'info',
content: '任务已提交生成'
})
expect(getOperation(projectId)).toMatchObject({ noticeType: 'info', notice: '任务已提交生成' })
})
})
+303 -5
View File
@@ -28,6 +28,9 @@ 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 IdentityGallery from '@/features/subject-identity/components/IdentityGallery.vue'
import { subjectIdentityApi } from '@/features/subject-identity/api'
import { subjectImagesApi } from '@/features/subject-images/api'
import { styleFixture, styleImageFixture } from '@/features/visual-style/testing/fixtures'
import { identityFixture, identityImageFixture } from '@/features/subject-identity/testing/fixtures'
import { getIdentitySession } from '@/features/subject-identity/model'
@@ -213,7 +216,7 @@ afterEach(() => {
Object.assign(getStoryboardSession(fixture.id), { receipt: null, prompts: {}, regeneratedEpisodes: {} })
getImageSession(fixture.id).receipt = null
getImageSession(fixture.id).promptReceipt = null
Object.assign(getOperation(fixture.id), { pending: false, label: '', error: '', notice: '' })
Object.assign(getOperation(fixture.id), { pending: false, label: '', error: '', notice: '', noticeType: null })
})
describe('内容级滚动下的生产反馈', () => {
@@ -304,6 +307,217 @@ describe('内容级滚动下的生产反馈', () => {
})
describe('视觉风格与主体身份工作区', () => {
it('当前主体已确认但其它角色未完成时,隐藏形态入口;保存后按新阶段状态开放', async () => {
/** 当前主体已锁定,其它角色仍未确认,用真实项目准入规则约束页面入口。 */
const saved = identityFixture({ isLocked: true })
vi.spyOn(subjectIdentityApi, 'get').mockResolvedValue(saved)
vi.spyOn(subjectIdentityApi, 'save').mockImplementation(async (_id, input) => ({ ...saved, ...input }))
vi.spyOn(subjectIdentityApi, 'listImages').mockResolvedValue([identityImageFixture()])
vi.spyOn(subjectIdentityApi, 'castingReadiness').mockResolvedValue({
total: 0,
ready: 0,
missingIdentity: 0,
missingAnchor: 0,
candidatePending: 0,
unlocked: 0,
locked: 0,
items: []
})
stubFetch(
vi
.fn<typeof fetch>()
.mockImplementation(async url =>
jsonResponse(String(url).endsWith('/subject-forms') ? [formFixture()] : styleFixture())
)
)
const provided = await mountAssets('identity')
provided.data.value!.stageReadiness.identity = { ready: false, reason: '还有角色身份需要确认' }
await flushPromises()
expect(wrapper!.get('.identity-next-action').text()).toContain('还有角色身份需要确认')
expect(wrapper!.get('.identity-next-action').find('button').exists()).toBe(false)
expect(wrapper!.get('.identity-subject-forms').text()).not.toContain('查看此主体形态图片')
expect(wrapper!.find('a[href*="/subject-images"]').exists()).toBe(false)
vi.mocked(provided.refreshStageReadiness).mockImplementation(async () => {
provided.data.value!.stageReadiness.identity = { ready: true, reason: null }
})
await wrapper!.get('#identity-description').setValue('保存后仍保留已确认母版')
button('保存主体身份').click()
await flushPromises()
expect(provided.refreshStageReadiness).toHaveBeenCalledOnce()
expect(button('查看形态图片').disabled).toBe(false)
expect(wrapper!.get('.identity-detail a[href*="/subject-images"]').attributes('href')).toContain(
'subjectRef=@CH0001'
)
})
it('生成进度与失败提示位于两栏上方,切换主体后不会保留其它主体的状态,完成后隐藏', async () => {
/** 两个主体分别处于生成中与失败状态,所有查询均使用隔离的测试响应。 */
const first = formFixture()
const second = { ...formFixture(), id: 'second-form', subjectId: 'second-subject', images: [] }
second.subject = { ...second.subject, id: second.subjectId, name: '第二个主体', ref: '@CH0002' }
vi.spyOn(subjectIdentityApi, 'get').mockImplementation(async id =>
identityFixture({ id: `identity-${id}`, subjectId: id })
)
vi.spyOn(subjectIdentityApi, 'listImages').mockImplementation(async id => [
identityImageFixture({
identityId: `identity-${id}`,
status: id === first.subjectId ? 'generating' : 'failed',
isAnchor: false,
imageUrl: null,
error: id === first.subjectId ? null : '模型暂时不可用'
})
])
vi.spyOn(subjectIdentityApi, 'castingReadiness').mockResolvedValue({
total: 0,
ready: 0,
missingIdentity: 0,
missingAnchor: 0,
candidatePending: 0,
unlocked: 0,
locked: 0,
items: []
})
stubFetch(
vi
.fn<typeof fetch>()
.mockImplementation(async url =>
jsonResponse(String(url).endsWith('/subject-forms') ? [first, second] : styleFixture())
)
)
await mountAssets('identity')
const feedback = wrapper!.get('.identity-generation-feedback')
const workspace = wrapper!.get('.identity-workspace')
expect(feedback.element.closest('.identity-workspace-region')).toBe(
wrapper!.get('.identity-workspace-region').element
)
expect(feedback.element.closest('.identity-detail')).toBeNull()
expect(feedback.element.compareDocumentPosition(workspace.element) & 4).toBe(4)
expect(feedback.text()).toContain('林知夏 的身份图片正在生成')
await wrapper!
.findAll('.identity-subject-item')
.find(item => item.text().includes('第二个主体'))!
.trigger('click')
await flushPromises()
expect(wrapper!.get('.identity-generation-feedback').text()).toContain('模型暂时不可用')
expect(wrapper!.get('.identity-generation-feedback').text()).not.toContain('林知夏 的身份图片正在生成')
expect(wrapper!.findAll('.identity-generation-feedback')).toHaveLength(1)
vi.mocked(subjectIdentityApi.listImages).mockResolvedValue([
identityImageFixture({ identityId: `identity-${second.subjectId}`, status: 'completed' })
])
await wrapper!
.get('.identity-detail')
.findAll('button')
.find(item => item.text() === '刷新身份')!
.trigger('click')
await flushPromises()
expect(wrapper!.find('.identity-generation-feedback').exists()).toBe(false)
})
it('主体目录与详情分别显示骨架,查询失败结束占位并可重试恢复', async () => {
/** 分别阻塞目录与详情,避免将未完成查询误显示为空身份。 */
let rejectCatalog!: (error: Error) => void
let rejectDetail!: (error: Error) => void
vi.spyOn(subjectImagesApi, 'listForms')
.mockImplementationOnce(
() =>
new Promise((_resolve, reject) => {
rejectCatalog = reject
})
)
.mockResolvedValue([formFixture()])
vi.spyOn(subjectIdentityApi, 'get')
.mockImplementationOnce(
() =>
new Promise((_resolve, reject) => {
rejectDetail = reject
})
)
.mockResolvedValue(null)
vi.spyOn(subjectIdentityApi, 'castingReadiness').mockResolvedValue({
total: 0,
ready: 0,
missingIdentity: 0,
missingAnchor: 0,
candidatePending: 0,
unlocked: 0,
locked: 0,
items: []
})
stubFetch(vi.fn<typeof fetch>().mockImplementation(async () => jsonResponse(styleFixture())))
await mountAssets('identity')
expect(wrapper!.get('.subject-identity-skeleton').attributes('aria-busy')).toBe('true')
expect(wrapper!.get('.subject-identity-skeleton').text()).toBe('')
expect(wrapper!.find('#identity-description').exists()).toBe(false)
expect(wrapper!.text()).not.toContain('尚无身份参考图')
rejectCatalog(new Error('主体目录读取失败'))
await flushPromises()
expect(wrapper!.find('.subject-identity-skeleton').exists()).toBe(false)
expect(wrapper!.get('.workspace-feedback [role="alert"]').text()).toContain('主体目录读取失败')
button('重试读取目录').click()
await flushPromises()
expect(wrapper!.find('.subject-identity-skeleton').exists()).toBe(false)
expect(wrapper!.findAll('.identity-subject-item')).toHaveLength(1)
expect(wrapper!.get('.identity-detail').text()).toContain('林知夏')
expect(wrapper!.get('.identity-detail-skeleton').attributes('aria-busy')).toBe('true')
rejectDetail(new Error('身份读取失败'))
await flushPromises()
expect(wrapper!.find('.identity-detail-skeleton').exists()).toBe(false)
expect(wrapper!.get('.identity-detail [role="alert"]').text()).toContain('身份读取失败')
expect(wrapper!.find('#identity-description').exists()).toBe(false)
button('刷新身份').click()
await flushPromises()
expect(wrapper!.get<HTMLInputElement>('#identity-description').element.value).toBe('')
expect(wrapper!.text()).toContain('尚无身份参考图')
})
it('已有身份刷新保留草稿与图库,图片操作归属图库并遵守未保存限制', async () => {
/** 刷新返回前后均保持编辑器实例,防止骨架导致草稿丢失。 */
let finishRefresh!: (value: ReturnType<typeof identityFixture>) => void
vi.spyOn(subjectIdentityApi, 'get')
.mockResolvedValueOnce(identityFixture())
.mockImplementationOnce(
() =>
new Promise(resolve => {
finishRefresh = resolve
})
)
vi.spyOn(subjectIdentityApi, 'listImages').mockResolvedValue([identityImageFixture()])
vi.spyOn(subjectIdentityApi, 'castingReadiness').mockResolvedValue({
total: 0,
ready: 0,
missingIdentity: 0,
missingAnchor: 0,
candidatePending: 0,
unlocked: 0,
locked: 0,
items: []
})
stubFetch(
vi
.fn<typeof fetch>()
.mockImplementation(async url =>
jsonResponse(String(url).endsWith('/subject-forms') ? [formFixture()] : styleFixture())
)
)
await mountAssets('identity')
const editor = wrapper!.get('#identity-description').element
const gallery = wrapper!.get('[aria-label="身份参考图库"]')
expect(gallery.get('.identity-gallery-actions').text()).toContain('生成辅助参考图')
expect(wrapper!.get('.page-form-actions').text()).not.toContain('生成辅助参考图')
expect(button('生成辅助参考图').disabled).toBe(false)
await wrapper!.get('#identity-description').setValue('保留人工身份草稿')
expect(button('生成辅助参考图').disabled).toBe(true)
button('刷新身份').click()
await flushPromises()
expect(wrapper!.find('.identity-detail-skeleton').exists()).toBe(false)
expect(wrapper!.get('#identity-description').element).toBe(editor)
expect(gallery.find('img').exists()).toBe(true)
finishRefresh(identityFixture({ description: '服务器刷新结果' }))
await flushPromises()
expect(wrapper!.get<HTMLTextAreaElement>('#identity-description').element.value).toBe('保留人工身份草稿')
expect(button('生成辅助参考图').disabled).toBe(true)
})
it('风格首读显示骨架,失败后展示重试,恢复后分类与规则始终可见', async () => {
/** 延迟首次响应,确认骨架不会混入尚未创建或空参考图提示。 */
let rejectStyle!: (error: Error) => void
@@ -503,7 +717,9 @@ describe('视觉风格与主体身份工作区', () => {
const put = fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')!
expect(put[0]).toBe('/api/subjects/subject-db-1/identity')
expect(JSON.parse(put[1]!.body as string)).toMatchObject({ description: '人工稳定身份', isLocked: true })
expect(button('生成选角候选').disabled).toBe(false)
expect(wrapper!.get('.page-form-actions').text()).not.toContain('当前内容已保存到项目')
expect(wrapper!.get('.page-form-actions button[type="submit"]').text()).toBe('已保存')
expect(button('AI 生成角色候选图').disabled).toBe(false)
await new DOMWrapper(document.body).get('#identity-description').setValue('新的未保存草稿')
await wrapper!.findAll('.identity-subject-item')[1]!.trigger('click')
expect(document.body.textContent).toContain('切换会丢弃草稿')
@@ -515,6 +731,8 @@ describe('视觉风格与主体身份工作区', () => {
expect((new DOMWrapper(document.body).get('#identity-description').element as HTMLTextAreaElement).value).toBe(
''
)
expect(wrapper!.get('.page-form-actions button[type="submit"]').text()).toBe('保存主体身份')
expect(wrapper!.get('.page-form-actions').text()).not.toContain('已保存')
})
it('链接添加拒绝危险 URL,只传已有地址及分类排序,成功后关闭并清空弹窗', async () => {
@@ -697,7 +915,34 @@ describe('视觉风格与主体身份工作区', () => {
expect(wrapper!.text()).toContain('2 个形态')
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/subjects/subject-db-1/identity'))).toBe(true)
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/identity/images'))).toBe(false)
expect(button('生成身份文本').disabled).toBe(false)
expect(button('AI 生成主体身份').disabled).toBe(false)
})
it('AI 主体身份生成在表单底部保留唯一入口,覆盖已保存文本需要确认', async () => {
let identity = identityFixture()
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
if (String(url).endsWith('/subject-forms')) return jsonResponse([formFixture()])
if (String(url).endsWith('/visual-style')) return jsonResponse(styleFixture())
if (String(url).endsWith('/identity/images')) return jsonResponse([])
if (init?.method === 'POST') identity = identityFixture({ description: 'AI 重新生成的身份描述' })
return jsonResponse(identity)
})
stubFetch(fetcher)
await mountAssets('identity')
const actions = wrapper!.get('.page-form-actions')
expect(actions.text()).toContain('AI 生成主体身份')
expect(actions.findAll('button').map(item => item.text())).toEqual(['已保存', 'AI 生成主体身份'])
expect(actions.text()).not.toContain('当前内容已保存到项目')
expect(wrapper!.findAll('button').filter(item => item.text() === 'AI 生成主体身份')).toHaveLength(1)
button('AI 生成主体身份').click()
await flushPromises()
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'POST')).toBe(false)
button('确认AI 生成主体身份').click()
await flushPromises()
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
expect(post[0]).toBe('/api/subjects/subject-db-1/identity/generate')
expect(JSON.parse(post[1]!.body as string)).toEqual({ force: true })
expect(wrapper!.get<HTMLTextAreaElement>('#identity-description').element.value).toBe('AI 重新生成的身份描述')
})
it('锁定阻止身份 AI 覆盖但不阻止人工编辑,并按步骤进入后续操作', async () => {
@@ -711,6 +956,7 @@ describe('视觉风格与主体身份工作区', () => {
stubFetch(fetcher)
await mountAssets('identity')
expect(wrapper!.text()).toContain('主体身份已完成')
expect(button('AI 生成主体身份').disabled).toBe(true)
await new DOMWrapper(document.body).get('#identity-description').setValue('人工稳定身份草稿')
expect(button('保存主体身份').disabled).toBe(false)
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'POST')).toBe(false)
@@ -727,6 +973,7 @@ describe('视觉风格与主体身份工作区', () => {
)
await mountAssets('identity')
expect(button('设置视觉风格').disabled).toBe(false)
expect(button('AI 生成主体身份').disabled).toBe(true)
await new DOMWrapper(document.body).get('#identity-description').setValue('人工稳定身份草稿')
expect(button('保存主体身份').disabled).toBe(false)
})
@@ -758,6 +1005,50 @@ describe('视觉风格与主体身份工作区', () => {
expect(drawerPanel().text()).toContain('文本模型超时')
})
it.each([true, false])(
'身份图片校验按真实 passed=%s 反馈,等待时显示目标按钮加载,结果不驻留页面',
async passed => {
/** 延迟校验回执以覆盖请求期间的真实按钮状态。 */
let finish!: (response: Response) => void
const response = new Promise<Response>(resolve => {
finish = resolve
})
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
const path = String(url)
if (path.endsWith('/subject-forms')) return jsonResponse([formFixture()])
if (path.endsWith('/visual-style')) return jsonResponse(styleFixture())
if (init?.method === 'POST' && path.endsWith('/validate')) return response
if (path.endsWith('/identity/images')) return jsonResponse([identityImageFixture()])
return jsonResponse(identityFixture())
})
stubFetch(fetcher)
await mountAssets('identity')
const gallery = wrapper!.findComponent(IdentityGallery)
gallery.vm.$emit('validate', 'identity-image-1')
await flushPromises()
expect(gallery.props('pendingOperation')).toMatchObject({ imageId: 'identity-image-1', kind: 'validate' })
expect(button('校验此身份图片').disabled).toBe(true)
expect(getOperation(fixture.id).pending).toBe(true)
finish(
jsonResponse({
subjectId: 'subject-db-1',
imageId: 'identity-image-1',
passed,
summary: '本次视觉检查结果',
issues: []
})
)
await flushPromises()
expect(getOperation(fixture.id)).toMatchObject({
pending: false,
noticeType: passed ? 'success' : 'warning',
notice: `林知夏 的身份图片校验${passed ? '通过' : '未通过'}:本次视觉检查结果`
})
expect(gallery.props('pendingOperation')).toBeNull()
expect(wrapper!.text()).not.toContain('本次视觉检查结果')
}
)
it('身份候选母版切换需确认,只发送正确 Subject ID 的 anchor PUT', async () => {
let selected = false
const form = formFixture()
@@ -789,6 +1080,10 @@ describe('视觉风格与主体身份工作区', () => {
'/api/subjects/subject-db-1/identity/images/candidate/stable-anchor'
)
expect(wrapper!.text()).toContain('当前身份母版')
expect(getOperation(fixture.id)).toMatchObject({
noticeType: 'success',
notice: '林知夏 的身份母版已确认并锁定。'
})
const anchorImage = wrapper!
.findAllComponents(NImage)
.find(image => image.props('alt')?.endsWith('当前身份母版'))!
@@ -943,8 +1238,11 @@ describe('视觉风格与主体身份工作区', () => {
})
stubFetch(fetcher)
await mountAssets('identity')
expect(wrapper!.find('.subject-identity-skeleton').exists()).toBe(false)
expect(wrapper!.find('.identity-detail-skeleton').exists()).toBe(true)
await wrapper!.findAll('.identity-subject-item')[1]!.trigger('click')
await flushPromises()
expect(wrapper!.find('.identity-detail-skeleton').exists()).toBe(false)
expect(
fetcher.mock.calls.find(([url]) => String(url).endsWith('/subject-db-1/identity'))?.[1]?.signal?.aborted
).toBe(true)
@@ -966,14 +1264,14 @@ describe('视觉风格与主体身份工作区', () => {
})
stubFetch(fetcher)
const provided = await mountAssets('identity')
button('生成身份文本').click()
button('AI 生成主体身份').click()
await flushPromises()
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1)
expect(getOperation(fixture.id).error).toContain('无法连接后端')
provided.data.value!.project = { ...fixture, status: 'generating' }
await flushPromises()
expect(new DOMWrapper(document.body).get('#identity-description').attributes('disabled')).toBeDefined()
expect(button('生成身份文本').disabled).toBe(true)
expect(button('AI 生成主体身份').disabled).toBe(true)
})
})