2020-07-31 20:48:15 +00:00
|
|
|
// License: LGPL-3.0-or-later
|
2020-10-24 19:46:36 +00:00
|
|
|
import { createIntl, FormatMoneyOptions } from "./";
|
2020-07-31 20:48:15 +00:00
|
|
|
import { Money } from "../../common/money";
|
|
|
|
const NBSP = '\xa0';
|
|
|
|
|
|
|
|
let tests:Array<[Money, FormatMoneyOptions, string]>;
|
|
|
|
|
|
|
|
describe('formatMoney', () => {
|
|
|
|
describe('en', () => {
|
2020-10-24 19:46:36 +00:00
|
|
|
const intl = createIntl({locale: 'en'});
|
2020-07-31 20:48:15 +00:00
|
|
|
const oneDollar = Money.fromCents(100, 'usd');
|
|
|
|
const oneThousandDollars = Money.fromCents(100000, 'usd');
|
|
|
|
const oneThousandDollarsTenCents = Money.fromCents(100010, 'usd');
|
|
|
|
const oneEuro = Money.fromCents(100, 'eur');
|
|
|
|
const oneHundredYen = Money.fromCents(100, 'jpy');
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
[oneDollar, {}, "$1.00"],
|
|
|
|
[oneDollar, {currencyDisplay: 'code'}, `USD${NBSP}1.00`],
|
|
|
|
[oneDollar, {currencyDisplay: "name"}, "1.00 US dollars"],
|
|
|
|
[oneThousandDollars, {}, '$1,000.00'],
|
|
|
|
[oneThousandDollars, {currencyDisplay: 'code'}, `USD${NBSP}1,000.00`],
|
|
|
|
[oneThousandDollars, {currencyDisplay: "name"}, `1,000.00 US dollars`],
|
|
|
|
[oneThousandDollars, {minimumFractionDigits: 0}, "$1,000"],
|
|
|
|
[oneThousandDollarsTenCents, {minimumFractionDigits: 2}, "$1,000.10"],
|
|
|
|
[oneEuro, {}, "€1.00"],
|
|
|
|
[oneEuro, {currencyDisplay: 'code'}, `EUR${NBSP}1.00`],
|
|
|
|
[oneEuro, {currencyDisplay: "name"}, "1.00 euros"],
|
|
|
|
[oneHundredYen, {}, "¥100"],
|
|
|
|
[oneHundredYen, {currencyDisplay: 'code'}, `JPY${NBSP}100`],
|
2020-09-30 17:05:22 +00:00
|
|
|
[oneHundredYen, {currencyDisplay: "name"}, "100 Japanese yen"],
|
2020-07-31 20:48:15 +00:00
|
|
|
];
|
|
|
|
it.each(tests)('money representing %j with opts %j returns %s', (money, opts, expected ) => {
|
|
|
|
expect.assertions(1);
|
|
|
|
const output = intl.formatMoney(money, opts);
|
|
|
|
expect(output).toBe(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|