ueberpruefen
This commit is contained in:
52
__tests__/lib/utils/datetime.test.ts
Normal file
52
__tests__/lib/utils/datetime.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
formatDuration,
|
||||
parseDuration,
|
||||
} from '../../../src/lib/utils/datetime';
|
||||
|
||||
describe('DateTime Utils', () => {
|
||||
describe('formatDuration', () => {
|
||||
it('formats minutes to h:mm', () => {
|
||||
expect(formatDuration(60)).toBe('1:00');
|
||||
expect(formatDuration(90)).toBe('1:30');
|
||||
expect(formatDuration(125)).toBe('2:05');
|
||||
expect(formatDuration(600)).toBe('10:00');
|
||||
});
|
||||
|
||||
it('handles zero minutes', () => {
|
||||
expect(formatDuration(0)).toBe('0:00');
|
||||
});
|
||||
|
||||
it('handles less than 60 minutes', () => {
|
||||
expect(formatDuration(45)).toBe('0:45');
|
||||
expect(formatDuration(5)).toBe('0:05');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseDuration', () => {
|
||||
it('parses h:mm to minutes', () => {
|
||||
expect(parseDuration('1:00')).toBe(60);
|
||||
expect(parseDuration('1:30')).toBe(90);
|
||||
expect(parseDuration('2:05')).toBe(125);
|
||||
expect(parseDuration('10:00')).toBe(600);
|
||||
});
|
||||
|
||||
it('returns null for invalid format', () => {
|
||||
expect(parseDuration('1:5')).toBeNull(); // missing leading zero
|
||||
expect(parseDuration('abc')).toBeNull();
|
||||
expect(parseDuration('1:60')).toBeNull(); // invalid minutes
|
||||
});
|
||||
|
||||
it('handles zero duration', () => {
|
||||
expect(parseDuration('0:00')).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('roundtrip conversion', () => {
|
||||
it('format and parse roundtrip correctly', () => {
|
||||
const minutes = 125;
|
||||
const formatted = formatDuration(minutes);
|
||||
const parsed = parseDuration(formatted);
|
||||
expect(parsed).toBe(minutes);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user