refactor(frontend): replace legacy settings init/settings pattern with typed config functions

This commit is contained in:
Yiannis
2026-03-11 02:14:45 +02:00
parent 7a5fca6fd8
commit 374ae4de6e
45 changed files with 1137 additions and 1371 deletions

View File

@@ -1,9 +1,4 @@
import { init, settings } from '../../../src/static/js/utils/settings/optionsEmbedded';
const optionsEmbeddedConfig = (embeddedVideo?: any) => {
init(embeddedVideo);
return settings();
};
import { optionsEmbeddedConfig } from '../../../src/static/js/utils/settings/optionsEmbedded';
describe('utils/settings', () => {
describe('optionsEmbedded', () => {
@@ -22,32 +17,30 @@ describe('utils/settings', () => {
expect(cfg.video.dimensions).toStrictEqual({ width: 640, widthUnit: 'px', height: 360, heightUnit: 'px' });
});
// @todo: Revisit this behavior
test('Ignores NaN and non-numeric width/height and keeps defaults', () => {
const cfg1 = optionsEmbeddedConfig({ initialDimensions: { width: NaN, height: NaN } });
const cfg1 = optionsEmbeddedConfig({ initialDimensions: { width: NaN, height: NaN } } as any);
expect(cfg1.video.dimensions).toStrictEqual({ width: 560, widthUnit: 'px', height: 315, heightUnit: 'px' });
const cfg2 = optionsEmbeddedConfig({ initialDimensions: { width: '640', height: '360' } });
expect(cfg2.video.dimensions).toStrictEqual({
width: '640',
widthUnit: 'px',
height: '360',
heightUnit: 'px',
});
const cfg2 = optionsEmbeddedConfig({ initialDimensions: { width: '640', height: '360' } } as any);
expect(cfg2.video.dimensions).toStrictEqual({ width: 560, widthUnit: 'px', height: 315, heightUnit: 'px' });
});
// @todo: Revisit this behavior
test('Ignores provided widthUnit/heightUnit as they are not used', () => {
const cfg = optionsEmbeddedConfig({
initialDimensions: { width: 800, height: 450, widthUnit: 'percent', heightUnit: 'percent' },
});
initialDimensions: {
width: 800,
height: 450,
widthUnit: 'percent',
heightUnit: 'percent',
},
} as any);
// units should remain default 'px'
expect(cfg.video.dimensions.width).toBe(800);
expect(cfg.video.dimensions.height).toBe(450);
expect(cfg.video.dimensions.widthUnit).toBe('px');
expect(cfg.video.dimensions.heightUnit).toBe('px');
});
// @todo: Revisit this behavior
test('Does not mutate the provided settings object', () => {
const input = {
initialDimensions: { width: 700, height: 400, widthUnit: 'percent', heightUnit: 'percent' },