From e842999ccfdcbf3c43fdb53d800b87e788aa8e79 Mon Sep 17 00:00:00 2001 From: Mohammad Nakhaee <nakhaee@physik.hu-berlin.de> Date: Wed, 21 Aug 2024 10:21:07 +0000 Subject: [PATCH] Resolve "frontend float quantities validation" Changelog: Fixed --- gui/src/components/editQuantity/NumberEditQuantity.spec.js | 6 ++++-- gui/src/components/units/common.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gui/src/components/editQuantity/NumberEditQuantity.spec.js b/gui/src/components/editQuantity/NumberEditQuantity.spec.js index 6479defbef..5658da36fb 100644 --- a/gui/src/components/editQuantity/NumberEditQuantity.spec.js +++ b/gui/src/components/editQuantity/NumberEditQuantity.spec.js @@ -45,11 +45,13 @@ describe('Test numberEditQuantity', () => { await waitFor(() => expect(numberFieldValueInput.value).toEqual('10')) await changeValue(numberFieldValueInput, '5') + await changeValue(numberFieldValueInput, '0') await changeValue(numberFieldValueInput, '') - await waitFor(() => expect(handleChange.mock.calls).toHaveLength(2)) + await waitFor(() => expect(handleChange.mock.calls).toHaveLength(3)) await waitFor(() => expect(handleChange.mock.calls[0][0]).toBe(5)) - await waitFor(() => expect(handleChange.mock.calls[1][0]).toBe(undefined)) + await waitFor(() => expect(handleChange.mock.calls[1][0]).toBe(0)) + await waitFor(() => expect(handleChange.mock.calls[2][0]).toBe(undefined)) }) test.each([ diff --git a/gui/src/components/units/common.js b/gui/src/components/units/common.js index e0a6e46b56..a864747094 100644 --- a/gui/src/components/units/common.js +++ b/gui/src/components/units/common.js @@ -16,7 +16,7 @@ * limitations under the License. */ -import {memoize, has} from 'lodash' +import {memoize, has, isNil} from 'lodash' import {Unit} from './Unit' import { Unit as UnitMathJS } from 'mathjs' @@ -53,7 +53,7 @@ export function parse(input, options) { try { const parseResults = parseInternal(input, options) - result.value = parseResults.value || undefined + result.value = isNil(parseResults.value) ? undefined : parseResults.value result.valueString = parseResults.valueString || undefined if (parseResults.unit?.units?.length) { result.unit = new Unit(parseResults.unit) -- GitLab