import test from 'node:test' import assert from 'node:assert/strict' import {ehThumbnailUrl, pickDefaultResolution} from '../src/utils/thumbnail.js' test('remote thumbnail paths are wrapped with the auth code', () => { const url = ehThumbnailUrl('samples/thumb.png', 'abc123') assert.match(url, /^https:\/\/downloader\.lionwebsite\.xyz\/GalleryManage\/ehThumbnail\?/) assert.match(url, /path=samples%2Fthumb\.png/) assert.match(url, /AuthCode=abc123/) }) test('a missing thumbnail path produces no url', () => { assert.equal(ehThumbnailUrl('', 'abc123'), '') assert.equal(ehThumbnailUrl(undefined, 'abc123'), '') }) test('the original resolution is preselected when offered', () => { const chosen = pickDefaultResolution({ '800x': '37.53MiB', '1280x': '66.57MiB', '2560x': '84.01MiB', 'Original': '498.2MiB', }) assert.equal(chosen, 'Original') }) test('the original label is matched case-insensitively', () => { assert.equal(pickDefaultResolution({'800x': '1MiB', 'original': '2MiB'}), 'original') }) test('without an original the largest entry wins across units', () => { const chosen = pickDefaultResolution({ '800x': '37.53MiB', '2560x': '84.01MiB', '2160x': '1.2GiB', }) assert.equal(chosen, '2160x') }) test('an empty or absent resolution map selects nothing', () => { assert.equal(pickDefaultResolution({}), '') assert.equal(pickDefaultResolution(undefined), '') }) test('unparseable sizes fall back to the first entry instead of throwing', () => { assert.equal(pickDefaultResolution({'800x': 'unknown', '1280x': 'unknown'}), '800x') })