Review changes

This commit is contained in:
Vesa Luusua 2018-04-16 19:08:17 +03:00
parent c4b48e7a05
commit 5dd455ffa5
3 changed files with 36 additions and 2 deletions

View file

@ -66,7 +66,6 @@ export const Empty = {
},
onSubmit: values => {
console.log('Submitting a form with values:', values);
return false;
},
},
group: 'custom inputs',

View file

@ -71,7 +71,6 @@ export const Empty = {
},
onSubmit: values => {
console.log('Submitting a form with values:', values);
return false;
},
},
group: 'custom inputs',

View file

@ -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');
});
});
});