add unit tests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-24 11:14:24 +01:00
parent 7e938138ff
commit d7e144620e
23 changed files with 2766 additions and 17 deletions

View File

@@ -0,0 +1,43 @@
import { describe, expect, it } from 'vitest';
import { capitalize, formatDate, splitAndCapitalize } from '../../src/utils/formatting';
describe('formatDate', () => {
it('formats date in it-IT locale and includes seconds when requested', () => {
const withoutSeconds = formatDate('2026-01-01T12:34:56.000Z');
const withSeconds = formatDate('2026-01-01T12:34:56.000Z', true);
expect(withoutSeconds).toContain('2026');
expect(withSeconds).toContain('56');
});
});
describe('capitalize', () => {
it('capitalizes every space-delimited word', () => {
expect(capitalize('hello WORLD')).toBe('Hello World');
expect(capitalize('mUlTi SPACES')).toBe('Multi Spaces');
});
});
describe('splitAndCapitalize', () => {
it('splits underscore and hyphen mode', () => {
expect(splitAndCapitalize('hello_world-test', 'underscore')).toBe('Hello World Test');
});
it('splits camel mode with acronym and number boundaries', () => {
expect(splitAndCapitalize('helloWorldXML2Http', 'camel')).toBe('Hello World Xml 2 Http');
});
it('auto mode prefers underscore splitting when underscore-like chars exist', () => {
expect(splitAndCapitalize('user_name')).toBe('User Name');
expect(splitAndCapitalize('kebab-case')).toBe('Kebab Case');
});
it('auto mode falls back to camel splitting when underscore-like chars are absent', () => {
expect(splitAndCapitalize('helloWorldTest')).toBe('Hello World Test');
});
it('returns empty string for empty or missing input', () => {
expect(splitAndCapitalize('')).toBe('');
expect(splitAndCapitalize(undefined)).toBe('');
});
});