Spaces:
Sleeping
Sleeping
File size: 1,567 Bytes
ebe1c3d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import { describe, it, expect } from 'vitest';
import { formatTimestamp, truncateText, classNames, formatDuration } from '../utils/helpers';
describe('helpers', () => {
describe('formatTimestamp', () => {
it('formats ISO timestamps', () => {
const result = formatTimestamp('2024-01-15T10:30:00Z');
expect(result).toBeDefined();
expect(typeof result).toBe('string');
});
it('handles invalid dates', () => {
const result = formatTimestamp('invalid');
expect(result).toBe('Invalid Date');
});
});
describe('truncateText', () => {
it('truncates long strings', () => {
const result = truncateText('This is a long string', 13);
expect(result).toBe('This is a ...');
});
it('leaves short strings unchanged', () => {
const result = truncateText('Short', 10);
expect(result).toBe('Short');
});
});
describe('classNames', () => {
it('joins class names', () => {
const result = classNames('a', 'b', 'c');
expect(result).toBe('a b c');
});
it('filters falsy values', () => {
const result = classNames('a', false, undefined, 'b', null, 'c');
expect(result).toBe('a b c');
});
});
describe('formatDuration', () => {
it('formats milliseconds to seconds', () => {
expect(formatDuration(45000)).toBe('45s');
});
it('formats minutes and seconds', () => {
expect(formatDuration(125000)).toBe('2m 5s');
});
it('formats hours', () => {
expect(formatDuration(3665000)).toBe('1h 1m');
});
});
});
|