31 lines
1.8 KiB
TypeScript
31 lines
1.8 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { parseAppearance, normalizeAppearance, THEMES } from '../src/lib/theme/appearance.ts';
|
|
|
|
test('Removed palettes preserve the saved mode with the default palette', () => {
|
|
for (const theme of ['gpt', 'terminal', 'unknown']) {
|
|
for (const mode of ['light', 'dark'] as const) {
|
|
assert.deepEqual(parseAppearance(JSON.stringify({ theme, mode })), { theme: 'default', mode });
|
|
}
|
|
}
|
|
assert.deepEqual(THEMES, ['default', 'claude', 'sakura']);
|
|
});
|
|
test('Sakura cannot restore or save a dark appearance', () => {
|
|
assert.deepEqual(parseAppearance('{"theme":"sakura","mode":"dark"}'), { theme: 'sakura', mode: 'light' });
|
|
assert.deepEqual(normalizeAppearance({ theme: 'sakura', mode: 'dark' }), { theme: 'sakura', mode: 'light' });
|
|
});
|
|
test('Malformed storage returns a valid default appearance', () => {
|
|
for (const raw of [null, '', '{', 'null', '42', '[]']) {
|
|
assert.deepEqual(parseAppearance(raw), { theme: 'default', mode: 'dark' });
|
|
}
|
|
});
|
|
|
|
test('Saved image layout restores valid choices and rejects CSS injection', () => {
|
|
const imageId = '01234567-89ab-cdef-0123-456789abcdef';
|
|
const restored = parseAppearance(JSON.stringify({ newTabBackground: { imageId, position: 'top left', size: 'auto', overlay: -0.4 } }));
|
|
assert.deepEqual(restored.newTabBackground, { imageId, position: 'top left', size: 'auto', overlay: -0.4 });
|
|
const invalid = normalizeAppearance({ newTabBackground: { imageId, position: 'url(https://example.com)', size: '100000px', overlay: Infinity } });
|
|
assert.deepEqual(invalid.newTabBackground, { imageId, position: 'center', size: 'cover', overlay: 0 });
|
|
assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId } }).newTabBackground, { imageId, overlay: 0, position: 'center', size: 'cover' });
|
|
});
|