fix(short-drama-agent-front): 修复资产库请求与管理流程
This commit is contained in:
1 parent
41d1cfe3ed
commit
f8b0fbb8ca
10 files changed
+672
-77
No files matched your search
@@ -4,6 +4,7 @@ import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import ProjectAssetsPage from '@/features/project-assets/ProjectAssetsPage.vue'
|
||||
import { projectContextKey } from '@/features/projects/context'
|
||||
import { testProjectContext } from '@/testing/project-context'
|
||||
import AppDialog from '@/components/ui/AppDialog.vue'
|
||||
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
@@ -13,7 +14,88 @@ afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** 当前项目的受控素材,未调用真实资产接口。 */
|
||||
const projectAssetFixture = {
|
||||
id: 'fixture-asset',
|
||||
projectId: 'capability-test',
|
||||
name: '隔离测试图片',
|
||||
type: 'image',
|
||||
category: 'reference',
|
||||
mimeType: 'image/png',
|
||||
extension: 'png',
|
||||
size: 1024,
|
||||
publicUrl: '/storage/fixture.png',
|
||||
metadata: null,
|
||||
createdAt: '2026-11-01T00:00:00Z',
|
||||
updatedAt: '2026-11-01T00:00:00Z'
|
||||
}
|
||||
|
||||
describe('项目资产库页面', () => {
|
||||
it('项目读取失败只暂停保存,仍允许取消已有草稿', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({ data: [projectAssetFixture] })))
|
||||
)
|
||||
const context = testProjectContext()
|
||||
wrapper = mount(ProjectAssetsPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context } }
|
||||
})
|
||||
await flushPromises()
|
||||
await wrapper
|
||||
.findAll('button')
|
||||
.find(button => button.text().trim() === '编辑')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
context.error.value = '项目暂时读取失败'
|
||||
await flushPromises()
|
||||
const dialog = document.querySelector('[role="dialog"][aria-label="编辑素材信息"]')!
|
||||
const cancel = [...dialog.querySelectorAll<HTMLButtonElement>('button')].find(
|
||||
button => button.textContent?.trim() === '取消'
|
||||
)!
|
||||
expect(cancel.disabled).toBe(false)
|
||||
cancel.click()
|
||||
await flushPromises()
|
||||
expect(
|
||||
wrapper
|
||||
.findAllComponents(AppDialog)
|
||||
.find(item => item.props('title') === '编辑素材信息')!
|
||||
.props('open')
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('切换项目时关闭旧素材编辑,不让旧项目草稿留在新页面', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({ data: [projectAssetFixture] })))
|
||||
)
|
||||
const context = testProjectContext()
|
||||
wrapper = mount(ProjectAssetsPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context } }
|
||||
})
|
||||
await flushPromises()
|
||||
await wrapper
|
||||
.findAll('button')
|
||||
.find(button => button.text().trim() === '编辑')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(
|
||||
wrapper
|
||||
.findAllComponents(AppDialog)
|
||||
.find(dialog => dialog.props('title') === '编辑素材信息')!
|
||||
.props('open')
|
||||
).toBe(true)
|
||||
context.data.value!.project.id = 'second-project'
|
||||
await flushPromises()
|
||||
expect(
|
||||
wrapper
|
||||
.findAllComponents(AppDialog)
|
||||
.find(dialog => dialog.props('title') === '编辑素材信息')!
|
||||
.props('open')
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('读取当前项目素材并支持名称、分类和原文件名筛选', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response(
|
||||
@@ -74,6 +156,9 @@ describe('项目资产库页面', () => {
|
||||
expect(wrapper.text()).toContain('雨夜街道')
|
||||
expect(wrapper.text()).toContain('林默正面照')
|
||||
|
||||
await wrapper.get('input[aria-label="搜索项目素材"]').setValue('场景')
|
||||
expect(wrapper.findAll('.project-asset-card')).toHaveLength(1)
|
||||
expect(wrapper.text()).toContain('雨夜街道')
|
||||
await wrapper.get('input[aria-label="搜索项目素材"]').setValue('street-original')
|
||||
expect(wrapper.findAll('.project-asset-card')).toHaveLength(1)
|
||||
expect(wrapper.text()).toContain('雨夜街道')
|
||||
|
||||
Reference in new issue
Block a user