/**
 * Example and edge-case unit tests for the resolution-date helper.
 *
 * Spec: .kiro/specs/compliance-metric-estimated-resolution-date
 * Task: 1.7 — Example and edge-case unit tests for the helper
 * Requirements: 1.1, 1.4, 1.6, 2.1
 *
 * These concrete fixtures anchor the contract of `formatResolutionDate` and
 * double as regression cases. The universal behavior is covered separately by
 * the property-based tests in `resolutionDate.property.test.js`.
 */

import {
  formatResolutionDate,
  RESOLUTION_DATE_LABEL,
  NO_DATE_PLACEHOLDER,
  INVALID_DATE_PLACEHOLDER,
} from '../resolutionDate';

describe('formatResolutionDate', () => {
  describe('set — valid calendar dates (Requirements 1.1, 1.4)', () => {
    it("classifies '2026-07-01' as set with the normalized YYYY-MM-DD value", () => {
      expect(formatResolutionDate('2026-07-01')).toEqual({
        state: 'set',
        value: '2026-07-01',
      });
    });

    it("classifies the leap day '2024-02-29' as set (2024 is a leap year)", () => {
      expect(formatResolutionDate('2024-02-29')).toEqual({
        state: 'set',
        value: '2024-02-29',
      });
    });

    it("classifies an ISO datetime '2026-07-03T00:00:00.000Z' as set with the date prefix", () => {
      expect(formatResolutionDate('2026-07-03T00:00:00.000Z')).toEqual({
        state: 'set',
        value: '2026-07-03',
      });
    });
  });

  describe('invalid — present but not a valid calendar date (Requirement 1.6)', () => {
    it("classifies '2026-7-1' as invalid (components not zero-padded)", () => {
      expect(formatResolutionDate('2026-7-1')).toEqual({ state: 'invalid' });
    });

    it("classifies '07/01/2026' as invalid (wrong shape / separators)", () => {
      expect(formatResolutionDate('07/01/2026')).toEqual({ state: 'invalid' });
    });

    it("classifies '2023-02-29' as invalid (2023 is not a leap year)", () => {
      expect(formatResolutionDate('2023-02-29')).toEqual({ state: 'invalid' });
    });

    it("classifies '2026-13-01' as invalid (month out of range)", () => {
      expect(formatResolutionDate('2026-13-01')).toEqual({ state: 'invalid' });
    });

    it("classifies '2026-00-10' as invalid (month below range)", () => {
      expect(formatResolutionDate('2026-00-10')).toEqual({ state: 'invalid' });
    });

    it("classifies '2026-01-32' as invalid (day above month length)", () => {
      expect(formatResolutionDate('2026-01-32')).toEqual({ state: 'invalid' });
    });
  });

  describe('none — absent values (Requirements 2.1)', () => {
    it('classifies whitespace-only input as none', () => {
      expect(formatResolutionDate('  ')).toEqual({ state: 'none' });
    });

    it('classifies null as none', () => {
      expect(formatResolutionDate(null)).toEqual({ state: 'none' });
    });

    it('classifies undefined as none', () => {
      expect(formatResolutionDate(undefined)).toEqual({ state: 'none' });
    });

    it('classifies the empty string as none', () => {
      expect(formatResolutionDate('')).toEqual({ state: 'none' });
    });
  });

  describe('display constants', () => {
    it('exposes the expected label and placeholder strings', () => {
      expect(RESOLUTION_DATE_LABEL).toBe('Est. Resolution');
      expect(NO_DATE_PLACEHOLDER).toBe('not set');
      expect(INVALID_DATE_PLACEHOLDER).toBe('invalid date');
    });
  });
});
