@@ -2,7 +2,8 @@ import { expect } from 'chai';
2
2
3
3
import { FieldError } from 'error' ;
4
4
import { validateRequired } from '../validateRequired' ;
5
- import { conditionallyHiddenRequiredHiddenField , hiddenRequiredField , requiredNonInputField , simpleTextField } from './fixtures/components' ;
5
+
6
+ import { conditionallyHiddenRequiredHiddenField , hiddenRequiredField , requiredNonInputField , simpleTextField , simpleSelectBoxes , simpleRadioField } from './fixtures/components' ;
6
7
import { processOne } from 'processes/processOne' ;
7
8
import { generateProcessorContext } from './fixtures/util' ;
8
9
import { ProcessorsContext , ValidationScope } from 'types' ;
@@ -25,6 +26,56 @@ it('Validating a simple component that is required and present in the data will
25
26
expect ( result ) . to . equal ( null ) ;
26
27
} ) ;
27
28
29
+
30
+ it ( 'Validating a simple radio component that is required and present in the data with value set to false will return null' , async ( ) => {
31
+ const component = { ...simpleRadioField , validate : { required : true } , values : [
32
+ {
33
+ label : 'Yes' ,
34
+ value : 'true' ,
35
+ } ,
36
+ {
37
+ label : 'No' ,
38
+ value : 'false' ,
39
+ } ] } ;
40
+ const data = { component : false } ;
41
+ const context = generateProcessorContext ( component , data ) ;
42
+ const result = await validateRequired ( context ) ;
43
+ expect ( result ) . to . equal ( null ) ;
44
+ } ) ;
45
+
46
+
47
+ it ( 'Validating a simple selectbox that is required and present in the data with value set to zero will return null' , async ( ) => {
48
+ const component = { ...simpleSelectBoxes , validate : { required : true } , values : [
49
+ {
50
+ label : 'true' ,
51
+ value : 'true' ,
52
+ } ,
53
+ {
54
+ label : 'Null' ,
55
+ value : '0' ,
56
+ } ] } ;
57
+ const data = { component : 0 } ;
58
+ const context = generateProcessorContext ( component , data ) ;
59
+ const result = await validateRequired ( context ) ;
60
+ expect ( result ) . to . equal ( null ) ;
61
+ } ) ;
62
+
63
+ it ( 'Validating a simple selectbox that is required and present in the data with value set to false will return null' , async ( ) => {
64
+ const component = { ...simpleSelectBoxes , validate : { required : true } , values : [
65
+ {
66
+ label : 'true' ,
67
+ value : 'true' ,
68
+ } ,
69
+ {
70
+ label : 'false' ,
71
+ value : 'false' ,
72
+ } ] } ;
73
+ const data = { component : false } ;
74
+ const context = generateProcessorContext ( component , data ) ;
75
+ const result = await validateRequired ( context ) ;
76
+ expect ( result ) . to . equal ( null ) ;
77
+ } ) ;
78
+
28
79
it ( 'Validating a simple component that is not required and present in the data will return null' , async ( ) => {
29
80
const component = simpleTextField ;
30
81
const data = { component : 'a simple value' } ;
0 commit comments