refactor: load project

This commit is contained in:
Carlos Valente
2024-07-02 16:52:18 +02:00
committed by Carlos Valente
parent 9c5e403b18
commit 751c3329f0
11 changed files with 153 additions and 87 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { ensureJsonExtension } from '../fileManagement.js';
import { appendToName, ensureJsonExtension } from '../fileManagement.js';
describe('ensureJsonExtension', () => {
it('should add .json to a filename without an extension', () => {
@@ -26,3 +26,26 @@ describe('ensureJsonExtension', () => {
expect(result).toBe('my.test.file.json');
});
});
describe('appendToName', () => {
it('appends a given string to a file name', () => {
const filename = 'file.json';
const append = '(recovered)';
const result = appendToName(filename, append);
expect(result).toBe('file (recovered).json');
});
it('handles paths', () => {
const path = '/Users/carlos/Library/Application Support/Ontime/projects/file.json';
const append = '(recovered)';
const result = appendToName(path, append);
expect(result).toBe('/Users/carlos/Library/Application Support/Ontime/projects/file (recovered).json');
});
it('handles multiple . in string', () => {
const path = 'strange.file.name.json';
const append = '(recovered)';
const result = appendToName(path, append);
expect(result).toBe('strange.file.name (recovered).json');
});
});