@@ -3,6 +3,7 @@ import expect from "expect"
33import { fromJS , OrderedMap } from "immutable"
44import {
55 mapToList ,
6+ validatePattern ,
67 validateMinLength ,
78 validateMaxLength ,
89 validateDateTime ,
@@ -216,9 +217,9 @@ describe("utils", function() {
216217 expect ( validateFile ( 1 ) ) . toEqual ( errorMessage )
217218 expect ( validateFile ( "string" ) ) . toEqual ( errorMessage )
218219 } )
219- } )
220+ } )
220221
221- describe ( "validateDateTime" , function ( ) {
222+ describe ( "validateDateTime" , function ( ) {
222223 let errorMessage = "Value must be a DateTime"
223224
224225 it ( "doesn't return for valid dates" , function ( ) {
@@ -229,7 +230,7 @@ describe("utils", function() {
229230 expect ( validateDateTime ( null ) ) . toEqual ( errorMessage )
230231 expect ( validateDateTime ( "string" ) ) . toEqual ( errorMessage )
231232 } )
232- } )
233+ } )
233234
234235 describe ( "validateGuid" , function ( ) {
235236 let errorMessage = "Value must be a Guid"
@@ -243,9 +244,9 @@ describe("utils", function() {
243244 expect ( validateGuid ( 1 ) ) . toEqual ( errorMessage )
244245 expect ( validateGuid ( "string" ) ) . toEqual ( errorMessage )
245246 } )
246- } )
247+ } )
247248
248- describe ( "validateMaxLength" , function ( ) {
249+ describe ( "validateMaxLength" , function ( ) {
249250 let errorMessage = "Value must be less than MaxLength"
250251
251252 it ( "doesn't return for valid guid" , function ( ) {
@@ -258,9 +259,9 @@ describe("utils", function() {
258259 expect ( validateMaxLength ( "abc" , 1 ) ) . toEqual ( errorMessage )
259260 expect ( validateMaxLength ( "abc" , 2 ) ) . toEqual ( errorMessage )
260261 } )
261- } )
262+ } )
262263
263- describe ( "validateMinLength" , function ( ) {
264+ describe ( "validateMinLength" , function ( ) {
264265 let errorMessage = "Value must be greater than MinLength"
265266
266267 it ( "doesn't return for valid guid" , function ( ) {
@@ -272,7 +273,29 @@ describe("utils", function() {
272273 expect ( validateMinLength ( "abc" , 5 ) ) . toEqual ( errorMessage )
273274 expect ( validateMinLength ( "abc" , 8 ) ) . toEqual ( errorMessage )
274275 } )
275- } )
276+ } )
277+
278+ describe ( "validatePattern" , function ( ) {
279+ let rxPattern = "^(red|blue)"
280+ let errorMessage = "Value must follow pattern " + rxPattern
281+
282+ it ( "doesn't return for a match" , function ( ) {
283+ expect ( validatePattern ( "red" , rxPattern ) ) . toBeFalsy ( )
284+ expect ( validatePattern ( "blue" , rxPattern ) ) . toBeFalsy ( )
285+ } )
286+
287+ it ( "returns a message for invalid pattern" , function ( ) {
288+ expect ( validatePattern ( "pink" , rxPattern ) ) . toEqual ( errorMessage )
289+ expect ( validatePattern ( "123" , rxPattern ) ) . toEqual ( errorMessage )
290+ } )
291+
292+ it ( "fails gracefully when an invalid regex value is passed" , function ( ) {
293+ expect ( ( ) => validatePattern ( "aValue" , "---" ) ) . toNotThrow ( )
294+ expect ( ( ) => validatePattern ( "aValue" , 1234 ) ) . toNotThrow ( )
295+ expect ( ( ) => validatePattern ( "aValue" , null ) ) . toNotThrow ( )
296+ expect ( ( ) => validatePattern ( "aValue" , [ ] ) ) . toNotThrow ( )
297+ } )
298+ } )
276299
277300 describe ( "validateParam" , function ( ) {
278301 let param = null
0 commit comments