42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { TimeFormatter } from './TimeFormatter';
|
|
|
|
describe('TimeFormatter', () => {
|
|
describe('timeAgo', () => {
|
|
it('should return "Just now" for less than 1 minute ago', () => {
|
|
const now = new Date();
|
|
const thirtySecondsAgo = new Date(now.getTime() - 30 * 1000);
|
|
const result = TimeFormatter.timeAgo(thirtySecondsAgo);
|
|
expect(result).toBe('Just now');
|
|
});
|
|
|
|
it('should return "X min ago" for less than 1 hour ago', () => {
|
|
const now = new Date();
|
|
const thirtyMinutesAgo = new Date(now.getTime() - 30 * 60 * 1000);
|
|
const result = TimeFormatter.timeAgo(thirtyMinutesAgo);
|
|
expect(result).toBe('30 min ago');
|
|
});
|
|
|
|
it('should return "X h ago" for less than 24 hours ago', () => {
|
|
const now = new Date();
|
|
const fiveHoursAgo = new Date(now.getTime() - 5 * 60 * 60 * 1000);
|
|
const result = TimeFormatter.timeAgo(fiveHoursAgo);
|
|
expect(result).toBe('5 h ago');
|
|
});
|
|
|
|
it('should return "X d ago" for 24 hours or more ago', () => {
|
|
const now = new Date();
|
|
const twoDaysAgo = new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000);
|
|
const result = TimeFormatter.timeAgo(twoDaysAgo);
|
|
expect(result).toBe('2 d ago');
|
|
});
|
|
|
|
it('should handle string input', () => {
|
|
const now = new Date();
|
|
const thirtyMinutesAgo = new Date(now.getTime() - 30 * 60 * 1000);
|
|
const result = TimeFormatter.timeAgo(thirtyMinutesAgo.toISOString());
|
|
expect(result).toBe('30 min ago');
|
|
});
|
|
});
|
|
});
|