import {
  getDecimalSeparator,
  getFormattedString,
  getGroupSeparator,
  getUnformattedNumber,
} from './utils';

describe('utils', () => {
  describe('getDecimalSeparator', () => {
    it('gets decimal separator for Spanish', () => {
      expect(getDecimalSeparator('EUR', 'es')).toBe(',');
    });

    it('gets decimal separator for English', () => {
      expect(getDecimalSeparator('EUR', 'en')).toBe('.');
    });

    it('gets decimal separator for Spanish in HUF', () => {
      expect(getDecimalSeparator('HUF', 'es')).toBe('');
    });

    it('gets decimal separator for English in HUF', () => {
      expect(getDecimalSeparator('HUF', 'en')).toBe('');
    });
  });

  describe('getGroupSeparator', () => {
    it('gets group separator for Spanish', () => {
      expect(getGroupSeparator('EUR', 'es')).toBe('.');
    });

    it('gets group separator for English', () => {
      expect(getGroupSeparator('EUR', 'en')).toBe(',');
    });

    it('gets group separator for French', () => {
      expect(getGroupSeparator('EUR', 'fr')).toBe(' ');
    });
  });

  describe('getUnformattedNumber', () => {
    it('can turn a Spanish string into a number', () => {
      expect(
        getUnformattedNumber({
          value: '123.456,00',
          currency: 'EUR',
          locale: 'es',
        }),
      ).toBe(123456);
    });

    it('can turn a French string into a number', () => {
      expect(
        getUnformattedNumber({
          value: '1 234 567,45',
          currency: 'EUR',
          locale: 'fr',
        }),
      ).toBe(1234567.45);
    });

    it('can turn a English string into a number', () => {
      expect(
        getUnformattedNumber({
          value: '123,456.78',
          currency: 'EUR',
          locale: 'en',
        }),
      ).toBe(123456.78);
    });

    it('can turn a Magyar string into a number', () => {
      expect(
        getUnformattedNumber({
          value: '11 000 000',
          currency: 'HUF',
          locale: 'hu',
        }),
      ).toBe(11000000);
    });
  });

  describe('getFormattedString', () => {
    it('can turn a number into a Spanish string', () => {
      expect(
        getFormattedString({
          value: 123456.45,
          currency: 'EUR',
          locale: 'es',
        }),
      ).toBe('123.456,45');
    });

    it('can turn a number into a French string', () => {
      expect(
        getFormattedString({
          value: 1234567.45,
          currency: 'EUR',
          locale: 'fr',
        }),
      ).toBe('1 234 567,45');
    });

    it('can turn a number into a English string', () => {
      expect(
        getFormattedString({
          value: 123456.78,
          currency: 'EUR',
          locale: 'en',
        }),
      ).toBe('123,456.78');
    });
  });
});
