48 lines
3.1 KiB
TypeScript
48 lines
3.1 KiB
TypeScript
// The theme editor model (src/lib/theme/themeEditor.ts): role groups, drafts, saved files, and the results of each role.
|
|
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { ROLE_GROUPS, builtinDraft, customDraft, draftColors, draftFindings, draftTheme, roleStatus, uniqueThemeId } from '../../../src/lib/theme/themeEditor.ts';
|
|
import { ROLES, resolveColors } from '../../../src/lib/theme/roles.ts';
|
|
import { parseCustomTheme } from '../../../src/lib/theme/customThemes.ts';
|
|
import { BUILTIN_THEMES } from '../../../src/lib/theme/themes/index.ts';
|
|
|
|
test('The editor groups show every role once', () => {
|
|
const shown = ROLE_GROUPS.flatMap(group => group.roles);
|
|
assert.equal(new Set(shown).size, shown.length);
|
|
assert.deepEqual([...shown].sort(), [...ROLES].sort());
|
|
});
|
|
|
|
test('A built-in draft has the colors of its theme', () => {
|
|
for (const theme of BUILTIN_THEMES) for (const [mode, colors] of Object.entries(theme.variants)) {
|
|
const draft = builtinDraft(theme.id, mode as 'light' | 'dark', theme.name);
|
|
assert.deepEqual(draftColors(draft), resolveColors(colors!, mode as 'light' | 'dark'));
|
|
}
|
|
});
|
|
|
|
test('A saved draft is a short schema 3 theme that the parser accepts and that keeps its colors', () => {
|
|
const draft = { ...builtinDraft('harvest-moon', 'dark', 'Harvest Moon copy'), overrides: { accent: '#00c8ff', selection: '#20406080' } };
|
|
const theme = draftTheme(draft, 'harvest-moon-copy', 'Harvest Moon copy');
|
|
assert.deepEqual(theme, { schema: 3, id: 'harvest-moon-copy', name: 'Harvest Moon copy', mode: 'dark', base: 'harvest-moon', colors: { accent: '#00c8ff', selection: '#20406080' } });
|
|
const parsed = parseCustomTheme(theme);
|
|
assert.deepEqual(draftColors(customDraft(parsed)), draftColors(draft));
|
|
});
|
|
|
|
test('Theme IDs from names are valid and unique', () => {
|
|
assert.equal(uniqueThemeId('RuneStone Dark copy', []), 'runestone-dark-copy');
|
|
assert.equal(uniqueThemeId('RuneStone Dark copy', ['runestone-dark-copy', 'runestone-dark-copy-2']), 'runestone-dark-copy-3');
|
|
assert.equal(uniqueThemeId('2026 theme', []), 't-2026-theme');
|
|
assert.equal(uniqueThemeId('桜', []), 'theme');
|
|
for (const name of ['RuneStone Dark copy', '2026 theme', '桜', 'x'.repeat(100), '--Ünïcode--']) assert.match(uniqueThemeId(name, []), /^[a-z][a-z0-9-]{0,63}$/);
|
|
});
|
|
|
|
test('A role shows the results where it is the color, the surface, or one of a pair', () => {
|
|
const draft = { ...builtinDraft('default', 'dark', 'Test'), overrides: { 'text-dim': '#3a3a3a', ok: '#55dcf5' } };
|
|
const findings = draftFindings(draft);
|
|
const dim = roleStatus('text-dim', findings);
|
|
assert(dim.failures.length > 0 && dim.failures.every(finding => finding.subject.startsWith('text-dim on ')));
|
|
assert(dim.lowest && dim.lowest.value < 4.5);
|
|
assert(roleStatus('bg', findings).failures.some(finding => finding.subject === 'text-dim on bg'), 'A surface shows the text that fails on it');
|
|
assert(roleStatus('ok', findings).failures.some(finding => finding.subject === 'accent and ok'), 'A status color shows a pair that is too close');
|
|
assert.deepEqual(roleStatus('syntax-keyword', findings).failures, []);
|
|
});
|