import { test } from 'node:test'; import assert from 'node:assert/strict'; import { gifPreviewBox } from './gifPreviewSize'; test('gifPreviewBox: a landscape GIF wider than the card fills its width', () => { assert.deepEqual(gifPreviewBox(480, 270), { width: 400, height: 225 }); assert.deepEqual(gifPreviewBox(480, 200), { width: 400, height: 167 }); }); test('gifPreviewBox: square and portrait GIFs keep their shape instead of being cropped', () => { assert.deepEqual(gifPreviewBox(300, 300), { width: 320, height: 320 }); assert.deepEqual(gifPreviewBox(480, 480), { width: 320, height: 320 }); assert.deepEqual(gifPreviewBox(240, 480), { width: 160, height: 320 }); }); test('gifPreviewBox: a small GIF is enlarged at most 2×', () => { assert.deepEqual(gifPreviewBox(100, 80), { width: 200, height: 160 }); assert.deepEqual(gifPreviewBox(150, 150), { width: 300, height: 300 }); }); test('gifPreviewBox: extreme aspect ratios stay inside the box and never collapse to 0', () => { assert.deepEqual(gifPreviewBox(2000, 50), { width: 400, height: 10 }); assert.deepEqual(gifPreviewBox(1, 10000), { width: 1, height: 320 }); }); test('gifPreviewBox: accepts numeric strings and rejects unknown sizes', () => { assert.deepEqual(gifPreviewBox('480', '270'), { width: 400, height: 225 }); assert.equal(gifPreviewBox(undefined, 270), undefined); assert.equal(gifPreviewBox(480, 0), undefined); assert.equal(gifPreviewBox('wide', 270), undefined); assert.equal(gifPreviewBox(Number.NaN, 270), undefined); }); test('gifPreviewBox: custom limits', () => { assert.deepEqual(gifPreviewBox(480, 270, 200, 200, 1), { width: 200, height: 113 }); });