import {
  parseHours, formatMoney
} from './formatters';
import ITFSettings from "../ITFSettings";

describe('Formatters', () => {
  const $t = (str) => str;

  test('parseHours', () => {
    expect(parseHours('10s')).toEqual(10);
    expect(parseHours('12h')).toEqual(12 * 60 * 60);
    expect(parseHours('10m')).toEqual(10 * 60);
    expect(parseHours('12h 10m')).toEqual(12 * 60 * 60 + 10 * 60);
    expect(parseHours('12h 10s')).toEqual(12 * 60 * 60 + 10);
    expect(parseHours('12h 10m 10s')).toEqual(12 * 60 * 60 + 10 * 60 + 10);
    expect(parseHours('1d 12h 10m 10s')).toEqual(8 * 60 * 60 + 12 * 60 * 60 + 10 * 60 + 10);
  });

  test('formatMoney', () => {
    ITFSettings.defaultLocale = 'uk_UA';
    let currency = { Id: 1, Symbol: '#', IsCryptoCurrency: false, Code: 'TTT' };
    expect(formatMoney(1, '$')).toEqual('1,00 $');
    expect(formatMoney(-1, '$')).toEqual('-1,00 $');
    expect(formatMoney(-1000000, currency)).toEqual('-1 000 000,00 #');
    expect(formatMoney(NaN)).toEqual('—');

    ITFSettings.defaultLocale = 'en_US';
    currency = { Id: 1, Symbol: '#', IsCryptoCurrency: false, Code: 'TTT' };
    expect(formatMoney(1, '$')).toEqual('$1.00');
    expect(formatMoney(-1, '$')).toEqual('$-1.00');
    expect(formatMoney(-1, currency)).toEqual('#-1.00');
    expect(formatMoney(NaN)).toEqual('—');
  });
});
