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/contents';
const contentsConfig = (obj: any) => {
init(obj);
return settings();
};
import { contentsConfig } from '../../../src/static/js/utils/settings/contents';
describe('utils/settings', () => {
describe('contents', () => {
@@ -53,8 +48,7 @@ describe('utils/settings', () => {
});
});
// @todo: Revisit this behavior
test('Sidebar menu items require text, link, icon and NOT get trimmed', () => {
test('Sidebar menu items require text, link, icon and get trimmed', () => {
const cfg = contentsConfig({
sidebar: {
mainMenuExtraItems: [
@@ -62,22 +56,63 @@ describe('utils/settings', () => {
{ text: 'no-link', icon: 'i' },
{ link: '/missing-text', icon: 'i' },
{ text: 'no-icon', link: '/x' },
null as any,
undefined,
],
navMenuItems: [
{ text: ' B ', link: ' /b ', icon: ' i-b ' },
{ text: ' ', link: '/bad', icon: 'i' },
null as any,
undefined,
],
},
});
expect(cfg.sidebar.mainMenuExtra.items).toStrictEqual([
{ text: ' A ', link: ' /a ', icon: ' i-a ', className: ' cls ' },
]);
expect(cfg.sidebar.mainMenuExtra.items).toEqual([{ text: 'A', link: '/a', icon: 'i-a', className: 'cls' }]);
expect(cfg.sidebar.navMenu.items).toStrictEqual([
{ text: ' B ', link: ' /b ', icon: ' i-b ', className: undefined },
{ text: ' ', link: '/bad', icon: 'i', className: undefined },
]);
expect(cfg.sidebar.navMenu.items).toEqual([{ text: 'B', link: '/b', icon: 'i-b', className: '' }]);
});
test('sidebar strings are trimmed or default to empty', () => {
const cfg = contentsConfig({
sidebar: {
belowNavMenu: ' X ',
belowThemeSwitcher: ' Y ',
footer: ' Z ',
},
} as any);
expect(cfg.sidebar.belowNavMenu).toBe('X');
expect(cfg.sidebar.belowThemeSwitcher).toBe('Y');
expect(cfg.sidebar.footer).toBe('Z');
const cfg2 = contentsConfig({ sidebar: {} } as any);
expect(cfg2.sidebar.belowNavMenu).toBe('');
expect(cfg2.sidebar.belowThemeSwitcher).toBe('');
expect(cfg2.sidebar.footer).toBe('');
});
test('uploader strings are trimmed or default to empty', () => {
const cfg = contentsConfig({
uploader: { belowUploadArea: ' U1 ', postUploadMessage: ' U2 ' },
} as any);
expect(cfg.uploader.belowUploadArea).toBe('U1');
expect(cfg.uploader.postUploadMessage).toBe('U2');
const cfg2 = contentsConfig({ uploader: {} } as any);
expect(cfg2.uploader.belowUploadArea).toBe('');
expect(cfg2.uploader.postUploadMessage).toBe('');
});
test('handles completely missing settings by returning defaults', () => {
const cfg = contentsConfig(undefined as any);
expect(cfg.header.right).toBe('');
expect(cfg.header.onLogoRight).toBe('');
expect(cfg.sidebar.mainMenuExtra.items).toEqual([]);
expect(cfg.sidebar.navMenu.items).toEqual([]);
expect(cfg.sidebar.footer).toBe('');
expect(cfg.uploader.postUploadMessage).toBe('');
});
});
});