@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
167 lines • 8.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const filevitural_1 = require("../vo/filevitural");
const fileinfo_1 = require("../vo/fileinfo");
// Mock dependencies
jest.mock('../vo/fileinfo');
jest.mock('../vo/filemeta', () => ({
newFileMeta: jest.fn().mockImplementation((filename) => ({
fileName: jest.fn().mockReturnValue(filename),
relativeFilename: jest.fn().mockReturnValue(filename),
component: jest.fn().mockReturnValue(''),
root: jest.fn().mockReturnValue(''),
open: jest.fn(),
setComponentRoot: jest.fn(),
setComponentDir: jest.fn(),
})),
}));
describe('FileVirtual Value Object', () => {
afterEach(() => {
jest.clearAllMocks();
// Reset global virtual file instance
global.globalVirtualFile = null;
});
describe('Virtual File functionality', () => {
it('should be tested through public interfaces', () => {
// Since VirtualFileInfo is private, we test through public functions
const result = (0, filevitural_1.newFileInfoWithName)('test.txt');
expect(result).toBeDefined();
expect(fileinfo_1.FileInfo).toHaveBeenCalled();
});
});
describe('Virtual File creation', () => {
it('should be tested through public interfaces', () => {
// Since VirtualFile is private, we test through public functions
const result = (0, filevitural_1.newFileInfoWithContent)('Test content');
expect(result).toBeDefined();
expect(fileinfo_1.FileInfo).toHaveBeenCalled();
});
});
describe('global virtual file functionality', () => {
it('should be tested through newFileInfoWithName', () => {
// Test global virtual file through public interface
const result1 = (0, filevitural_1.newFileInfoWithName)('file1.txt');
const result2 = (0, filevitural_1.newFileInfoWithName)('file2.txt');
expect(result1).toBeDefined();
expect(result2).toBeDefined();
expect(fileinfo_1.FileInfo).toHaveBeenCalledTimes(2);
});
});
describe('content-based virtual file functionality', () => {
it('should be tested through newFileInfoWithContent', () => {
// Test content-based virtual files through public interface
const result1 = (0, filevitural_1.newFileInfoWithContent)('Content 1');
const result2 = (0, filevitural_1.newFileInfoWithContent)('Content 2');
expect(result1).toBeDefined();
expect(result2).toBeDefined();
expect(fileinfo_1.FileInfo).toHaveBeenCalledTimes(2);
});
it('should handle various content types', () => {
const contents = ['', 'Simple text', 'Unicode: 🎉', '{"json": "data"}'];
contents.forEach(content => {
const result = (0, filevitural_1.newFileInfoWithContent)(content);
expect(result).toBeDefined();
});
expect(fileinfo_1.FileInfo).toHaveBeenCalledTimes(contents.length);
});
});
describe('newFileInfoWithName', () => {
it('should create FileInfo with virtual file and filename', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
const mockFileInfoInstance = {
name: jest.fn(),
meta: jest.fn(),
};
mockFileInfoConstructor.mockImplementation(() => mockFileInfoInstance);
const filename = '/test/virtual.txt';
const result = (0, filevitural_1.newFileInfoWithName)(filename);
expect(fileinfo_1.FileInfo).toHaveBeenCalledWith(expect.any(Object), // Virtual file info
expect.any(Object) // File meta
);
expect(result).toBe(mockFileInfoInstance);
});
it('should use global virtual file info', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
mockFileInfoConstructor.mockImplementation(() => ({}));
(0, filevitural_1.newFileInfoWithName)('/test/file.txt');
// Verify that FileInfo was called with virtual file info
expect(fileinfo_1.FileInfo).toHaveBeenCalledWith(expect.objectContaining({
name: expect.any(Function),
size: expect.any(Function),
mode: expect.any(Function),
modTime: expect.any(Function),
isDir: expect.any(Function),
sys: expect.any(Function),
}), expect.any(Object));
});
it('should handle different filename formats', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
mockFileInfoConstructor.mockImplementation(() => ({}));
const filenames = [
'/absolute/path/file.txt',
'relative/file.txt',
'simple.txt',
'/path/with spaces/file.txt',
'/path/with-dashes/file_underscore.txt',
];
filenames.forEach(filename => {
(0, filevitural_1.newFileInfoWithName)(filename);
expect(fileinfo_1.FileInfo).toHaveBeenCalled();
});
expect(fileinfo_1.FileInfo).toHaveBeenCalledTimes(filenames.length);
});
});
describe('newFileInfoWithContent', () => {
it('should create FileInfo with virtual file and content', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
const mockFileInfoInstance = {
name: jest.fn(),
meta: jest.fn(),
};
mockFileInfoConstructor.mockImplementation(() => mockFileInfoInstance);
const content = 'Test virtual file content';
const result = (0, filevitural_1.newFileInfoWithContent)(content);
expect(fileinfo_1.FileInfo).toHaveBeenCalledWith(expect.any(Object), // Virtual file info
expect.any(Object) // File meta
);
expect(result).toBe(mockFileInfoInstance);
});
it('should create unique virtual files for different content', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
mockFileInfoConstructor.mockImplementation(() => ({}));
const content1 = 'First content';
const content2 = 'Second content';
(0, filevitural_1.newFileInfoWithContent)(content1);
(0, filevitural_1.newFileInfoWithContent)(content2);
expect(fileinfo_1.FileInfo).toHaveBeenCalledTimes(2);
});
});
describe('integration tests', () => {
it('should work with FileInfo and FileMeta integration', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
mockFileInfoConstructor.mockImplementation(() => ({
name: jest.fn().mockReturnValue('test.txt'),
meta: jest.fn().mockReturnValue({
fileName: jest.fn().mockReturnValue('/test.txt'),
}),
}));
const result = (0, filevitural_1.newFileInfoWithName)('/test.txt');
expect(result).toBeDefined();
expect(fileinfo_1.FileInfo).toHaveBeenCalledWith(expect.any(Object), expect.any(Object));
});
});
describe('error handling', () => {
it('should handle null filename gracefully', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
mockFileInfoConstructor.mockImplementation(() => ({}));
expect(() => (0, filevitural_1.newFileInfoWithName)(null)).not.toThrow();
});
it('should handle very long filenames', () => {
const mockFileInfoConstructor = fileinfo_1.FileInfo;
mockFileInfoConstructor.mockImplementation(() => ({}));
const longFilename = '/very/long/path/' + 'a'.repeat(1000) + '.txt';
expect(() => (0, filevitural_1.newFileInfoWithName)(longFilename)).not.toThrow();
});
});
});
//# sourceMappingURL=vo-filevitural.test.js.map