Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Bonus Pagamenti Digitali): [#175700724] Fixes wrong format of bpd amount #2376

Merged
merged 4 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ global:
question: "?"
asterisk: "*"
localization:
delimiterSeparator: ","
decimalSeparator: "."
date:
today: "today"
Expand Down
1 change: 1 addition & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ global:
question: "?"
asterisk: "*"
localization:
delimiterSeparator: "."
decimalSeparator: ","
date:
today: "oggi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ const statusClosedHandler = (props: Props): GraphicalState => {
totalAmount.transactionNumber < period.minTransactionNumber &&
!isInGracePeriod
? ["0", "00"]
: formatNumberAmount(props.totalAmount.totalCashback).split(","),
: formatNumberAmount(props.totalAmount.totalCashback).split(
Undermaken marked this conversation as resolved.
Show resolved Hide resolved
I18n.t("global.localization.decimalSeparator")
),
isInGracePeriod,
// TODO: Add supercashback business logic
statusBadge: isInGracePeriod
Expand Down Expand Up @@ -208,7 +210,9 @@ const statusActiveHandler = (props: Props): GraphicalState => {
label: I18n.t("bonus.bpd.details.card.status.active")
},
showLock: totalAmount.transactionNumber < period.minTransactionNumber,
amount: formatNumberAmount(props.totalAmount.totalCashback).split(",")
amount: formatNumberAmount(props.totalAmount.totalCashback).split(
I18n.t("global.localization.decimalSeparator")
)
};
};

Expand All @@ -221,7 +225,9 @@ const statusInactiveHandler = (props: Props): GraphicalState => ({
label: I18n.t("bonus.bpd.details.card.status.inactive")
},
showLock: true,
amount: formatNumberAmount(props.totalAmount.totalCashback).split(",")
amount: formatNumberAmount(props.totalAmount.totalCashback).split(
I18n.t("global.localization.decimalSeparator")
)
});

const statusHandlersMap = new Map<
Expand Down Expand Up @@ -274,7 +280,7 @@ export const BpdCardComponent: React.FunctionComponent<Props> = (
<Text bold={true} white={true} style={[styles.amountTextBaseFull]}>
{"€ "}
<Text white={true} style={styles.amountTextUpperFull}>
{amount[0]},
{`${amount[0]}${I18n.t("global.localization.decimalSeparator")}`}
</Text>
{amount[1]}
</Text>
Expand Down Expand Up @@ -359,7 +365,9 @@ export const BpdCardComponent: React.FunctionComponent<Props> = (
>
{"€ "}
<Text white={true} style={styles.amountTextUpperPreview}>
{amount[0]},
{`${amount[0]}${I18n.t(
"global.localization.decimalSeparator"
)}`}
</Text>
{amount[1]}
</Text>
Expand Down
45 changes: 35 additions & 10 deletions ts/utils/__tests__/stringBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import { entries } from "lodash";
import { Locales } from "../../../locales/locales";
import { setLocale } from "../../i18n";
import { formatNumberAmount } from "../stringBuilder";

const valuesEN = {
"10.00": 10,
"0.30": 0.3,
"0.12": 0.1 + 0.02,
"100.99": 100.99,
"102.00": 101.999999, // round to the appropriate 2-decimals number
"10.50": 10.5001,
"1,000.50": 1000.5
};

beforeAll(() => setLocale("en" as Locales));

describe("amountBuilder", () => {
it("should render amounts correctly for EN language", async () => {
entries(valuesEN).forEach(([k, v]) =>
expect(formatNumberAmount(v)).toEqual(k)
);
});
});

const valuesIT = {
"10,00": 10,
"0,30": 0.3,
"0,12": 0.1 + 0.02,
"100,99": 100.99,
"102,00": 101.999999, // round to the appropriate 2-decimals number
"10,50": 10.5001,
"1.000,50": 1000.5
};

describe("amountBuilder", () => {
it("should render amounts correctly", async () => {
const values = {
"10.00": 10,
"0.30": 0.3,
"0.12": 0.1 + 0.02,
"100.99": 100.99,
"102.00": 101.999999, // round to the appropriate 2-decimals number
"10.50": 10.5001
};
entries(values).forEach(([k, v]) =>
it("should render amounts correctly for IT language", async () => {
setLocale("it" as Locales);
entries(valuesIT).forEach(([k, v]) =>
expect(formatNumberAmount(v)).toEqual(k)
);
});
Expand Down
1 change: 1 addition & 0 deletions ts/utils/stringBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const formatNumberAmount = (
): string =>
I18n.toCurrency(amount, {
precision: DISPLAYED_DIGITS,
delimiter: I18n.t("global.localization.delimiterSeparator"),
separator: I18n.t("global.localization.decimalSeparator"),
format: displayCurrency ? "€ %n" : "%n"
});
Expand Down