Files
gridpilot.gg/apps/website/lib/formatters/TimeFormatter.test.ts
Marc Mintel 3db2209d2a
Some checks failed
CI / lint-typecheck (push) Failing after 4m52s
CI / tests (push) Has been skipped
CI / contract-tests (push) Has been skipped
CI / e2e-tests (push) Has been skipped
CI / comment-pr (push) Has been skipped
CI / commit-types (push) Has been skipped
formatter tests
2026-01-25 11:17:47 +01:00

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');
});
});
});