22 lines
1.7 KiB
TypeScript
22 lines
1.7 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { normalizeTheme as normalizeChoice, resolveTheme, resolvedTheme, THEME_DEFAULT } from '../src/inject/theme.ts';
|
|
import { buildStructureCss } from '../src/inject/themeStructure.ts';
|
|
import { parseIconPackJson } from '../../../waybetter/packages/runtime/src/themeIcons.ts';
|
|
|
|
// An imported icon pack (Appearance > Icons > Import) lives in the theme choice and reaches X's
|
|
// static sheet exactly like a built-in pack; removing it falls back to the theme's icons.
|
|
const doc = JSON.stringify({ id: 'imported-test', name: 'Imported test', author: 'Test', license: 'CC0-1.0', glyphs: { home: { d: 'M3 3h18v18H3z' }, like: { d: 'M4 4h16v16H4z' } } });
|
|
|
|
test('an imported icon pack reaches the X sheet and goes away with the pack', () => {
|
|
const parsed = parseIconPackJson(doc);
|
|
assert.ok(!('error' in parsed), 'the test pack parses');
|
|
const pack = (parsed as { pack: import('../../../waybetter/packages/runtime/src/themeIcons.ts').IconPack }).pack;
|
|
const choice = normalizeChoice({ ...THEME_DEFAULT, icons: pack.id, packs: [pack] });
|
|
assert.equal(choice.packs?.length, 1, 'the choice keeps the pack');
|
|
const css = buildStructureCss(resolveTheme(choice), resolvedTheme(choice, 'dark'), { icons: choice.icons ?? 'theme', packs: choice.packs });
|
|
assert.match(css, /M3%203h18v18H3z/, 'the pack glyph is in the sheet');
|
|
const without = normalizeChoice({ ...choice, packs: [] });
|
|
const plain = buildStructureCss(resolveTheme(without), resolvedTheme(without, 'dark'), { icons: without.icons ?? 'theme', packs: without.packs });
|
|
assert.doesNotMatch(plain, /M3%203h18v18H3z/, 'a removed pack draws nothing');
|
|
});
|