import { describe, it, expect } from 'vitest' import { AssetManager } from '@/lib/assets/assetManager' function u8(n: number): Uint8Array { const a = new Uint8Array(n); for (let i=0;i { it('writes assets under assets/images and assets/fonts when grouped', async () => { const am = new AssetManager({ maxBytes: 1024*1024, allowedExts: ['png','woff2'], pathStrategy: 'grouped' }) const img = await am.add({ name: 'hero.png', type: 'image/png', bytes: u8(10) }) const font = await am.add({ name: 'main.woff2', type: 'font/woff2', bytes: u8(12) }) expect(img.path).toMatch(/^assets\/images\/[0-9a-f]{8}\.png$/) expect(font.path).toMatch(/^assets\/fonts\/[0-9a-f]{8}\.woff2$/) const zip = am.toZipStructure() const keys = Object.keys(zip) expect(keys.some(k => /^assets\/images\//.test(k))).toBe(true) expect(keys.some(k => /^assets\/fonts\//.test(k))).toBe(true) }) it('rewriteUrl marks referenced originals and returns grouped path', async () => { const am = new AssetManager({ maxBytes: 1024*1024, allowedExts: ['png'], pathStrategy: 'grouped' }) const img = await am.add({ name: 'hero.png', type: 'image/png', bytes: u8(10) }) const rewritten = am.rewriteUrl('local:hero.png') expect(rewritten).toBe(img.path) expect(am.referencedList()).toContain('hero.png') }) })