feat: 在全局资产库内完成素材管理
This commit is contained in:
@@ -13,44 +13,48 @@ afterEach(() => {
|
||||
|
||||
describe('全局资产库', () => {
|
||||
it('单次读取并直接显示全部剧本图片,支持按图片与剧本搜索', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: [
|
||||
{
|
||||
id: 'asset-scene',
|
||||
projectId: 'project-one',
|
||||
name: '雨夜街道',
|
||||
type: 'image',
|
||||
category: 'scene',
|
||||
mimeType: 'image/png',
|
||||
extension: 'png',
|
||||
size: 4096,
|
||||
publicUrl: '/storage/scene.png',
|
||||
metadata: null,
|
||||
createdAt: '2026-09-22T00:00:00Z',
|
||||
updatedAt: '2026-09-22T00:00:00Z',
|
||||
project: { id: 'project-one', title: '记忆当铺', topic: '记忆交易', status: 'completed' }
|
||||
},
|
||||
{
|
||||
id: 'asset-character',
|
||||
projectId: 'project-two',
|
||||
name: '林默正面照',
|
||||
type: 'image',
|
||||
category: 'character',
|
||||
mimeType: 'image/jpeg',
|
||||
extension: 'jpg',
|
||||
size: 8192,
|
||||
publicUrl: '/storage/character.jpg',
|
||||
metadata: null,
|
||||
createdAt: '2026-09-22T01:00:00Z',
|
||||
updatedAt: '2026-09-22T01:00:00Z',
|
||||
project: { id: 'project-two', title: '天降甘霖', topic: '乡村故事', status: 'completed' }
|
||||
}
|
||||
]
|
||||
})
|
||||
)
|
||||
)
|
||||
const assets = [
|
||||
{
|
||||
id: 'asset-scene',
|
||||
projectId: 'project-one',
|
||||
name: '雨夜街道',
|
||||
type: 'image',
|
||||
category: 'scene',
|
||||
mimeType: 'image/png',
|
||||
extension: 'png',
|
||||
size: 4096,
|
||||
publicUrl: '/storage/scene.png',
|
||||
metadata: null,
|
||||
createdAt: '2026-09-22T00:00:00Z',
|
||||
updatedAt: '2026-09-22T00:00:00Z',
|
||||
project: { id: 'project-one', title: '记忆当铺', topic: '记忆交易', status: 'completed' }
|
||||
},
|
||||
{
|
||||
id: 'asset-character',
|
||||
projectId: 'project-two',
|
||||
name: '林默正面照',
|
||||
type: 'image',
|
||||
category: 'character',
|
||||
mimeType: 'image/jpeg',
|
||||
extension: 'jpg',
|
||||
size: 8192,
|
||||
publicUrl: '/storage/character.jpg',
|
||||
metadata: null,
|
||||
createdAt: '2026-09-22T01:00:00Z',
|
||||
updatedAt: '2026-09-22T01:00:00Z',
|
||||
project: { id: 'project-two', title: '天降甘霖', topic: '乡村故事', status: 'completed' }
|
||||
}
|
||||
]
|
||||
const projects = assets.map(asset => ({
|
||||
...asset.project,
|
||||
style: null,
|
||||
createdAt: '',
|
||||
updatedAt: ''
|
||||
}))
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
|
||||
const url = String(input)
|
||||
return new Response(JSON.stringify({ data: url.endsWith('/projects') ? projects : assets }))
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
@@ -63,13 +67,21 @@ describe('全局资产库', () => {
|
||||
wrapper = mount(AssetLibraryPage, { attachTo: document.body, global: { plugins: [router] } })
|
||||
await flushPromises()
|
||||
|
||||
expect(fetcher).toHaveBeenCalledOnce()
|
||||
expect(fetcher).toHaveBeenCalledTimes(2)
|
||||
expect(fetcher).toHaveBeenCalledWith('/api/assets', expect.objectContaining({ method: 'GET' }))
|
||||
expect(wrapper.findAll('.asset-library-card')).toHaveLength(2)
|
||||
expect(wrapper.text()).toContain('雨夜街道')
|
||||
expect(wrapper.text()).toContain('林默正面照')
|
||||
expect(wrapper.text()).toContain('记忆当铺')
|
||||
|
||||
await wrapper
|
||||
.findAll('button')
|
||||
.find(button => button.text() === '管理')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(document.querySelector('[role="dialog"][aria-label="管理素材信息"]')).not.toBeNull()
|
||||
expect(router.currentRoute.value.path).toBe('/assets')
|
||||
|
||||
await wrapper.get('input[aria-label="搜索资产图片"]').setValue('天降甘霖')
|
||||
expect(wrapper.findAll('.asset-library-card')).toHaveLength(1)
|
||||
expect(wrapper.text()).toContain('林默正面照')
|
||||
|
||||
Reference in New Issue
Block a user