From 462b679a9a625654717f1c045a9dd1f737768f2f Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Tue, 12 Nov 2024 22:31:46 +0200 Subject: [PATCH] #10663: edit unit test in IntlNumberFormatControl-test.jsx to fix FE failure --- .../I18N/__tests__/IntlNumberFormatControl-test.jsx | 6 +++--- web/client/libs/numeric-input/NumericInput.jsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web/client/components/I18N/__tests__/IntlNumberFormatControl-test.jsx b/web/client/components/I18N/__tests__/IntlNumberFormatControl-test.jsx index b0e94a820b..5075959141 100644 --- a/web/client/components/I18N/__tests__/IntlNumberFormatControl-test.jsx +++ b/web/client/components/I18N/__tests__/IntlNumberFormatControl-test.jsx @@ -120,7 +120,7 @@ describe('IntlNumberFormControl', () => { TestUtils.Simulate.change(element, {target: {value: '12.'}}); expect(element.value).toBe("12"); TestUtils.Simulate.change(element, {target: {value: '12.0'}}); - expect(element.value).toBe("12"); + expect(element.value).toBe("12.0"); TestUtils.Simulate.change(element, {target: {value: '12.04'}}); expect(element.value).toBe("12.04"); TestUtils.Simulate.change(element, {target: {value: '12.402'}}); @@ -128,9 +128,9 @@ describe('IntlNumberFormControl', () => { TestUtils.Simulate.change(element, {target: {value: '-12.04'}}); expect(element.value).toBe("-12.04"); TestUtils.Simulate.change(element, {target: {value: '-12.40'}}); - expect(element.value).toBe("-12.4"); + expect(element.value).toBe("-12.40"); TestUtils.Simulate.change(element, {target: {value: '-12.0'}}); - expect(element.value).toBe("-12"); + expect(element.value).toBe("-12.0"); }); it('check calling passed onkeydown, onkeyup events', () => { const intl = {locale: "en-US"}; diff --git a/web/client/libs/numeric-input/NumericInput.jsx b/web/client/libs/numeric-input/NumericInput.jsx index 4730695984..da365f73c7 100644 --- a/web/client/libs/numeric-input/NumericInput.jsx +++ b/web/client/libs/numeric-input/NumericInput.jsx @@ -414,10 +414,10 @@ class NumericInput extends Component { const escapedDecimalSymbol = decimalSymbol.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const RE_TRAILING_DECIMAL_ZEROS = new RegExp(`\\d+${escapedDecimalSymbol}\\d*0+`); - // incomplete number - if (loose && RE_INCOMPLETE_NUMBER.test(stringValue)) { + // incomplete number or number contains decimal symbol [centesimal decimal numbers] + if ((loose && RE_INCOMPLETE_NUMBER.test(stringValue)) || RE_TRAILING_DECIMAL_ZEROS.test(stringValue)) { attrs.input.value = stringValue; - } else if ((loose && stringValue && !RE_NUMBER.test(stringValue)) || RE_TRAILING_DECIMAL_ZEROS.test(stringValue)) {// Not a number and not empty (loose mode only) || if number contains decimal symbol [centesimal decimal numbers] + } else if ((loose && stringValue && !RE_NUMBER.test(stringValue))) {// Not a number and not empty (loose mode only) attrs.input.value = stringValue; } else if (state.value || state.value === 0) { // number attrs.input.value = this._format(state.value);