mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-03-22 12:33:11 -04:00
62 lines
2.5 KiB
TypeScript
62 lines
2.5 KiB
TypeScript
import { siteConfig } from '../../../src/static/js/utils/settings/site';
|
|
|
|
describe('utils/settings', () => {
|
|
describe('site', () => {
|
|
test('Applies defaults when no settings provided', () => {
|
|
const cfg = siteConfig();
|
|
expect(cfg).toStrictEqual({
|
|
id: 'media-cms',
|
|
url: '',
|
|
api: '',
|
|
title: '',
|
|
useRoundedCorners: true,
|
|
version: '1.0.0',
|
|
});
|
|
});
|
|
|
|
test('Trims string fields (id, url, api, title, version)', () => {
|
|
const cfg = siteConfig({
|
|
id: ' my-site ',
|
|
url: ' https://example.com/ ',
|
|
api: ' https://example.com/api/ ',
|
|
title: ' Media CMS ',
|
|
version: ' 2.3.4 ',
|
|
});
|
|
|
|
expect(cfg).toStrictEqual({
|
|
id: 'my-site',
|
|
url: 'https://example.com/',
|
|
api: 'https://example.com/api/',
|
|
title: 'Media CMS',
|
|
useRoundedCorners: true,
|
|
version: '2.3.4',
|
|
});
|
|
});
|
|
|
|
test('Handles useRoundedCorners: defaults to true unless explicitly false', () => {
|
|
expect(siteConfig({}).useRoundedCorners).toBe(true);
|
|
expect(siteConfig({ useRoundedCorners: true }).useRoundedCorners).toBe(true);
|
|
expect(siteConfig({ useRoundedCorners: false }).useRoundedCorners).toBe(false);
|
|
// non-boolean should still evaluate to default true because only === false toggles it off
|
|
expect(siteConfig({ useRoundedCorners: 'no' as any }).useRoundedCorners).toBe(true);
|
|
expect(siteConfig({ useRoundedCorners: 0 as any }).useRoundedCorners).toBe(true);
|
|
expect(siteConfig({ useRoundedCorners: null as any }).useRoundedCorners).toBe(true);
|
|
});
|
|
|
|
test('Is resilient to partial inputs and ignores extra properties', () => {
|
|
const cfg = siteConfig({ id: ' x ', extra: 'y' } as any);
|
|
expect(cfg).toMatchObject({ id: 'x' });
|
|
expect(Object.keys(cfg).sort()).toStrictEqual(
|
|
['api', 'id', 'title', 'url', 'useRoundedCorners', 'version'].sort()
|
|
);
|
|
});
|
|
|
|
test('Does not mutate input object', () => {
|
|
const input = { id: ' my-id ', useRoundedCorners: false };
|
|
const copy = JSON.parse(JSON.stringify(input));
|
|
siteConfig(input);
|
|
expect(input).toStrictEqual(copy);
|
|
});
|
|
});
|
|
});
|