import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { formatRelativeTime } from "../format-date";

describe("formatRelativeTime", () => {
  beforeEach(() => {
    vi.useFakeTimers();
    vi.setSystemTime(new Date("2026-06-17T12:00:00Z"));
  });
  afterEach(() => {
    vi.useRealTimers();
  });

  it("returns 'just now' for < 45s", () => {
    expect(formatRelativeTime("2026-06-17T11:59:30Z")).toBe("just now");
  });

  it("returns '5m ago' for ~5 minutes", () => {
    expect(formatRelativeTime("2026-06-17T11:55:00Z")).toBe("5m ago");
  });

  it("returns '2h ago' for ~2 hours", () => {
    expect(formatRelativeTime("2026-06-17T10:00:00Z")).toBe("2h ago");
  });

  it("returns 'yesterday' for 1 day", () => {
    expect(formatRelativeTime("2026-06-16T12:00:00Z")).toBe("yesterday");
  });

  it("returns '3d ago' for 3 days", () => {
    expect(formatRelativeTime("2026-06-14T12:00:00Z")).toBe("3d ago");
  });

  it("returns MM/DD/YYYY for > 7 days", () => {
    expect(formatRelativeTime("2026-06-01T12:00:00Z")).toBe("06/01/2026");
  });
});
