import {
  fahrenheitToCelsius,
  celsiusToFahrenheit,
  convertTemperature,
  formatTemperature,
} from '../../../src/lib/utils/conversions';

describe('Temperature Conversions', () => {
  describe('fahrenheitToCelsius', () => {
    it('converts 32°F to 0°C', () => {
      expect(fahrenheitToCelsius(32)).toBe(0);
    });

    it('converts 212°F to 100°C', () => {
      expect(fahrenheitToCelsius(212)).toBe(100);
    });

    it('converts 2232°F (cone 6) to approximately 1222°C', () => {
      const result = fahrenheitToCelsius(2232);
      expect(Math.round(result)).toBe(1222);
    });
  });

  describe('celsiusToFahrenheit', () => {
    it('converts 0°C to 32°F', () => {
      expect(celsiusToFahrenheit(0)).toBe(32);
    });

    it('converts 100°C to 212°F', () => {
      expect(celsiusToFahrenheit(100)).toBe(212);
    });
  });

  describe('convertTemperature', () => {
    it('returns same temperature if units match', () => {
      const temp = { value: 100, unit: 'F' as const };
      const result = convertTemperature(temp, 'F');
      expect(result).toEqual(temp);
    });

    it('converts from F to C', () => {
      const temp = { value: 2232, unit: 'F' as const };
      const result = convertTemperature(temp, 'C');
      expect(result.value).toBe(1222);
      expect(result.unit).toBe('C');
    });

    it('converts from C to F', () => {
      const temp = { value: 1222, unit: 'C' as const };
      const result = convertTemperature(temp, 'F');
      expect(result.value).toBe(2232);
      expect(result.unit).toBe('F');
    });
  });

  describe('formatTemperature', () => {
    it('formats Fahrenheit temperature', () => {
      const temp = { value: 2232, unit: 'F' as const };
      expect(formatTemperature(temp)).toBe('2232°F');
    });

    it('formats Celsius temperature', () => {
      const temp = { value: 1222, unit: 'C' as const };
      expect(formatTemperature(temp)).toBe('1222°C');
    });
  });
});
