import { describe, expect, it, vi } from 'vitest';
import { formatDate, formatDateTime } from './DateTime';

describe('DateTime', () => {
  const languageGetter = vi.spyOn(window.navigator, 'language', 'get');

  languageGetter.mockReturnValue('en-US');

  const dateString = '2020-09-09T09:30:15.000';
  const falseDateString = 'test';

  describe('formatDateTime', () => {
    it('should return a formatted value for a given date time string', () => {
      expect(formatDateTime(dateString)).toBe('9/9/2020, 9:30 AM');
    });

    it('should handle malformed values', () => {
      expect(formatDateTime(falseDateString)).toBe(falseDateString);
    });
  });

  describe('formatDate', () => {
    it('should return a formatted value for a given date string', () => {
      expect(formatDate(dateString)).toBe('9/9/2020');
    });

    it('should handle malformed values', () => {
      expect(formatDate(falseDateString)).toBe(falseDateString);
    });
  });
});
