Files
dashtab/tests/unit/utils/image-file-test.js
raucao 8ab486dee8 Treat uploaded custom link icons as maskable
Custom icons uploaded for a custom site link were always stored as
non-maskable, so they rendered inset with a rounded border instead of
filling the tile. Mark every readIconFile result as maskable so uploads
are drawn edge-to-edge like a site's own maskable icon, and update the
image-file tests accordingly.
2026-11-15 14:34:40 +04:00

70 lines
1.7 KiB
JavaScript

import { module, test } from 'qunit';
import {
ICON_MAX_FILE_SIZE,
IconFileError,
readIconFile,
} from 'dashtab/utils/image-file';
function file(parts, name, type) {
return new File(parts, name, { type });
}
module('Unit | Utility | image-file', function () {
test('rejects a non-image file', async function (assert) {
await assert.rejects(
readIconFile(file(['hello'], 'notes.txt', 'text/plain')),
IconFileError,
'rejects the file'
);
});
test('rejects a file above the size cap', async function (assert) {
const big = file(
[new Uint8Array(ICON_MAX_FILE_SIZE + 1)],
'big.png',
'image/png'
);
await assert.rejects(
readIconFile(big),
IconFileError,
'rejects the oversized file'
);
});
test('keeps an SVG as its original data URL', async function (assert) {
const svg = file(
['<svg xmlns="http://www.w3.org/2000/svg"></svg>'],
'icon.svg',
'image/svg+xml'
);
const icon = await readIconFile(svg);
assert.true(icon.dataUrl.startsWith('data:image/svg+xml'));
assert.true(icon.maskable);
});
test('falls back to the original bytes when decoding fails', async function (assert) {
const original = globalThis.createImageBitmap;
globalThis.createImageBitmap = async () => {
throw new Error('cannot decode');
};
try {
const png = file(
[Uint8Array.from([0x89, 0x50, 0x4e, 0x47])],
'icon.png',
'image/png'
);
const icon = await readIconFile(png);
assert.true(icon.dataUrl.startsWith('data:image/png;base64,'));
assert.true(icon.maskable);
} finally {
globalThis.createImageBitmap = original;
}
});
});