Chart theming: custom named themes + Theme Builder

This commit is contained in:
2026-06-12 18:15:54 +03:00
parent 44a601affd
commit b193464f55
32 changed files with 2220 additions and 70 deletions
@@ -0,0 +1,37 @@
import { describe, expect, it } from 'vitest';
import { CURRENT_THEME_VERSION } from '@core/custom-theme';
import { migrateCustomTheme } from './theme-migrations';
describe('migrateCustomTheme', () => {
it('passes a current record through unchanged (plus version stamp)', () => {
const record = {
id: 3,
version: CURRENT_THEME_VERSION,
name: 'Brand',
config: { font: 'Georgia' },
created: '2026-06-12T10:00:00.000Z',
modified: '2026-06-12T11:00:00.000Z',
};
expect(migrateCustomTheme(record)).toEqual(record);
});
it('fills missing or invalid fields with safe defaults', () => {
const migrated = migrateCustomTheme({ id: '7', config: ['not', 'an', 'object'] });
expect(migrated.id).toBe(7);
expect(migrated.version).toBe(CURRENT_THEME_VERSION);
expect(migrated.name).toBe('Untitled theme');
expect(migrated.config).toEqual({});
expect(typeof migrated.created).toBe('string');
expect(typeof migrated.modified).toBe('string');
});
it('keeps unknown fields written by a newer build', () => {
const migrated = migrateCustomTheme({
id: 1,
name: 'Next',
config: {},
futureField: 'kept',
});
expect((migrated as unknown as Record<string, unknown>).futureField).toBe('kept');
});
});