UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

165 lines 8.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const root_1 = require("../vo/root"); describe('Root Value Object', () => { describe('DefaultRootConfig', () => { it('should have correct default values', () => { expect(root_1.DefaultRootConfig.baseURL).toBe(''); expect(root_1.DefaultRootConfig.title).toBe(''); expect(root_1.DefaultRootConfig.theme).toEqual([]); expect(root_1.DefaultRootConfig.timeout).toBe('30s'); expect(root_1.DefaultRootConfig.contentDir).toBe('content'); expect(root_1.DefaultRootConfig.dataDir).toBe('data'); expect(root_1.DefaultRootConfig.layoutDir).toBe('layouts'); expect(root_1.DefaultRootConfig.staticDir).toBe('static'); expect(root_1.DefaultRootConfig.archetypeDir).toBe('archetypes'); expect(root_1.DefaultRootConfig.assetDir).toBe('assets'); expect(root_1.DefaultRootConfig.publishDir).toBe('public'); expect(root_1.DefaultRootConfig.buildDrafts).toBe(false); expect(root_1.DefaultRootConfig.buildExpired).toBe(false); expect(root_1.DefaultRootConfig.buildFuture).toBe(false); expect(root_1.DefaultRootConfig.copyright).toBe(''); expect(root_1.DefaultRootConfig.defaultContentLanguage).toBe('en'); expect(root_1.DefaultRootConfig.defaultContentLanguageInSubdir).toBe(false); expect(root_1.DefaultRootConfig.disableAliases).toBe(false); expect(root_1.DefaultRootConfig.disablePathToLower).toBe(false); expect(root_1.DefaultRootConfig.disableKinds).toEqual([]); expect(root_1.DefaultRootConfig.disableLanguages).toEqual([]); expect(root_1.DefaultRootConfig.renderSegments).toEqual([]); expect(root_1.DefaultRootConfig.disableHugoGeneratorInject).toBe(false); expect(root_1.DefaultRootConfig.disableLiveReload).toBe(false); expect(root_1.DefaultRootConfig.enableEmoji).toBe(false); }); }); describe('decodeRootConfig', () => { it('should decode empty data with default values', () => { const config = (0, root_1.decodeRootConfig)({}); expect(config.baseURL).toBe(''); expect(config.title).toBe(''); expect(config.theme).toEqual([]); expect(config.timeout).toBe('30s'); expect(config.contentDir).toBe('content'); expect(config.defaultContentLanguage).toBe('en'); expect(config.buildDrafts).toBe(false); expect(config.enableEmoji).toBe(false); }); it('should decode custom configuration data', () => { const inputData = { baseURL: 'https://example.com', title: 'My Blog', theme: ['mytheme', 'fallback'], timeout: '60s', contentDir: 'posts', buildDrafts: true, buildFuture: true, enableEmoji: true, defaultContentLanguage: 'zh', disableKinds: ['RSS', 'sitemap'], copyright: '© 2024 My Blog' }; const config = (0, root_1.decodeRootConfig)(inputData); expect(config.baseURL).toBe('https://example.com'); expect(config.title).toBe('My Blog'); expect(config.theme).toEqual(['mytheme', 'fallback']); expect(config.timeout).toBe('60s'); expect(config.contentDir).toBe('posts'); expect(config.buildDrafts).toBe(true); expect(config.buildFuture).toBe(true); expect(config.enableEmoji).toBe(true); expect(config.defaultContentLanguage).toBe('zh'); expect(config.disableKinds).toEqual(['RSS', 'sitemap']); expect(config.copyright).toBe('© 2024 My Blog'); }); it('should handle boolean fields correctly', () => { // Test explicit false values const falseData = { buildDrafts: false, buildExpired: false, buildFuture: false, disableAliases: false, enableEmoji: false }; const falseConfig = (0, root_1.decodeRootConfig)(falseData); expect(falseConfig.buildDrafts).toBe(false); expect(falseConfig.buildExpired).toBe(false); expect(falseConfig.buildFuture).toBe(false); expect(falseConfig.disableAliases).toBe(false); expect(falseConfig.enableEmoji).toBe(false); // Test explicit true values const trueData = { buildDrafts: true, buildExpired: true, buildFuture: true, disableAliases: true, enableEmoji: true }; const trueConfig = (0, root_1.decodeRootConfig)(trueData); expect(trueConfig.buildDrafts).toBe(true); expect(trueConfig.buildExpired).toBe(true); expect(trueConfig.buildFuture).toBe(true); expect(trueConfig.disableAliases).toBe(true); expect(trueConfig.enableEmoji).toBe(true); }); it('should handle array fields correctly', () => { const data = { theme: ['theme1', 'theme2', 'theme3'], disableKinds: ['RSS', 'sitemap', 'taxonomy'], disableLanguages: ['fr', 'de'], renderSegments: ['page', 'home'] }; const config = (0, root_1.decodeRootConfig)(data); expect(config.theme).toEqual(['theme1', 'theme2', 'theme3']); expect(config.disableKinds).toEqual(['RSS', 'sitemap', 'taxonomy']); expect(config.disableLanguages).toEqual(['fr', 'de']); expect(config.renderSegments).toEqual(['page', 'home']); }); it('should handle partial configuration data', () => { const partialData = { title: 'Partial Config', buildDrafts: true, theme: ['custom-theme'] // Other fields should use defaults }; const config = (0, root_1.decodeRootConfig)(partialData); expect(config.title).toBe('Partial Config'); expect(config.buildDrafts).toBe(true); expect(config.theme).toEqual(['custom-theme']); // Should use defaults for missing fields expect(config.baseURL).toBe(''); expect(config.contentDir).toBe('content'); expect(config.defaultContentLanguage).toBe('en'); expect(config.buildExpired).toBe(false); }); it('should preserve complex nested boolean logic', () => { const complexData = { defaultContentLanguageInSubdir: true, disableHugoGeneratorInject: true, disableLiveReload: true, disablePathToLower: true }; const config = (0, root_1.decodeRootConfig)(complexData); expect(config.defaultContentLanguageInSubdir).toBe(true); expect(config.disableHugoGeneratorInject).toBe(true); expect(config.disableLiveReload).toBe(true); expect(config.disablePathToLower).toBe(true); }); it('should handle null and undefined values gracefully', () => { const dataWithNulls = { title: null, theme: undefined, buildDrafts: null, disableKinds: null }; const config = (0, root_1.decodeRootConfig)(dataWithNulls); // Null/undefined string values should fallback to defaults expect(config.title).toBe(''); // default expect(config.theme).toEqual([]); // default // Null boolean values should use the ternary logic in decodeRootConfig // which checks for undefined, so null will be passed through expect(config.buildDrafts).toBe(null); // null is passed through // Null array values should fallback to defaults expect(config.disableKinds).toEqual([]); // default }); }); }); //# sourceMappingURL=vo-root.test.js.map