Skip to content

Commit

Permalink
fix: currency symbol placement evaluation [ATLAS-199] (#146)
Browse files Browse the repository at this point in the history
* [fix]: fix logic for prefix evaluation of currency symbol

* [test]: add missing UTs

* Create slimy-rules-thank.md

* [test]: add missing UTs
  • Loading branch information
RgnDunes authored May 21, 2024
1 parent 08342e6 commit 3803afe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slimy-rules-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@razorpay/i18nify-js": patch
---

currency symbol placement evaluation in formatNumberToParts
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,30 @@ describe('formatNumberByParts', () => {
),
);
});

it('should return correct value for isPrefixSymbol for negative amounts', () => {
const inrParts = formatNumberByParts(-1234567, {
currency: 'INR',
locale: 'en-IN',
intlOptions: { style: 'currency' },
} as any);

const eurParts = formatNumberByParts(-1234567, {
currency: 'EUR',
locale: 'de-DE',
intlOptions: { style: 'currency' },
} as any);

expect(inrParts.isPrefixSymbol).toEqual(true);
expect(eurParts.isPrefixSymbol).toEqual(false);

expect(inrParts.minusSign).toEqual('-');
expect(eurParts.minusSign).toEqual('-');
});

it('should return true as default value of isPrefixSymbol even when currency code is not passed', () => {
expect(formatNumberByParts(-1234567, {} as any).isPrefixSymbol).toEqual(
true,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const formatNumberByParts = (

return {
...formattedObj,
isPrefixSymbol: parts[0].type === 'currency',
isPrefixSymbol:
parts.findIndex((item) => item.type === 'currency') <
parts.findIndex((item) => item.type === 'integer'),
rawParts: parts,
};
} catch (err) {
Expand Down

0 comments on commit 3803afe

Please sign in to comment.