Skip to content

Commit

Permalink
Update test cases to address the latest changes in ICU 74.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnzlml committed Dec 4, 2023
1 parent c25a43b commit 46a6646
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 37 deletions.
9 changes: 6 additions & 3 deletions src/sx-design/src/DateTime/__tests__/DateTime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ it('works correctly for `es-MX` locale', () => {
{ locale: 'es-MX' },
);

// Change in ICU 72.1 (https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V19.md#19.1.0)
if (Number(process.versions.icu) >= 72.1) {
if (Number(process.versions.icu) >= 74.1) {
// Change in ICU 74.1 (https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V21.md#21.3.0)
expect(getByText('16 abr 2022, 1:00:00 a.m.')).toBeInTheDocument();
} else if (Number(process.versions.icu) >= 72.1) {
// Change in ICU 72.1 (https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V19.md#19.1.0)
expect(getByText('16 abr 2022, 01:00:00')).toBeInTheDocument();
} else {
expect(getByText('16 abr 2022 01:00:00')).toBeInTheDocument();
Expand Down Expand Up @@ -81,8 +84,8 @@ it('works correctly with additional format options', () => {
{ locale: 'cs-CZ' },
);

// Change in ICU 72.1 (https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V19.md#19.1.0)
if (Number(process.versions.icu) >= 72.1) {
// Change in ICU 72.1 (https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V19.md#19.1.0)
expect(
getByText('sobota 16. dubna 2022 našeho letopočtu v 1:00:00, koordinovaný světový čas'),
).toBeInTheDocument();
Expand Down
96 changes: 62 additions & 34 deletions src/sx-design/src/Money/__tests__/Money.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,92 @@ import { SupportedCurrencies } from '../../constants';

// When adding new currencies, always add one line for `en-US` and one line for the new locale.
// This way we can test that it works well for both natives and foreigners.
//
// TODO: remove old ICU test cases when not needed
test.each`
locale | currency | expectedReact | expectedFn
${'en-US'} | ${'CZK'} | ${'CZK 10.00'} | ${'CZK 10.00'}
${'cs-CZ'} | ${'CZK'} | ${'10,00 Kč'} | ${'10,00 Kč'}
${'en-US'} | ${'USD'} | ${'$10.00'} | ${'$10.00'}
${'es-MX'} | ${'USD'} | ${'USD 10.00'} | ${'USD 10.00'}
${'en-US'} | ${'MXN'} | ${'MX$10.00'} | ${'MX$10.00'}
${'es-MX'} | ${'MXN'} | ${'$10.00'} | ${'$10.00'}
${'en-US'} | ${'NOK'} | ${'NOK 10.00'} | ${'NOK 10.00'}
${'no-NO'} | ${'NOK'} | ${'kr 10,00'} | ${'kr 10,00'}
${'en-US'} | ${'RUB'} | ${'RUB 10.00'} | ${'RUB 10.00'}
${'ru-RU'} | ${'RUB'} | ${'10,00 ₽'} | ${'10,00 ₽'}
${'en-US'} | ${'UAH'} | ${'UAH 10.00'} | ${'UAH 10.00'}
${'uk-UA'} | ${'UAH'} | ${'10,00 ₴'} | ${'10,00 ₴'}
locale | currency | expectedReact | expectedReactICU741 | expectedFn | expectedFnICU741
${'en-US'} | ${'CZK'} | ${'CZK 10.00'} | ${'CZK 10.00'} | ${'CZK 10.00'} | ${'CZK 10.00'}
${'cs-CZ'} | ${'CZK'} | ${'10,00 Kč'} | ${'10,00 Kč'} | ${'10,00 Kč'} | ${'10,00 Kč'}
${'en-US'} | ${'USD'} | ${'$10.00'} | ${'$10.00'} | ${'$10.00'} | ${'$10.00'}
${'es-MX'} | ${'USD'} | ${'USD 10.00'} | ${'USD 10.00'} | ${'USD 10.00'} | ${'USD 10.00'}
${'en-US'} | ${'MXN'} | ${'MX$10.00'} | ${'MX$10.00'} | ${'MX$10.00'} | ${'MX$10.00'}
${'es-MX'} | ${'MXN'} | ${'$10.00'} | ${'$10.00'} | ${'$10.00'} | ${'$10.00'}
${'en-US'} | ${'NOK'} | ${'NOK 10.00'} | ${'NOK 10.00'} | ${'NOK 10.00'} | ${'NOK 10.00'}
${'no-NO'} | ${'NOK'} | ${'kr 10,00'} | ${'10,00 kr'} | ${'kr 10,00'} | ${'10,00 kr'}
${'en-US'} | ${'RUB'} | ${'RUB 10.00'} | ${'RUB 10.00'} | ${'RUB 10.00'} | ${'RUB 10.00'}
${'ru-RU'} | ${'RUB'} | ${'10,00 ₽'} | ${'10,00 ₽'} | ${'10,00 ₽'} | ${'10,00 ₽'}
${'en-US'} | ${'UAH'} | ${'UAH 10.00'} | ${'UAH 10.00'} | ${'UAH 10.00'} | ${'UAH 10.00'}
${'uk-UA'} | ${'UAH'} | ${'10,00 ₴'} | ${'10,00 ₴'} | ${'10,00 ₴'} | ${'10,00 ₴'}
`(
'renders price with locale "$locale" and currency "$currency" correctly ("$expectedFn")',
({ locale, currency, expectedReact, expectedFn }) => {
({ locale, currency, expectedReact, expectedReactICU741, expectedFn, expectedFnICU741 }) => {
const amount = 10;

const { getByText } = render(
<Money priceUnitAmount={amount} priceUnitAmountCurrency={currency} />,
{ locale },
);
expect(getByText(expectedReact)).toBeInTheDocument();

if (Number(process.versions.icu) >= 74.1) {
// Change in ICU 74.1 (https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V21.md#21.3.0)
expect(getByText(expectedReactICU741)).toBeInTheDocument();
} else {
expect(getByText(expectedReact)).toBeInTheDocument();
}

// alternative non-React function
expect(
MoneyFn({
locale,
priceUnitAmount: amount,
priceUnitAmountCurrency: currency,
}),
).toBe(expectedFn);
if (Number(process.versions.icu) >= 74.1) {
expect(
MoneyFn({
locale,
priceUnitAmount: amount,
priceUnitAmountCurrency: currency,
}),
).toBe(expectedFnICU741);
} else {
expect(
MoneyFn({
locale,
priceUnitAmount: amount,
priceUnitAmountCurrency: currency,
}),
).toBe(expectedFn);
}
},
);

// Special test case for arabic (different before and after Node.js 19.1.0 - change in ICU 72.1).
// See: https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V19.md#19.1.0
//
// TODO: remove old ICU test cases when not needed
test.each`
locale | expectedFnOld | expectedFnNew
locale | expectedFn | expectedFnICU721
${'en-US'} | ${'AED 10.00'} | ${'AED 10.00'}
${'ar-AR'} | ${'د.إ.‏ 10.00'} | ${'‏10.00 د.إ.‏'}
${'ar-AR-u-nu-arab'} | ${'١٠٫٠٠ د.إ.‏'} | ${'‏١٠٫٠٠ د.إ.‏'}
`(
'renders price with locale "$locale" and currency "AED" correctly ("$expectedFnNew")',
({ locale, expectedFnOld, expectedFnNew }) => {
'renders price with locale "$locale" and currency "AED" correctly ("$expectedFn")',
({ locale, expectedFn, expectedFnICU721 }) => {
const amount = 10;
const currency = SupportedCurrencies.AED;

expect(
MoneyFn({
locale,
priceUnitAmount: amount,
priceUnitAmountCurrency: currency,
}),
).toBe(
if (Number(process.versions.icu) >= 72.1) {
// Change in ICU 72.1 (https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V19.md#19.1.0)
Number(process.versions.icu) >= 72.1 ? expectedFnNew : expectedFnOld,
);
expect(
MoneyFn({
locale,
priceUnitAmount: amount,
priceUnitAmountCurrency: currency,
}),
).toBe(expectedFnICU721);
} else {
expect(
MoneyFn({
locale,
priceUnitAmount: amount,
priceUnitAmountCurrency: currency,
}),
).toBe(expectedFn);
}
},
);

0 comments on commit 46a6646

Please sign in to comment.