/**
 * @file MessageList.test.tsx
 * @description Tests for formatTime utility in MessageList
 */

import { describe, it, expect } from "vitest";
import { formatTime } from "./MessageList";

describe("formatTime", () => {
  it("should format a valid ISO date string", () => {
    const result = formatTime("2024-06-15T14:30:00Z");
    // The exact output depends on locale, but it should not be empty or "Invalid date"
    expect(result).toBeTruthy();
    expect(result).not.toBe("Invalid date");
  });

  it('should return "Invalid date" for an invalid date string', () => {
    const result = formatTime("not-a-date");
    expect(result).toBe("Invalid date");
  });

  it('should return "Invalid date" for an empty string', () => {
    const result = formatTime("");
    expect(result).toBe("Invalid date");
  });

  it('should return "Invalid date" for garbage input', () => {
    const result = formatTime("abc123xyz");
    expect(result).toBe("Invalid date");
  });

  it("should handle a valid date without time component", () => {
    const result = formatTime("2024-01-01");
    expect(result).toBeTruthy();
    expect(result).not.toBe("Invalid date");
  });

  it("should handle Unix epoch", () => {
    const result = formatTime("1970-01-01T00:00:00Z");
    expect(result).toBeTruthy();
    expect(result).not.toBe("Invalid date");
  });
});
