Skip to content

Commit

Permalink
Add JS tests to cover the get currency by locale helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarcosta99 committed Apr 30, 2024
1 parent 8a4cbc7 commit d8a1a8a
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion client/utils/currency/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe( 'Currency utilities', () => {
jest.clearAllMocks();
global.wcpaySettings = {
shouldUseExplicitPrice: true,
zeroDecimalCurrencies: [ 'vnd', 'jpy' ],
zeroDecimalCurrencies: [ 'vnd', 'jpy', 'xpf' ],
connect: {
country: 'US',
},
Expand All @@ -25,6 +25,11 @@ describe( 'Currency utilities', () => {
thousandSeparator: ',',
decimalSeparator: '.',
precision: 2,
defaultLocale: {
symbolPosition: 'left',
thousandSeparator: ',',
decimalSeparator: '.',
},
},
JP: {
code: 'JPY',
Expand All @@ -33,6 +38,11 @@ describe( 'Currency utilities', () => {
thousandSeparator: ',',
decimalSeparator: '.',
precision: 0,
defaultLocale: {
symbolPosition: 'left',
thousandSeparator: ',',
decimalSeparator: '.',
},
},
FR: {
code: 'EUR',
Expand All @@ -41,6 +51,11 @@ describe( 'Currency utilities', () => {
thousandSeparator: ' ',
decimalSeparator: ',',
precision: 2,
defaultLocale: {
symbolPosition: 'right_space',
thousandSeparator: ',',
decimalSeparator: '.',
},
},
GB: {
code: 'GBP',
Expand All @@ -49,6 +64,11 @@ describe( 'Currency utilities', () => {
thousandSeparator: ',',
decimalSeparator: '.',
precision: 2,
defaultLocale: {
symbolPosition: 'left',
thousandSeparator: ',',
decimalSeparator: '.',
},
},
IN: {
code: 'INR',
Expand All @@ -57,6 +77,24 @@ describe( 'Currency utilities', () => {
thousandSeparator: ',',
decimalSeparator: '.',
precision: 2,
defaultLocale: {
symbolPosition: 'left',
thousandSeparator: ',',
decimalSeparator: '.',
},
},
NC: {
code: 'XPF',
symbol: 'XPF',
symbolPosition: 'right_space',
thousandSeparator: ' ',
decimalSeparator: '.',
precision: 0,
defaultLocale: {
symbolPosition: 'left_space',
thousandSeparator: ',',
decimalSeparator: '.',
},
},
RU: {
code: 'RUB',
Expand All @@ -65,6 +103,11 @@ describe( 'Currency utilities', () => {
thousandSeparator: ' ',
decimalSeparator: ',',
precision: 2,
defaultLocale: {
symbolPosition: 'right_space',
thousandSeparator: ' ',
decimalSeparator: ',',
},
},
},
};
Expand Down Expand Up @@ -110,6 +153,27 @@ describe( 'Currency utilities', () => {
expect( utils.formatCurrency( 100000, 'EUR' ) ).toEqual( '€1,000.00' );
} );

test( 'getCurrencyLocale should use store country currency when it matches', () => {
expect( utils.formatCurrency( 100000, 'USD', null, true ) ).toEqual(
'$1,000.00'
);

global.wcpaySettings.connect.country = 'NC';

expect( utils.formatCurrency( 100000, 'XPF', null, true ) ).toEqual(
'100 000 XPF'
);
} );

test( 'getCurrencyLocale should use default locale formatting', () => {
expect( utils.formatCurrency( 100000, 'EUR', null, true ) ).toEqual(
'1,000.00 €'
);
expect( utils.formatCurrency( 100000, 'XPF', null, true ) ).toEqual(
'XPF 100,000'
);
} );

test( 'format export amounts', () => {
expect( utils.formatExportAmount( 1000, 'USD' ) ).toEqual( 10 );
expect( utils.formatExportAmount( 1250, 'USD' ) ).toEqual( 12.5 );
Expand Down

0 comments on commit d8a1a8a

Please sign in to comment.