code.gitea.io/gitea@v1.22.3/web_src/js/utils/image.test.js (about) 1 import {pngChunks, imageInfo} from './image.js'; 2 3 const pngNoPhys = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAADUlEQVQIHQECAP3/AAAAAgABzePRKwAAAABJRU5ErkJggg=='; 4 const pngPhys = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAEElEQVQI12OQNZcAIgYIBQAL8gGxdzzM0A=='; 5 const pngEmpty = 'data:image/png;base64,'; 6 7 async function dataUriToBlob(datauri) { 8 return await (await globalThis.fetch(datauri)).blob(); 9 } 10 11 test('pngChunks', async () => { 12 expect(await pngChunks(await dataUriToBlob(pngNoPhys))).toEqual([ 13 {name: 'IHDR', data: new Uint8Array([0, 0, 0, 1, 0, 0, 0, 1, 8, 0, 0, 0, 0])}, 14 {name: 'IDAT', data: new Uint8Array([8, 29, 1, 2, 0, 253, 255, 0, 0, 0, 2, 0, 1])}, 15 {name: 'IEND', data: new Uint8Array([])}, 16 ]); 17 expect(await pngChunks(await dataUriToBlob(pngPhys))).toEqual([ 18 {name: 'IHDR', data: new Uint8Array([0, 0, 0, 2, 0, 0, 0, 2, 8, 2, 0, 0, 0])}, 19 {name: 'pHYs', data: new Uint8Array([0, 0, 22, 37, 0, 0, 22, 37, 1])}, 20 {name: 'IDAT', data: new Uint8Array([8, 215, 99, 144, 53, 151, 0, 34, 6, 8, 5, 0, 11, 242, 1, 177])}, 21 ]); 22 expect(await pngChunks(await dataUriToBlob(pngEmpty))).toEqual([]); 23 }); 24 25 test('imageInfo', async () => { 26 expect(await imageInfo(await dataUriToBlob(pngNoPhys))).toEqual({width: 1, dppx: 1}); 27 expect(await imageInfo(await dataUriToBlob(pngPhys))).toEqual({width: 2, dppx: 2}); 28 expect(await imageInfo(await dataUriToBlob(pngEmpty))).toEqual({width: 0, dppx: 1}); 29 });