优化采购实时编辑与权限,支持先到货后补报价、按批次补录照片和批量附件上传。更新验收报告模板及明细选择,增加验收发票独立管理和付款前置校验。完善 BOM 数据权限及 App 更新兼容性。
23 lines
2.0 KiB
JavaScript
23 lines
2.0 KiB
JavaScript
import {expect,it,vi} from 'vitest'
|
|
import {isHeicHeader,prepareArrivalPhoto,convertHeic} from '@/utils/arrival-photo-format'
|
|
function header(brand='heic'){return new Uint8Array([0,0,0,24,...new TextEncoder().encode('ftyp'+brand),0,0,0,0,...new TextEncoder().encode('mif1heic')])}
|
|
it('detects HEIF by file header independently of QQ filename and caches converted bytes for safe retries',async()=>{
|
|
const bytes=header(),file=new File([bytes],'QQ图片.png',{type:'image/png'}),convert=vi.fn(async()=>new Blob([new Uint8Array([255,216,255])],{type:'image/jpeg'}))
|
|
const result=await prepareArrivalPhoto(file,undefined,convert)
|
|
expect(result.name).toBe('QQ图片.jpg');expect(result.type).toBe('image/jpeg');expect(await prepareArrivalPhoto(file,undefined,convert)).toBe(result);expect(convert).toHaveBeenCalledTimes(1)
|
|
expect(isHeicHeader(header('avif'))).toBe(false)
|
|
})
|
|
it('leaves ordinary image bytes intact and does not need conversion libraries for a JPEG saved as PNG',async()=>{
|
|
const file=new File([new Uint8Array([255,216,255])],'QQ图片.png',{type:'image/png'}),convert=vi.fn()
|
|
expect(await prepareArrivalPhoto(file,undefined,convert)).toBe(file);expect(convert).not.toHaveBeenCalled()
|
|
})
|
|
it('cancelled and oversized HEIC conversions never produce an uploadable file',async()=>{
|
|
const file=new File([header()],'照片.HEIC',{type:'image/heic'}),ctl=new AbortController();ctl.abort()
|
|
await expect(prepareArrivalPhoto(file,ctl.signal)).rejects.toMatchObject({code:'ERR_CANCELED'})
|
|
await expect(prepareArrivalPhoto(file,undefined,async()=>new Blob([new Uint8Array(20*1024*1024+1)]))).rejects.toThrow('20MB')
|
|
})
|
|
it('cancelling an in-flight conversion terminates its worker immediately',async()=>{
|
|
const worker={terminate:vi.fn(),postMessage:vi.fn()},ctl=new AbortController();vi.stubGlobal('Worker',vi.fn(function(){return worker}))
|
|
try{const job=convertHeic(new Blob([header()]),ctl.signal);ctl.abort();await expect(job).rejects.toMatchObject({code:'ERR_CANCELED'});expect(worker.terminate).toHaveBeenCalledTimes(1)}finally{vi.unstubAllGlobals()}
|
|
})
|