Files
familienarchiv/frontend/src/lib/shared/utils.spec.ts
Marcel 567612761d refactor: move lib-root files to lib/shared/ and finalize domain structure
- Move api.server.ts, errors.ts, types.ts, utils.ts, relativeTime.ts to lib/shared/
- Move person relationship components to lib/person/relationship/
- Move Stammbaum components to lib/person/genealogy/
- Move HelpPopover to lib/shared/primitives/
- Update all import paths across routes, specs, and lib files
- Update vi.mock() paths in server-project test files
- Remove now-empty legacy directories (components/, hooks/, server/, etc.)
- Update vite.config.ts coverage include paths for new structure
- Update frontend/CLAUDE.md to reflect domain-based lib/ layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 14:53:31 +02:00

81 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { germanToIso, isoToGerman } from './utils';
describe('isoToGerman', () => {
it('converts a standard ISO date', () => {
expect(isoToGerman('2024-03-15')).toBe('15.03.2024');
});
it('preserves leading zeros for day and month', () => {
expect(isoToGerman('2024-01-05')).toBe('05.01.2024');
});
it('handles December 31', () => {
expect(isoToGerman('1945-12-31')).toBe('31.12.1945');
});
it('returns empty string for empty input', () => {
expect(isoToGerman('')).toBe('');
});
it('returns empty string for plain text', () => {
expect(isoToGerman('not-a-date')).toBe('');
});
it('returns empty string for partial ISO string', () => {
expect(isoToGerman('2024-03')).toBe('');
});
it('returns empty string for ISO with time component', () => {
expect(isoToGerman('2024-03-15T12:00:00')).toBe('');
});
});
describe('germanToIso', () => {
it('converts a standard German date', () => {
expect(germanToIso('15.03.2024')).toBe('2024-03-15');
});
it('preserves leading zeros for day and month', () => {
expect(germanToIso('05.01.2024')).toBe('2024-01-05');
});
it('handles December 31', () => {
expect(germanToIso('31.12.1945')).toBe('1945-12-31');
});
it('returns empty string for empty input', () => {
expect(germanToIso('')).toBe('');
});
it('returns empty string for plain text', () => {
expect(germanToIso('not-a-date')).toBe('');
});
it('returns empty string for date without leading zeros', () => {
expect(germanToIso('5.3.2024')).toBe('');
});
it('returns empty string for ISO format input', () => {
expect(germanToIso('2024-03-15')).toBe('');
});
it('returns empty string for partial German date', () => {
expect(germanToIso('15.03')).toBe('');
});
});
describe('round-trip conversion', () => {
const dates = ['2024-03-15', '1945-01-01', '2000-12-31', '1899-07-04'];
for (const date of dates) {
it(`ISO → German → ISO is identity for ${date}`, () => {
expect(germanToIso(isoToGerman(date))).toBe(date);
});
}
it('German → ISO → German is identity', () => {
expect(isoToGerman(germanToIso('20.04.1889'))).toBe('20.04.1889');
});
});