A calm place to write long-form, and publish it to the open social web. skypress.blog/
0

Configure Feed

Select the types of activity you want to include in your feed.

at trunk 1.3 kB View raw
1import { describe, it, expect, vi } from 'vitest'; 2import { createDeferredMediaUpload } from './deferred-media'; 3 4describe( 'createDeferredMediaUpload', () => { 5 it( 'previews each file as a data: URL and uploads nothing', async () => { 6 const handler = createDeferredMediaUpload(); 7 const file = new File( [ 'x' ], 'cat.png', { type: 'image/png' } ); 8 const onFileChange = vi.fn(); 9 10 await handler( { filesList: [ file ], onFileChange } ); 11 12 expect( onFileChange ).toHaveBeenCalledTimes( 1 ); 13 const [ media ] = onFileChange.mock.calls[ 0 ][ 0 ]; 14 expect( media.url.startsWith( 'data:image/png;base64,' ) ).toBe( true ); 15 expect( media.url.startsWith( 'blob:' ) ).toBe( false ); 16 expect( 'id' in media ).toBe( false ); 17 } ); 18 19 it( 'rejects oversize files via onError without previewing them', async () => { 20 const handler = createDeferredMediaUpload(); 21 const big = new File( [ 'x' ], 'big.png', { type: 'image/png' } ); 22 Object.defineProperty( big, 'size', { value: 5_000_000 } ); 23 const onFileChange = vi.fn(); 24 const onError = vi.fn(); 25 26 await handler( { 27 filesList: [ big ], 28 onFileChange, 29 onError, 30 maxUploadFileSize: 1_000_000, 31 } ); 32 33 expect( onFileChange ).not.toHaveBeenCalled(); 34 expect( onError ).toHaveBeenCalledTimes( 1 ); 35 expect( onError.mock.calls[ 0 ][ 0 ] ).toBeInstanceOf( Error ); 36 } ); 37} );