From b2bc83b3ad81db554ea66a0022f88ed83c5b08e2 Mon Sep 17 00:00:00 2001 From: Nima Jahanshahlou Date: Fri, 13 Mar 2026 13:17:28 +0100 Subject: [PATCH 1/3] feat(money-input): add zero-fraction currency variants and update tests --- .changeset/orange-cities-know.md | 5 ++++ .../src/localized-money-input.spec.js | 23 +++++++++++++++++++ .../inputs/money-input/src/currencies.ts | 7 ++++++ .../money-input/src/money-input.spec.js | 22 ++++++++++++++++++ .../inputs/money-input/src/money-input.tsx | 2 +- 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .changeset/orange-cities-know.md diff --git a/.changeset/orange-cities-know.md b/.changeset/orange-cities-know.md new file mode 100644 index 0000000000..9b369ad38c --- /dev/null +++ b/.changeset/orange-cities-know.md @@ -0,0 +1,5 @@ +--- +'@commercetools-uikit/money-input': minor +--- + +Support zero-fraction currency variants (CZK0, HUF0, ILS0, KZT0, TRY0, TWD0) and fix empty-value fraction digits in MoneyInput diff --git a/packages/components/inputs/localized-money-input/src/localized-money-input.spec.js b/packages/components/inputs/localized-money-input/src/localized-money-input.spec.js index 9695d3fe12..ed72b1e971 100644 --- a/packages/components/inputs/localized-money-input/src/localized-money-input.spec.js +++ b/packages/components/inputs/localized-money-input/src/localized-money-input.spec.js @@ -479,6 +479,29 @@ describe('LocalizedMoneyInput.convertToMoneyValues', () => { ]); }); }); + + describe('when called with a zero-fraction variant currency (CZK0)', () => { + it('should return centPrecision with 0 fraction digits when locale is provided', () => { + expect( + LocalizedMoneyInput.convertToMoneyValues( + { + CZK0: { + currencyCode: 'CZK0', + amount: '100', + }, + }, + 'en' + ) + ).toEqual([ + { + type: 'centPrecision', + currencyCode: 'CZK0', + centAmount: 100, + fractionDigits: 0, + }, + ]); + }); + }); }); describe('LocalizedMoneyInput.parseMoneyValues', () => { diff --git a/packages/components/inputs/money-input/src/currencies.ts b/packages/components/inputs/money-input/src/currencies.ts index 1f7d1b4c60..bc47d95410 100644 --- a/packages/components/inputs/money-input/src/currencies.ts +++ b/packages/components/inputs/money-input/src/currencies.ts @@ -220,6 +220,13 @@ const currencies = { ZWL: { fractionDigits: 2 }, ZWN: { fractionDigits: 2 }, ZWR: { fractionDigits: 2 }, + // Zero-fraction variants (non-ISO): base currency with 0 decimal places. + CZK0: { fractionDigits: 0 }, + HUF0: { fractionDigits: 0 }, + ILS0: { fractionDigits: 0 }, + KZT0: { fractionDigits: 0 }, + TRY0: { fractionDigits: 0 }, + TWD0: { fractionDigits: 0 }, } as const; export default currencies; diff --git a/packages/components/inputs/money-input/src/money-input.spec.js b/packages/components/inputs/money-input/src/money-input.spec.js index 3cbf38fbdf..c2bc0e4eb4 100644 --- a/packages/components/inputs/money-input/src/money-input.spec.js +++ b/packages/components/inputs/money-input/src/money-input.spec.js @@ -109,6 +109,28 @@ describe('MoneyInput.convertToMoneyValue', () => { }); }); + describe('when a zero-fraction variant currency (CZK0) is used', () => { + it('should return centPrecision with 0 fraction digits and whole-number centAmount', () => { + expect( + MoneyInput.convertToMoneyValue( + { currencyCode: 'CZK0', amount: '100' }, + 'en' + ) + ).toEqual({ + type: 'centPrecision', + currencyCode: 'CZK0', + centAmount: 100, + fractionDigits: 0, + }); + }); + it('should warn that locale is required when locale is not passed', () => { + MoneyInput.convertToMoneyValue({ currencyCode: 'CZK0', amount: '50' }); + expect(consoleWarnMock).toHaveBeenCalledWith( + 'Warning: MoneyInput: A locale must be provided when currency has no fraction digits (CZK0)' + ); + }); + }); + describe('when no amount is present', () => { it('should return an invalid object', () => { expect( diff --git a/packages/components/inputs/money-input/src/money-input.tsx b/packages/components/inputs/money-input/src/money-input.tsx index ceabd06bdd..c51328ed07 100644 --- a/packages/components/inputs/money-input/src/money-input.tsx +++ b/packages/components/inputs/money-input/src/money-input.tsx @@ -379,7 +379,7 @@ const createEmptyMoneyValue = (currencyCode: TCurrencyCode): TMoneyValue => ({ type: 'centPrecision', currencyCode, centAmount: NaN, - fractionDigits: 2, + fractionDigits: allCurrencies[currencyCode].fractionDigits, }); const getAmountAsNumberFromMoneyValue = (moneyValue: TMoneyValue) => From 8615df89f88648a0b6449ed0a515a7e7b0fc388a Mon Sep 17 00:00:00 2001 From: Nima Jahanshahlou Date: Fri, 13 Mar 2026 13:49:19 +0100 Subject: [PATCH 2/3] test(money-input): add test for zero-fraction currency variant (HUF0) formatting --- .../inputs/money-input/src/money-input.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/components/inputs/money-input/src/money-input.spec.js b/packages/components/inputs/money-input/src/money-input.spec.js index c2bc0e4eb4..8236190e0f 100644 --- a/packages/components/inputs/money-input/src/money-input.spec.js +++ b/packages/components/inputs/money-input/src/money-input.spec.js @@ -395,6 +395,20 @@ describe('MoneyInput.parseMoneyValue', () => { ).toEqual({ amount: '12.34', currencyCode: 'EUR' }); }); }); + describe('when called with a zero-fraction variant currency (HUF0)', () => { + it('should format amount with 0 fraction digits for display', () => { + expect( + MoneyInput.parseMoneyValue( + { + currencyCode: 'HUF0', + centAmount: 500, + fractionDigits: 0, + }, + 'en' + ) + ).toEqual({ amount: '500', currencyCode: 'HUF0' }); + }); + }); describe('when called with a minimal highPrecision price', () => { it('should turn it into a value', () => { expect( From 0da164395c59280d06ea0e5f98a22a526cc8df8b Mon Sep 17 00:00:00 2001 From: Nima Jahanshahlou Date: Fri, 13 Mar 2026 15:08:12 +0100 Subject: [PATCH 3/3] fix(money-input): set default fractionDigits to 2 for currencies without specified value --- packages/components/inputs/money-input/src/money-input.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/inputs/money-input/src/money-input.tsx b/packages/components/inputs/money-input/src/money-input.tsx index c51328ed07..856eb30866 100644 --- a/packages/components/inputs/money-input/src/money-input.tsx +++ b/packages/components/inputs/money-input/src/money-input.tsx @@ -379,7 +379,7 @@ const createEmptyMoneyValue = (currencyCode: TCurrencyCode): TMoneyValue => ({ type: 'centPrecision', currencyCode, centAmount: NaN, - fractionDigits: allCurrencies[currencyCode].fractionDigits, + fractionDigits: allCurrencies[currencyCode].fractionDigits ?? 2, }); const getAmountAsNumberFromMoneyValue = (moneyValue: TMoneyValue) =>