diff --git a/src/components/FieldDateInput/FieldDateInput.example.js b/src/components/FieldDateInput/FieldDateInput.example.js index 1d0249fb..11d37741 100644 --- a/src/components/FieldDateInput/FieldDateInput.example.js +++ b/src/components/FieldDateInput/FieldDateInput.example.js @@ -66,7 +66,6 @@ export const Empty = { }, onSubmit: values => { console.log('Submitting a form with values:', values); - return false; }, }, group: 'custom inputs', diff --git a/src/components/FieldDateRangeInput/FieldDateRangeInput.example.js b/src/components/FieldDateRangeInput/FieldDateRangeInput.example.js index 105364bd..4a8bcecb 100644 --- a/src/components/FieldDateRangeInput/FieldDateRangeInput.example.js +++ b/src/components/FieldDateRangeInput/FieldDateRangeInput.example.js @@ -71,7 +71,6 @@ export const Empty = { }, onSubmit: values => { console.log('Submitting a form with values:', values); - return false; }, }, group: 'custom inputs', diff --git a/src/util/validators.test.js b/src/util/validators.test.js index 22e7b08c..56c286bd 100644 --- a/src/util/validators.test.js +++ b/src/util/validators.test.js @@ -5,6 +5,7 @@ import { minLength, maxLength, moneySubUnitAmountAtLeast, + composeValidators, } from './validators'; const { Money } = sdkTypes; @@ -148,4 +149,39 @@ describe('validators', () => { expect(moneySubUnitAmountAtLeast('fail', 50)(new Money(100, 'USD'))).toBeUndefined(); }); }); + describe('composeValidators()', () => { + const validateLength = composeValidators(minLength('minLength', 4), maxLength('maxLength', 6)); + + it('should fail on composed minLength (4) and maxLength (6): undefined', () => { + expect(validateLength(undefined)).toEqual('minLength'); + }); + it('should fail on composed minLength (4) and maxLength (6): null', () => { + expect(validateLength(null)).toEqual('minLength'); + }); + + it('should fail on composed minLength (4) and maxLength (6): bad', () => { + expect(validateLength('bad')).toEqual('minLength'); + }); + it('should fail on composed minLength (4) and maxLength (6): longword', () => { + expect(validateLength('longword')).toEqual('maxLength'); + }); + it('should allow on composed minLength (4) and maxLength (6): good', () => { + expect(validateLength('good')).toBeUndefined(); + }); + + it('should fail on composed required and minLength (4): empty string. Error: required', () => { + const requiredWithMinLength = composeValidators( + required('required'), + minLength('minLength', 6) + ); + expect(requiredWithMinLength('')).toEqual('required'); + }); + it('should fail on composed minLength (4) and required: empty string. Error: minLength', () => { + const requiredWithMinLength = composeValidators( + minLength('minLength', 4), + required('required') + ); + expect(validateLength('')).toEqual('minLength'); + }); + }); });