import { buildSelectionRange, formatDateValue, formatRangeLabel, parseDateValue } from './dateUtils';

describe('dateUtils', () => {
  test('parseDateValue returns null for invalid input', () => {
    expect(parseDateValue('invalid')).toBeNull();
    expect(parseDateValue('')).toBeNull();
  });

  test('formatDateValue formats valid dates', () => {
    const date = new Date('2024-02-10T00:00:00.000Z');
    expect(formatDateValue(date)).toBe('2024-02-10');
  });

  test('formatRangeLabel handles ranges and single dates', () => {
    expect(formatRangeLabel('2024-02-10', '2024-02-10')).toBe('10.02.2024');
    expect(formatRangeLabel('2024-02-10', '2024-02-12')).toBe('10.02.2024 – 12.02.2024');
    expect(formatRangeLabel(null, null)).toBe('Zeitraum auswählen');
  });

  test('buildSelectionRange enforces minimum date', () => {
    const minDate = new Date('2024-05-01T00:00:00.000Z');
    const selection = buildSelectionRange('2024-04-01', '2024-04-05', minDate);
    expect(selection.startDate).toEqual(minDate);
    expect(selection.endDate).toEqual(minDate);
    expect(selection.key).toBe('selection');
  });
});
