formatter tests
Some checks failed
Some checks failed
This commit is contained in:
41
apps/website/lib/formatters/TimeFormatter.test.ts
Normal file
41
apps/website/lib/formatters/TimeFormatter.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user