From e8dcb0ab1a5b03c4b07d99f56b70eac2ee1ecc8a Mon Sep 17 00:00:00 2001 From: Ralf Eisele Date: Sat, 2 Mar 2024 08:43:59 +0100 Subject: [PATCH] Switch 2 tests from simpleTextField to simpleSelectBoxes to test required validation --- .../rules/__tests__/validateRequired.test.ts | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/process/validation/rules/__tests__/validateRequired.test.ts b/src/process/validation/rules/__tests__/validateRequired.test.ts index 878cc4af..8e62bdf6 100644 --- a/src/process/validation/rules/__tests__/validateRequired.test.ts +++ b/src/process/validation/rules/__tests__/validateRequired.test.ts @@ -2,7 +2,8 @@ import { expect } from 'chai'; import { FieldError } from 'error'; import { validateRequired } from '../validateRequired'; -import { conditionallyHiddenRequiredHiddenField, hiddenRequiredField, requiredNonInputField, simpleTextField } from './fixtures/components'; + +import { conditionallyHiddenRequiredHiddenField, hiddenRequiredField, requiredNonInputField, simpleTextField, simpleSelectBoxes } from './fixtures/components'; import { processOne } from 'processes/processOne'; import { generateProcessContext } from './fixtures/util'; import { ProcessorsContext, ValidationScope } from 'types'; @@ -25,16 +26,32 @@ it('Validating a simple component that is required and present in the data will expect(result).to.equal(null); }); -it('Validating a simple component that is required and present in the data with value=0 will return null', async () => { - const component = { ...simpleTextField, validate: { required: true } }; +it('Validating a simple selectbox that is required and present in the data with value=0 will return null', async () => { + const component = { ...simpleSelectBoxes, validate: { required: true }, values: [ + { + label: 'true', + value: 'true', + }, + { + label: 'Null', + value: '0', + }] }; const data = { component: 0 }; const context = generateProcessContext(component, data); const result = await validateRequired(context); expect(result).to.equal(null); }); -it('Validating a simple component that is required and present in the data with value=false will return null', async () => { - const component = { ...simpleTextField, validate: { required: true } }; +it('Validating a simple selectbox that is required and present in the data with value=false will return null', async () => { + const component = { ...simpleSelectBoxes, validate: { required: true }, values: [ + { + label: 'true', + value: 'true', + }, + { + label: 'false', + value: 'false', + }] }; const data = { component: false }; const context = generateProcessContext(component, data); const result = await validateRequired(context);