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,53 +1,51 @@
import { init, settings } from '../../../src/static/js/utils/settings/taxonomies';
import { taxonomiesConfig } from '../../../src/static/js/utils/settings/taxonomies';
const taxonomiesConfig = (sett?: any) => {
init(sett);
return settings();
};
describe('utils-settings/taxonomies', () => {
test('Should return defaults when settings is undefined', () => {
const res = taxonomiesConfig();
expect(res).toStrictEqual({
tags: { enabled: false, title: 'Tags' },
categories: { enabled: false, title: 'Categories' },
describe('utils/settings', () => {
describe('taxonomies', () => {
test('Should return defaults when settings is undefined', () => {
const res = taxonomiesConfig();
expect(res).toStrictEqual({
tags: { enabled: false, title: 'Tags' },
categories: { enabled: false, title: 'Categories' },
});
});
});
test('Should enable a taxonomy when enabled is true', () => {
const res = taxonomiesConfig({ tags: { enabled: true } });
expect(res.tags).toStrictEqual({ enabled: true, title: 'Tags' });
});
test('Should keep taxonomy disabled when enabled is true', () => {
const res = taxonomiesConfig({ categories: { enabled: true } });
expect(res.categories).toStrictEqual({ enabled: true, title: 'Categories' });
});
test('Should default to enabled=true when enabled is omitted but key exists', () => {
const res = taxonomiesConfig({ tags: {} });
expect(res.tags).toStrictEqual({ enabled: true, title: 'Tags' });
});
test('Should trim title when provided', () => {
const res = taxonomiesConfig({ tags: { title: ' My Tags ' } });
expect(res.tags).toStrictEqual({ enabled: true, title: 'My Tags' });
});
test('Should ignore unknown taxonomy keys', () => {
const input = {
unknownKey: { enabled: true, title: 'X' },
tags: { enabled: true, title: 'Tagz' },
};
const res = taxonomiesConfig(input);
expect(res).toStrictEqual({
tags: { enabled: true, title: 'Tagz' },
categories: { enabled: false, title: 'Categories' },
test('Should enable a taxonomy when enabled is true', () => {
const res = taxonomiesConfig({ tags: { enabled: true } });
expect(res.tags).toStrictEqual({ enabled: true, title: 'Tags' });
});
});
test('Should not change title when title is undefined', () => {
const res = taxonomiesConfig({ categories: { enabled: true, title: undefined } });
expect(res.categories).toStrictEqual({ enabled: true, title: 'Categories' });
test('Should keep taxonomy disabled when enabled is explicitly false', () => {
const res = taxonomiesConfig({ categories: { enabled: false } });
expect(res.categories).toStrictEqual({ enabled: false, title: 'Categories' });
});
test('Should default to enabled=true when enabled is omitted but key exists', () => {
const res = taxonomiesConfig({ tags: {} });
expect(res.tags).toStrictEqual({ enabled: true, title: 'Tags' });
});
test('Should trim title when provided', () => {
const res = taxonomiesConfig({ tags: { title: ' My Tags ' } });
expect(res.tags).toStrictEqual({ enabled: true, title: 'My Tags' });
});
test('Should ignore unknown taxonomy keys', () => {
const input = {
unknownKey: { enabled: true, title: 'X' },
tags: { enabled: true, title: 'Tagz' },
};
const res = taxonomiesConfig(input);
expect(res).toStrictEqual({
tags: { enabled: true, title: 'Tagz' },
categories: { enabled: false, title: 'Categories' },
});
});
test('Should not change title when title is undefined', () => {
const res = taxonomiesConfig({ categories: { enabled: true, title: undefined } });
expect(res.categories).toStrictEqual({ enabled: true, title: 'Categories' });
});
});
});