Skip to content

Commit

Permalink
Switch 2 tests from simpleTextField to simpleSelectBoxes to test requ…
Browse files Browse the repository at this point in the history
…ired validation
  • Loading branch information
ralfeis committed Mar 2, 2024
1 parent 7731dfa commit e8dcb0a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/process/validation/rules/__tests__/validateRequired.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down

0 comments on commit e8dcb0a

Please sign in to comment.