Skip to content

Commit

Permalink
FIO-8597: fixed an issue with a blank value for a number component wi…
Browse files Browse the repository at this point in the history
…th multiple values enabled
  • Loading branch information
KatrinKhilko committed Jun 28, 2024
1 parent 7b67d3e commit ae03252
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/process/validation/rules/__tests__/validateNumber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
2 changes: 1 addition & 1 deletion src/process/validation/rules/validateNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ae03252

Please sign in to comment.