import { describe, expect, it } from 'vitest';

import { formatMessageDateLabel, getCalendarDayKey } from '../messageDate';

describe('messageDate', () => {
  it('groups an absolute timestamp by the requested timezone', () => {
    const timestamp = Date.UTC(2026, 6, 12, 23, 30);

    expect(getCalendarDayKey(timestamp, 'UTC')).toBe('2026-07-12');
    expect(getCalendarDayKey(timestamp, 'Asia/Makassar')).toBe('2026-07-13');
  });

  it('formats today and yesterday relative to the display timezone', () => {
    const now = Date.UTC(2026, 6, 13, 12);

    expect(
      formatMessageDateLabel(Date.UTC(2026, 6, 13, 1), {
        locale: 'en-US',
        timeZone: 'UTC',
        now,
      }),
    ).toBe('Today');
    expect(
      formatMessageDateLabel(Date.UTC(2026, 6, 12, 23), {
        locale: 'en-US',
        timeZone: 'UTC',
        now,
      }),
    ).toBe('Yesterday');
  });

  it('includes the year only when the message is outside the current year', () => {
    const now = Date.UTC(2026, 6, 13, 12);

    expect(
      formatMessageDateLabel(Date.UTC(2026, 6, 4, 12), {
        locale: 'en-US',
        timeZone: 'UTC',
        now,
      }),
    ).toBe('Saturday, July 4');
    expect(
      formatMessageDateLabel(Date.UTC(2025, 6, 4, 12), {
        locale: 'en-US',
        timeZone: 'UTC',
        now,
      }),
    ).toBe('Friday, July 4, 2025');
  });
});
