|
| 1 | +import assert from 'node:assert'; |
| 2 | +import test from 'node:test'; |
| 3 | +import pickBestIcon from './icons.js'; |
| 4 | + |
| 5 | +const manifest = [ |
| 6 | + {url: '16.svg', size: 16}, |
| 7 | + {url: '32.svg', size: 32}, |
| 8 | +]; |
| 9 | + |
| 10 | +test('pickBestIcon', () => { |
| 11 | + globalThis.devicePixelRatio = 1; |
| 12 | + assert.equal(pickBestIcon(), 'icons/puzzle.svg'); |
| 13 | + assert.equal(pickBestIcon(undefined), 'icons/puzzle.svg'); |
| 14 | + assert.equal(pickBestIcon([]), 'icons/puzzle.svg'); |
| 15 | + assert.equal(pickBestIcon(manifest), '16.svg'); |
| 16 | + assert.equal(pickBestIcon(manifest, 16), '16.svg'); |
| 17 | + assert.equal(pickBestIcon(manifest, 1), '16.svg'); |
| 18 | + assert.equal(pickBestIcon(manifest, 32), '32.svg'); |
| 19 | + assert.equal(pickBestIcon(manifest, 48), '32.svg'); |
| 20 | + |
| 21 | + globalThis.devicePixelRatio = 2; |
| 22 | + assert.equal(pickBestIcon(manifest, 16), '32.svg'); |
| 23 | + assert.equal(pickBestIcon(manifest, 32), '32.svg'); |
| 24 | +}); |
0 commit comments