@@ -49,7 +49,7 @@ describe("validateField", () => {
49
49
expect ( validateField ( testField , [ testField ] , true ) . isValid ) . toBe ( false ) ;
50
50
} ) ;
51
51
52
- test ( "visible, required field with numberical value 0 is valid" , ( ) => {
52
+ test ( "visible, required field with numerical value 0 is valid" , ( ) => {
53
53
const testField = {
54
54
...field1 ,
55
55
visible : true ,
@@ -99,6 +99,116 @@ describe("validateField", () => {
99
99
expect ( validateField ( testField , [ testField ] , true ) . isValid ) . toBe ( true ) ;
100
100
} ) ;
101
101
102
+ test ( "correctly concats multiple error messages with ? punctuation" , ( ) => {
103
+ const errorMessage = "Where's my data?" ;
104
+ const errorMessage2 = "Where is my data!" ;
105
+ const testField = {
106
+ ...field1 ,
107
+ visible : true ,
108
+ required : true ,
109
+ value : "" ,
110
+ missingValueMessage : errorMessage ,
111
+ validWhen :{
112
+ isNot :{
113
+ values :[ "" ] ,
114
+ message : errorMessage2 ,
115
+ }
116
+ }
117
+ } ;
118
+ const validationResult = validateField ( testField , [ testField ] , true ) ;
119
+ expect ( validationResult . isValid ) . toBe ( false ) ;
120
+ expect ( validationResult . errorMessages ) . toBe ( "Where's my data? Where is my data!" ) ;
121
+ expect ( validateField ( testField , [ testField ] , true ) . isValid ) . toBe ( false ) ;
122
+ } ) ;
123
+
124
+ test ( "correctly concats multiple error messages with ! punctuation" , ( ) => {
125
+ const errorMessage = "Where's my data!" ;
126
+ const errorMessage2 = "Where is my data?" ;
127
+ const testField = {
128
+ ...field1 ,
129
+ visible : true ,
130
+ required : true ,
131
+ value : "" ,
132
+ missingValueMessage : errorMessage ,
133
+ validWhen :{
134
+ isNot :{
135
+ values :[ "" ] ,
136
+ message : errorMessage2 ,
137
+ }
138
+ }
139
+ } ;
140
+ const validationResult = validateField ( testField , [ testField ] , true ) ;
141
+ expect ( validationResult . isValid ) . toBe ( false ) ;
142
+ expect ( validationResult . errorMessages ) . toBe ( "Where's my data! Where is my data?" ) ;
143
+ expect ( validateField ( testField , [ testField ] , true ) . isValid ) . toBe ( false ) ;
144
+ } ) ;
145
+
146
+ test ( "correctly concats multiple error messages with no full stop" , ( ) => {
147
+ const errorMessage = "Where's my data" ;
148
+ const errorMessage2 = "Where is my data?" ;
149
+ const testField = {
150
+ ...field1 ,
151
+ visible : true ,
152
+ required : true ,
153
+ value : "" ,
154
+ missingValueMessage : errorMessage ,
155
+ validWhen :{
156
+ isNot :{
157
+ values :[ "" ] ,
158
+ message : errorMessage2 ,
159
+ }
160
+ }
161
+ } ;
162
+ const validationResult = validateField ( testField , [ testField ] , true ) ;
163
+ expect ( validationResult . isValid ) . toBe ( false ) ;
164
+ expect ( validationResult . errorMessages ) . toBe ( "Where's my data. Where is my data?" ) ;
165
+ expect ( validateField ( testField , [ testField ] , true ) . isValid ) . toBe ( false ) ;
166
+ } ) ;
167
+
168
+ test ( "correctly concats multiple error messages with a full stop" , ( ) => {
169
+ const errorMessage = "Where's my data." ;
170
+ const errorMessage2 = "Where is my data." ;
171
+ const testField = {
172
+ ...field1 ,
173
+ visible : true ,
174
+ required : true ,
175
+ value : "" ,
176
+ missingValueMessage : errorMessage ,
177
+ validWhen :{
178
+ isNot :{
179
+ values :[ "" ] ,
180
+ message : errorMessage2 ,
181
+ }
182
+ }
183
+ } ;
184
+ const validationResult = validateField ( testField , [ testField ] , true ) ;
185
+ expect ( validationResult . isValid ) . toBe ( false ) ;
186
+ expect ( validationResult . errorMessages ) . toBe ( "Where's my data. Where is my data." ) ;
187
+ expect ( validateField ( testField , [ testField ] , true ) . isValid ) . toBe ( false ) ;
188
+ } ) ;
189
+
190
+ test ( "concats multiple error messages in order" , ( ) => {
191
+ const errorMessage = "This should be first" ;
192
+ const errorMessage2 = "This should be second" ;
193
+ const testField = {
194
+ ...field1 ,
195
+ visible : true ,
196
+ required : true ,
197
+ value : "" ,
198
+ missingValueMessage : errorMessage ,
199
+ validWhen :{
200
+ isNot :{
201
+ values :[ "" ] ,
202
+ message : errorMessage2 ,
203
+ }
204
+ }
205
+ } ;
206
+ const validationResult = validateField ( testField , [ testField ] , true ) ;
207
+ expect ( validationResult . isValid ) . toBe ( false ) ;
208
+ expect ( validationResult . errorMessages ) . toBe ( "This should be first. This should be second." ) ;
209
+ expect ( validateField ( testField , [ testField ] , true ) . isValid ) . toBe ( false ) ;
210
+ } ) ;
211
+
102
212
test ( "visible, required field with missing data shows custom message" , ( ) => {
103
213
const errorMessage = "Where's my data?" ;
104
214
const testField = {
@@ -239,7 +349,7 @@ describe("lengthIsLessThan validator", () => {
239
349
) . toBeUndefined ( ) ;
240
350
} ) ;
241
351
242
- test ( "with invvalid value" , ( ) => {
352
+ test ( "with invalid value" , ( ) => {
243
353
expect (
244
354
lengthIsLessThan ( {
245
355
value : "test" ,
@@ -688,4 +798,4 @@ describe("hasValue", () => {
688
798
test ( "null" , ( ) => {
689
799
expect ( hasValue ( null ) ) . toEqual ( false ) ;
690
800
} ) ;
691
- } ) ;
801
+ } ) ;
0 commit comments