import { describe, it, expect } from 'vitest';
import { formatRelativeTime } from './time-utils';

const NOW = new Date('2026-04-21T12:00:00Z');

describe('formatRelativeTime', () => {
  it('returns "just now" for < 30s', () => {
    expect(formatRelativeTime('2026-04-21T11:59:50Z', NOW)).toBe('just now');
  });

  it('returns minutes for < 60m', () => {
    expect(formatRelativeTime('2026-04-21T11:57:00Z', NOW)).toBe('3m ago');
  });

  it('returns hours for < 24h', () => {
    expect(formatRelativeTime('2026-04-21T10:00:00Z', NOW)).toBe('2h ago');
  });

  it('returns days for < 30d', () => {
    expect(formatRelativeTime('2026-04-18T12:00:00Z', NOW)).toBe('3d ago');
  });

  it('returns locale date string for older than 30d', () => {
    const out = formatRelativeTime('2025-01-01T00:00:00Z', NOW);
    expect(out).not.toMatch(/ago$/);
    expect(out.length).toBeGreaterThan(0);
  });

  it('handles future timestamps by clamping to "just now"', () => {
    expect(formatRelativeTime('2026-04-21T12:00:30Z', NOW)).toBe('just now');
  });
});
