All checks were successful
continuous-integration/drone/push Build is passing
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
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('');
|
|
});
|
|
});
|