update tests based on i18n changes

This commit is contained in:
John Mitchell
2019-05-16 11:38:28 -04:00
parent e2de8e4d5f
commit f4550900bb
43 changed files with 3680 additions and 3335 deletions

View File

@@ -1,34 +1,36 @@
import { required, maxLength } from '../../src/util/validators';
const i18n = { _: val => val };
describe('validators', () => {
test('required returns undefined if value given', () => {
expect(required()('some value')).toBeUndefined();
expect(required('oops')('some value')).toBeUndefined();
expect(required(null, i18n)('some value')).toBeUndefined();
expect(required('oops', i18n)('some value')).toBeUndefined();
});
test('required returns default message if value missing', () => {
expect(required()('')).toEqual('This field must not be blank');
expect(required(null, i18n)('')).toEqual({ id: 'This field must not be blank' });
});
test('required returns custom message if value missing', () => {
expect(required('oops')('')).toEqual('oops');
expect(required('oops', i18n)('')).toEqual('oops');
});
test('required interprets white space as empty value', () => {
expect(required()(' ')).toEqual('This field must not be blank');
expect(required()('\t')).toEqual('This field must not be blank');
expect(required(null, i18n)(' ')).toEqual({ id: 'This field must not be blank' });
expect(required(null, i18n)('\t')).toEqual({ id: 'This field must not be blank' });
});
test('maxLength accepts value below max', () => {
expect(maxLength(10)('snazzy')).toBeUndefined();
expect(maxLength(10, i18n)('snazzy')).toBeUndefined();
});
test('maxLength accepts value equal to max', () => {
expect(maxLength(10)('abracadbra')).toBeUndefined();
expect(maxLength(10, i18n)('abracadbra')).toBeUndefined();
});
test('maxLength rejects value above max', () => {
expect(maxLength(8)('abracadbra'))
.toEqual('This field must not exceed 8 characters');
expect(maxLength(8, i18n)('abracadbra'))
.toEqual({ id: 'This field must not exceed {max} characters', values: { max: 8 } });
});
});