@@ -277,146 +277,4 @@ describe('message', () => {
277277 expect ( newmessage ) . equal ( false ) ;
278278 } ) ;
279279 } ) ;
280-
281- describe ( 'handleCustomErrorMessage invalid (customErrorMessage is undefined)' , ( ) => {
282- it ( '[empty]: Should return original message object when customErrorMessage is not valid' , ( ) => {
283- const tmpMessage = Object . assign ( { } , { ...Message } ) ;
284- const handleCustomErrorMessage = Message . __get__ ( 'handleCustomErrorMessage' ) ;
285- const newMessage = handleCustomErrorMessage ( tmpMessage , window ) ;
286- expect ( newMessage [ 'en-US' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be empty' ) ;
287- } ) ;
288- } ) ;
289-
290- describe ( 'handleCustomErrorMessage when window is undefined' , ( ) => {
291- it ( '[empty]: Should return original message object when window is undefined' , ( ) => {
292- const tmpMessage = Object . assign ( { } , { ...Message } ) ;
293- const handleCustomErrorMessage = Message . __get__ ( 'handleCustomErrorMessage' ) ;
294- const newMessage = handleCustomErrorMessage ( tmpMessage , undefined ) ;
295- expect ( newMessage [ 'en-US' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be empty' ) ;
296- } ) ;
297- } ) ;
298-
299- describe ( 'handleCustomErrorMessage invalid' , ( ) => {
300- beforeAll ( ( ) => {
301- window . REACT_INPUTS_VALIDATION = {
302- customErrorMessage : { }
303- } ;
304- } ) ;
305- it ( '[empty]: Should return original message object when customErrorMessage is not valid' , ( ) => {
306- const tmpMessage = Object . assign ( { } , { ...Message } ) ;
307- const handleCustomErrorMessage = Message . __get__ ( 'handleCustomErrorMessage' ) ;
308- const newMessage = handleCustomErrorMessage ( tmpMessage , window ) ;
309- expect ( newMessage [ 'en-US' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be empty' ) ;
310- } ) ;
311- } ) ;
312-
313- describe ( 'handleCustomErrorMessage invalid' , ( ) => {
314- beforeAll ( ( ) => {
315- window . REACT_INPUTS_VALIDATION = {
316- customErrorMessage : {
317- 'en-US' : { }
318- }
319- } ;
320- } ) ;
321- it ( '[empty]: Should return "foobar cannot be empty"' , ( ) => {
322- const tmpMessage = Object . assign ( { } , { ...Message } ) ;
323- const handleCustomErrorMessage = Message . __get__ ( 'handleCustomErrorMessage' ) ;
324- const newMessage = handleCustomErrorMessage ( tmpMessage , window ) ;
325- expect ( newMessage [ 'en-US' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be empty' ) ;
326- } ) ;
327- } ) ;
328-
329- describe ( 'handleCustomErrorMessage invalid' , ( ) => {
330- beforeAll ( ( ) => {
331- window . REACT_INPUTS_VALIDATION = {
332- customErrorMessage : {
333- 'en-US' : { textbox : { } }
334- }
335- } ;
336- } ) ;
337- it ( '[empty]: Should return "foobar cannot be empty"' , ( ) => {
338- const tmpMessage = Object . assign ( { } , { ...Message } ) ;
339- const handleCustomErrorMessage = Message . __get__ ( 'handleCustomErrorMessage' ) ;
340- const newMessage = handleCustomErrorMessage ( tmpMessage , window ) ;
341- expect ( newMessage [ 'en-US' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be empty' ) ;
342- } ) ;
343- } ) ;
344-
345- describe ( 'handleCustomErrorMessage valid' , ( ) => {
346- beforeAll ( ( ) => {
347- window . REACT_INPUTS_VALIDATION = {
348- customErrorMessage : {
349- 'en-US' : {
350- textbox : {
351- empty : function empty ( name ) {
352- return name + ' cannot be empty(custom message)' ;
353- }
354- }
355- }
356- }
357- } ;
358- } ) ;
359- it ( '[empty]: Should return "foobar cannot be empty(custom message)"' , ( ) => {
360- const tmpMessage = Object . assign ( { } , { ...Message } ) ;
361- const handleCustomErrorMessage = Message . __get__ ( 'handleCustomErrorMessage' ) ;
362- const newMessage = handleCustomErrorMessage ( tmpMessage , window ) ;
363- expect ( newMessage [ 'en-US' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be empty(custom message)' ) ;
364- } ) ;
365- } ) ;
366-
367- describe ( 'custom locale' , ( ) => {
368- beforeAll ( ( ) => {
369- window . REACT_INPUTS_VALIDATION = {
370- customErrorMessage : {
371- 'foo-bar' : {
372- textbox : {
373- empty : function empty ( name ) {
374- return name + ' cannot be foobar' ;
375- }
376- }
377- }
378- }
379- } ;
380- } ) ;
381- it ( '[empty]: Should return "foobar cannot be foobar"' , ( ) => {
382- const tmpMessage = Object . assign ( { } , { ...Message } ) ;
383- const handleCustomErrorMessage = Message . __get__ ( 'handleCustomErrorMessage' ) ;
384- const newMessage = handleCustomErrorMessage ( tmpMessage , window ) ;
385- expect ( newMessage [ 'foo-bar' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be foobar' ) ;
386- } ) ;
387- } ) ;
388-
389- describe ( 'getCustomErrorMessage valid' , ( ) => {
390- beforeAll ( ( ) => {
391- window . REACT_INPUTS_VALIDATION = {
392- customErrorMessage : {
393- 'en-US' : {
394- textbox : {
395- empty : function empty ( name ) {
396- return name + ' cannot be empty(custom message)' ;
397- }
398- }
399- }
400- }
401- } ;
402- } ) ;
403- it ( '[empty]: Should return "foobar cannot be empty(custom message)"' , ( ) => {
404- const getCustomErrorMessage = Message . __get__ ( 'getCustomErrorMessage' ) ;
405- const newMessage = getCustomErrorMessage ( window . REACT_INPUTS_VALIDATION [ 'customErrorMessage' ] , Message ) ;
406- expect ( newMessage [ 'en-US' ] [ 'textbox' ] [ 'empty' ] ( 'foobar' ) ) . equal ( 'foobar cannot be empty(custom message)' ) ;
407- } ) ;
408- } ) ;
409-
410- describe ( 'getCustomErrorMessage invalid' , ( ) => {
411- beforeAll ( ( ) => {
412- window . REACT_INPUTS_VALIDATION = {
413- customErrorMessage : { }
414- } ;
415- } ) ;
416- it ( '[empty]: Should return false when customErrorMessage is not valid' , ( ) => {
417- const getCustomErrorMessage = Message . __get__ ( 'getCustomErrorMessage' ) ;
418- const newMessage = getCustomErrorMessage ( window . REACT_INPUTS_VALIDATION [ 'customErrorMessage' ] , Message ) ;
419- expect ( newMessage ) . equal ( false ) ;
420- } ) ;
421- } ) ;
422280} ) ;
0 commit comments