import { cleanup } from '@testing-library/react';
import { moneyFormaterShort, moneyFormaterFull, numberFormat } from './formatters';

afterEach(cleanup);

// @todo: join with "utils/common/formatters"
describe('Check "utils/formatters"', () => {
  let result: string | number = '$2,500.00';
  let value: string | number = 2500;

  it(' Check moneyFormaterFull function with', () => {
    const fraction = 2;
    expect(moneyFormaterFull(value, fraction)).toEqual(result);

    result = '$2,500';
    expect(moneyFormaterFull(value)).toEqual(result);

    value = 'Hello';
    result = 'Hello';
    expect(moneyFormaterFull(value)).toEqual(result);

    value = '5200';
    result = '$5,200';
    expect(moneyFormaterFull(value)).toEqual(result);
  });

  it(' Check numberFormat function', () => {
    const value: string | number = 2500;
    result = '2,500';
    expect(numberFormat(value)).toEqual(result);
  });

  it(' Check moneyFormaterShort function', () => {
    let money: number | null | undefined | string = null;

    result = '$5.2k';
    expect(moneyFormaterShort(value)).toEqual(result);

    result = 'NA';
    expect(moneyFormaterShort(money)).toEqual(result);

    money = 33;
    result = '$33';
    expect(moneyFormaterShort(money)).toEqual(result);

    money = 0;
    result = 0;
    expect(moneyFormaterShort(money)).toEqual(result);

    money = -200;
    result = '$0.2k';
    expect(moneyFormaterShort(money)).toEqual(result);

    money = -2500000;
    result = '$2.5m';
    expect(moneyFormaterShort(money)).toEqual(result);

    money = 1300000000;
    result = '$1.3b';
    expect(moneyFormaterShort(money)).toEqual(result);

    money = 'Hello';
    result = 'Hello';
    expect(moneyFormaterShort(money)).toEqual(result);

    money = '5200';
    result = '$5.2k';
    expect(moneyFormaterShort(money)).toEqual(result);
  });
});
