import formatDateToLocalTime from './dateFormat.js';

describe('formatDateToLocalTime', () => {
  test('returns empty string for null input', () => {
    expect(formatDateToLocalTime(null)).toBe('');
  });

  test('returns empty string for undefined input', () => {
    expect(formatDateToLocalTime(undefined)).toBe('');
  });

  test('returns empty string for empty string input', () => {
    expect(formatDateToLocalTime('')).toBe('');
  });

  test('formats a valid ISO string', () => {
    const isoString = '2024-01-15T10:30:00Z';
    const result = formatDateToLocalTime(isoString);
    expect(result).toBeDefined();
    expect(typeof result).toBe('string');
    expect(result.length).toBeGreaterThan(0);
  });

  test('result contains time components', () => {
    const isoString = '2024-01-15T10:30:00Z';
    const result = formatDateToLocalTime(isoString);
    expect(result).toMatch(/\d{1,2}:\d{2}:\d{2}/);
  });

  test('handles date without time', () => {
    const isoString = '2024-01-15';
    const result = formatDateToLocalTime(isoString);
    expect(result).toBeDefined();
    expect(result.length).toBeGreaterThan(0);
  });

  test('handles current date', () => {
    const now = new Date().toISOString();
    const result = formatDateToLocalTime(now);
    expect(result).toBeDefined();
    expect(result.length).toBeGreaterThan(0);
  });

  test('result contains AM or PM', () => {
    const isoString = '2024-01-15T14:30:00Z';
    const result = formatDateToLocalTime(isoString);
    expect(result).toMatch(/(AM|PM)/);
  });

  test('result contains year', () => {
    const isoString = '2024-01-15T10:30:00Z';
    const result = formatDateToLocalTime(isoString);
    expect(result).toMatch(/2024/);
  });

  test('handles midnight time', () => {
    const isoString = '2024-01-15T00:00:00Z';
    const result = formatDateToLocalTime(isoString);
    expect(result).toBeDefined();
    expect(result.length).toBeGreaterThan(0);
  });

  test('handles noon time', () => {
    const isoString = '2024-01-15T12:00:00Z';
    const result = formatDateToLocalTime(isoString);
    expect(result).toBeDefined();
    expect(result.length).toBeGreaterThan(0);
  });

  test('formatted output is a string', () => {
    const isoString = '2024-01-15T10:30:00Z';
    const result = formatDateToLocalTime(isoString);
    expect(typeof result).toBe('string');
  });
});
