Skip to content

Commit 75dcdf8

Browse files
committed
Fix tests
1 parent fda3243 commit 75dcdf8

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

source/libs/icons.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export default function pickBestIcon(icons, size = 16) {
66
return 'icons/puzzle.svg';
77
}
88

9-
const largestToSmallest = icons.toSorted((a, b) => b.size - a.size);
9+
const smallestToLargest = icons.toSorted((a, b) => a.size - b.size);
1010

1111
// Find the smallest icon that is larger than the requested size
12-
for (const icon of largestToSmallest) {
12+
for (const icon of smallestToLargest) {
1313
if (icon.size >= size) {
1414
return icon.url;
1515
}
1616
}
1717

1818
// If it's not available (e.g. requested 32, available only 16), get the largest one
19-
return largestToSmallest[0].url;
19+
return smallestToLargest.at(-1).url;
2020
}

source/libs/icons.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@ import assert from 'node:assert';
22
import test from 'node:test';
33
import pickBestIcon from './icons.js';
44

5-
globalThis.devicePixelRatio = 1;
6-
75
const manifest = [
86
{url: '16.svg', size: 16},
97
{url: '32.svg', size: 32},
108
];
119

1210
test('pickBestIcon', () => {
11+
globalThis.devicePixelRatio = 1;
1312
assert.equal(pickBestIcon(), 'icons/puzzle.svg');
1413
assert.equal(pickBestIcon(undefined), 'icons/puzzle.svg');
1514
assert.equal(pickBestIcon([]), 'icons/puzzle.svg');
16-
// assert.equal(pickBestIcon(manifest), '16.svg');
17-
// assert.equal(pickBestIcon(manifest, 16), '16.svg');
18-
// assert.equal(pickBestIcon(manifest, 1), '16.svg');
19-
// assert.equal(pickBestIcon(manifest, 32), '32.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');
2019
assert.equal(pickBestIcon(manifest, 48), '32.svg');
2120

22-
// globalThis.devicePixelRatio = 2;
23-
// assert.equal(pickBestIcon(manifest, 16), '32.svg');
24-
// assert.equal(pickBestIcon(manifest, 32), '64.svg');
21+
globalThis.devicePixelRatio = 2;
22+
assert.equal(pickBestIcon(manifest, 16), '32.svg');
23+
assert.equal(pickBestIcon(manifest, 32), '32.svg');
2524
});

0 commit comments

Comments
 (0)