From ae0325263b7be61fde69dcd65ebc8508320a634c Mon Sep 17 00:00:00 2001 From: Katrin Khilko Date: Fri, 28 Jun 2024 14:35:30 +0300 Subject: [PATCH] FIO-8597: fixed an issue with a blank value for a number component with multiple values enabled --- .../rules/__tests__/validateNumber.test.ts | 14 ++++++++++++++ src/process/validation/rules/validateNumber.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/process/validation/rules/__tests__/validateNumber.test.ts b/src/process/validation/rules/__tests__/validateNumber.test.ts index 6ca89ccb..25657c27 100644 --- a/src/process/validation/rules/__tests__/validateNumber.test.ts +++ b/src/process/validation/rules/__tests__/validateNumber.test.ts @@ -4,6 +4,7 @@ import { FieldError } from 'error'; import { simpleNumberField } from './fixtures/components'; import { generateProcessorContext } from './fixtures/util'; import { validateNumber } from '../validateNumber'; +import { validateMultiple } from '../validateMultiple'; it('Validating a valid number will return null', async () => { const component = simpleNumberField; @@ -25,3 +26,16 @@ it('Validating an invalid number will return a FieldError', async () => { expect(result).to.be.instanceOf(FieldError); expect(result?.errorKeyOrMessage).to.contain('number'); }); + +it('Validating a multiple number with a blank value will return null', async () => { + const component = { + ...simpleNumberField, + multiple: true + }; + const data = { + component: [null], + }; + const context = generateProcessorContext(component, data); + const result = await validateMultiple(context); + expect(result).to.equal(null); +}); diff --git a/src/process/validation/rules/validateNumber.ts b/src/process/validation/rules/validateNumber.ts index 283bb9ce..fdeb597a 100644 --- a/src/process/validation/rules/validateNumber.ts +++ b/src/process/validation/rules/validateNumber.ts @@ -25,7 +25,7 @@ export const validateNumberSync: RuleFnSync = (context: ValidationContext) => { const error = new FieldError('number', context); const { value } = context; - if (typeof value !== 'number') { + if (value && typeof value !== 'number') { return error; } return null;