envoc-form 2.0.1-1 → 2.0.1-13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +7 -7
  2. package/dist/css/envoc-form-styles.css +43 -5
  3. package/dist/css/envoc-form-styles.css.map +1 -1
  4. package/es/AddressInput/AddressInput.js +8 -7
  5. package/es/ConfirmBaseForm/ConfirmBaseForm.js +3 -2
  6. package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +3 -2
  7. package/es/DatePickerInput/DatePickerInput.js +3 -2
  8. package/es/FileInput/DefaultFileList.js +36 -0
  9. package/es/FileInput/DropzoneFileInput.js +58 -0
  10. package/es/FileInput/FileInput.js +31 -9
  11. package/es/FileInput/index.js +2 -1
  12. package/es/Form/Form.js +11 -33
  13. package/es/Form/FormBasedPreventNavigation.js +1 -1
  14. package/es/FormGroupWrapper.js +2 -1
  15. package/es/FormInput/FormInput.js +29 -10
  16. package/es/FormInputArray/FormInputArray.js +39 -24
  17. package/es/IconInput.js +2 -1
  18. package/es/ReactSelectField/ReactSelectField.js +6 -3
  19. package/es/SubmitFormButton.js +2 -1
  20. package/es/__Tests__/FormTestBase.js +5 -2
  21. package/es/normalizers.js +10 -5
  22. package/es/useStandardFormInput.js +4 -2
  23. package/es/utils/index.js +3 -0
  24. package/es/utils/objectContainsNonSerializableProperty.js +16 -0
  25. package/es/utils/objectToFormData.js +65 -0
  26. package/es/utils/typeChecks.js +25 -0
  27. package/lib/AddressInput/AddressInput.js +15 -9
  28. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +4 -2
  29. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +6 -4
  30. package/lib/DatePickerInput/DatePickerInput.js +4 -2
  31. package/lib/FileInput/DefaultFileList.js +47 -0
  32. package/lib/FileInput/DropzoneFileInput.js +75 -0
  33. package/lib/FileInput/FileInput.js +39 -10
  34. package/lib/FileInput/index.js +13 -3
  35. package/lib/Form/Form.js +19 -39
  36. package/lib/Form/FormBasedPreventNavigation.js +7 -3
  37. package/lib/FormGroupWrapper.js +3 -1
  38. package/lib/FormInput/FormInput.js +31 -11
  39. package/lib/FormInputArray/FormInputArray.js +47 -26
  40. package/lib/FormSection.js +5 -1
  41. package/lib/IconInput.js +3 -1
  42. package/lib/ReactSelectField/ReactSelectField.js +13 -5
  43. package/lib/ReactSelectField/index.js +6 -2
  44. package/lib/SubmitFormButton.js +3 -1
  45. package/lib/__Tests__/FormTestBase.js +6 -2
  46. package/lib/index.js +7 -3
  47. package/lib/normalizers.js +10 -5
  48. package/lib/useStandardFormInput.js +5 -2
  49. package/lib/utils/index.js +23 -0
  50. package/lib/utils/objectContainsNonSerializableProperty.js +24 -0
  51. package/lib/utils/objectToFormData.js +73 -0
  52. package/lib/utils/typeChecks.js +58 -0
  53. package/lib/validators/index.js +5 -1
  54. package/package.json +99 -90
  55. package/src/AddressInput/AddesssInput.test.js +23 -23
  56. package/src/AddressInput/AddressInput.js +73 -73
  57. package/src/AddressInput/UsStates.js +53 -53
  58. package/src/AddressInput/__snapshots__/AddesssInput.test.js.snap +207 -207
  59. package/src/AddressInput/index.js +2 -2
  60. package/src/BoolInput/BoolInput.js +7 -7
  61. package/src/BoolInput/BoolInput.test.js +23 -23
  62. package/src/BoolInput/InlineBoolInput.js +7 -7
  63. package/src/BoolInput/__snapshots__/BoolInput.test.js.snap +89 -89
  64. package/src/BoolInput/boolOptions.js +6 -6
  65. package/src/BoolInput/index.js +4 -4
  66. package/src/ConfirmBaseForm/ConfirmBaseForm.js +37 -37
  67. package/src/ConfirmBaseForm/ConfirmBaseForm.test.js +14 -14
  68. package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.js.snap +23 -23
  69. package/src/ConfirmBaseForm/index.js +1 -1
  70. package/src/ConfirmDeleteForm/ConfirmDeleteForm.js +39 -39
  71. package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.js +24 -24
  72. package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.js.snap +25 -25
  73. package/src/ConfirmDeleteForm/index.js +1 -1
  74. package/src/DatePickerInput/DatePickerInput.js +46 -46
  75. package/src/DatePickerInput/DatePickerInput.test.js +74 -74
  76. package/src/DatePickerInput/__snapshots__/DatePickerInput.test.js.snap +134 -131
  77. package/src/DatePickerInput/date-picker-input.scss +42 -42
  78. package/src/DatePickerInput/index.js +3 -3
  79. package/src/ErrorScrollTarget.js +6 -6
  80. package/src/FileInput/DefaultFileList.js +39 -0
  81. package/src/FileInput/DropzoneFileInput.js +56 -0
  82. package/src/FileInput/DropzoneFileInput.test.js +24 -0
  83. package/src/FileInput/FileInput.js +77 -49
  84. package/src/FileInput/FileInput.test.js +24 -15
  85. package/src/FileInput/__snapshots__/DropzoneFileInput.test.js.snap +57 -0
  86. package/src/FileInput/__snapshots__/FileInput.test.js.snap +58 -22
  87. package/src/FileInput/file-input.scss +58 -17
  88. package/src/FileInput/index.js +4 -3
  89. package/src/Form/FocusError.js +48 -48
  90. package/src/Form/Form.js +139 -161
  91. package/src/Form/Form.test.js +23 -23
  92. package/src/Form/FormBasedPreventNavigation.js +25 -25
  93. package/src/Form/ServerErrorContext.js +7 -7
  94. package/src/Form/__snapshots__/Form.test.js.snap +9 -9
  95. package/src/Form/index.js +3 -3
  96. package/src/FormGroup.js +30 -30
  97. package/src/FormGroupWrapper.js +28 -28
  98. package/src/FormInput/FormInput.js +144 -136
  99. package/src/FormInput/FormInput.test.js +66 -66
  100. package/src/FormInput/__snapshots__/FormInput.test.js.snap +323 -313
  101. package/src/FormInput/form-input.scss +9 -9
  102. package/src/FormInput/index.js +2 -2
  103. package/src/FormInputArray/FormInputArray.js +224 -210
  104. package/src/FormInputArray/FormInputArray.test.js +108 -59
  105. package/src/FormInputArray/__snapshots__/FormInputArray.test.js.snap +52 -40
  106. package/src/FormInputArray/form-input-array.scss +13 -8
  107. package/src/FormInputArray/index.js +2 -2
  108. package/src/FormSection.js +13 -13
  109. package/src/IconInput.js +31 -31
  110. package/src/InlineFormInput/InlineFormInput.js +6 -6
  111. package/src/InlineFormInput/InlineFormInput.test.js +23 -23
  112. package/src/InlineFormInput/__snapshots__/InlineFormInput.test.js.snap +26 -26
  113. package/src/InlineFormInput/index.js +3 -3
  114. package/src/InlineFormInput/inline-form-input.scss +3 -3
  115. package/src/MoneyInput/InlineMoneyInput.js +7 -7
  116. package/src/MoneyInput/MoneyInput.js +7 -7
  117. package/src/MoneyInput/MoneyInputs.test.js +43 -43
  118. package/src/MoneyInput/__snapshots__/MoneyInputs.test.js.snap +81 -81
  119. package/src/MoneyInput/index.js +4 -4
  120. package/src/MoneyInput/money-input.scss +3 -3
  121. package/src/MoneyInput/moneyInputProps.js +12 -12
  122. package/src/NestedFormFieldContext.js +6 -6
  123. package/src/ReactSelectField/ReactSelectField.js +122 -120
  124. package/src/ReactSelectField/index.js +6 -6
  125. package/src/ReactSelectField/react-select-field.scss +5 -5
  126. package/src/StandardFormActions.js +27 -27
  127. package/src/SubmitFormButton.js +28 -28
  128. package/src/__Tests__/FormTestBase.js +14 -11
  129. package/src/__Tests__/IconInput.test.js +23 -23
  130. package/src/__Tests__/StandardFormActions.test.js +23 -23
  131. package/src/__Tests__/SubmitFormButton.test.js +23 -23
  132. package/src/__Tests__/__snapshots__/IconInput.test.js.snap +38 -38
  133. package/src/__Tests__/__snapshots__/StandardFormActions.test.js.snap +25 -25
  134. package/src/__Tests__/__snapshots__/SubmitFormButton.test.js.snap +18 -18
  135. package/src/__Tests__/index.js +2 -2
  136. package/src/_variables.scss +11 -11
  137. package/src/index.js +33 -33
  138. package/src/normalizers.js +42 -32
  139. package/src/selectors.js +3 -3
  140. package/src/styles.scss +7 -7
  141. package/src/useStandardFormInput.js +118 -118
  142. package/src/utils/index.js +3 -0
  143. package/src/utils/objectContainsNonSerializableProperty.js +15 -0
  144. package/src/utils/objectContainsNonSerializableProperty.test.js +49 -0
  145. package/src/utils/objectToFormData.js +89 -0
  146. package/src/utils/objectToFormData.test.js +76 -0
  147. package/src/utils/typeChecks.js +18 -0
  148. package/src/validators/index.js +2 -2
  149. package/src/validators/validators.js +93 -93
  150. package/src/validators/validators.test.js +79 -79
  151. package/CHANGELOG.json +0 -95
  152. package/CHANGELOG.md +0 -58
  153. package/es/FormInput/utilities.js +0 -71
  154. package/lib/FormInput/utilities.js +0 -86
  155. package/src/FormInput/utilities.js +0 -26
@@ -0,0 +1,89 @@
1
+ // Original: https://github.com/therealparmesh/object-to-formdata/blob/master/src/index.js
2
+ // With Multiple Form File Fix: https://github.com/therealparmesh/object-to-formdata/pull/94/files
3
+ import {
4
+ isUndefined,
5
+ isNull,
6
+ isBoolean,
7
+ isObject,
8
+ isArray,
9
+ isDate,
10
+ isBlob,
11
+ isFile,
12
+ } from './typeChecks';
13
+
14
+ const serialize = (obj, cfg, fd, pre) => {
15
+ cfg = cfg || {};
16
+
17
+ cfg.indices = isUndefined(cfg.indices) ? false : cfg.indices;
18
+
19
+ cfg.nullsAsUndefineds = isUndefined(cfg.nullsAsUndefineds)
20
+ ? false
21
+ : cfg.nullsAsUndefineds;
22
+
23
+ cfg.booleansAsIntegers = isUndefined(cfg.booleansAsIntegers)
24
+ ? false
25
+ : cfg.booleansAsIntegers;
26
+
27
+ cfg.allowEmptyArrays = isUndefined(cfg.allowEmptyArrays)
28
+ ? false
29
+ : cfg.allowEmptyArrays;
30
+
31
+ //reverse of normal because we want a different default
32
+ cfg.dotNotation = isUndefined(cfg.dotNotation) ? true : cfg.dotNotation;
33
+
34
+ fd = fd || new FormData();
35
+
36
+ if (isUndefined(obj)) {
37
+ return fd;
38
+ } else if (isNull(obj)) {
39
+ if (!cfg.nullsAsUndefineds) {
40
+ fd.append(pre, '');
41
+ }
42
+ } else if (isBoolean(obj)) {
43
+ if (cfg.booleansAsIntegers) {
44
+ fd.append(pre, obj ? 1 : 0);
45
+ } else {
46
+ fd.append(pre, obj);
47
+ }
48
+ } else if (isArray(obj)) {
49
+ if (obj.length) {
50
+ obj.forEach((value, index) => {
51
+ let key;
52
+ if (cfg.noFileListBrackets && isFile(value)) {
53
+ key = pre;
54
+ } else {
55
+ key = pre + '[' + (cfg.indices ? index : '') + ']';
56
+ }
57
+ serialize(value, cfg, fd, key);
58
+ });
59
+ } else if (cfg.allowEmptyArrays) {
60
+ fd.append(pre + '[]', '');
61
+ }
62
+ } else if (isDate(obj)) {
63
+ fd.append(pre, obj.toISOString());
64
+ } else if (isObject(obj) && !isFile(obj) && !isBlob(obj)) {
65
+ Object.keys(obj).forEach((prop) => {
66
+ const value = obj[prop];
67
+
68
+ if (isArray(value)) {
69
+ while (prop.length > 2 && prop.lastIndexOf('[]') === prop.length - 2) {
70
+ prop = prop.substring(0, prop.length - 2);
71
+ }
72
+ }
73
+
74
+ const key = pre
75
+ ? cfg.dotNotation
76
+ ? pre + '.' + prop
77
+ : pre + '[' + prop + ']'
78
+ : prop;
79
+
80
+ serialize(value, cfg, fd, key);
81
+ });
82
+ } else {
83
+ fd.append(pre, obj);
84
+ }
85
+
86
+ return fd;
87
+ };
88
+
89
+ export default serialize;
@@ -0,0 +1,76 @@
1
+ import serialize from './objectToFormData';
2
+
3
+ const options = {
4
+ indices: true,
5
+ dotNotation: true,
6
+ allowEmptyArrays: true,
7
+ noFileListBrackets: true,
8
+ };
9
+
10
+ const formDataAppend = global.FormData.prototype.append;
11
+
12
+ beforeEach(() => {
13
+ global.FormData.prototype.append = jest.fn(formDataAppend);
14
+ });
15
+
16
+ describe('Object To Form Data', () => {
17
+ it('properly serializes a simple object', () => {
18
+ const object = {
19
+ name: 'Bob',
20
+ age: 20,
21
+ };
22
+
23
+ const result = serialize(object, options);
24
+ expect(result.get('name')).toBe(object.name);
25
+ expect(result.get('age')).toBe('20');
26
+ });
27
+
28
+ it('properly serializes an object with a non-file array property', () => {
29
+ const object = {
30
+ name: 'Bob',
31
+ age: 20,
32
+ favoriteFoods: ['Hamburger', 'Pizza'],
33
+ };
34
+
35
+ const result = serialize(object, options);
36
+ expect(result.get('name')).toBe(object.name);
37
+ expect(result.has('favoriteFoods[0]')).toBe(true);
38
+ expect(result.get('favoriteFoods[0]')).toBe('Hamburger');
39
+ expect(result.has('favoriteFoods[1]')).toBe(true);
40
+ expect(result.get('favoriteFoods[1]')).toBe('Pizza');
41
+ });
42
+
43
+ it('properly serializes a file in a form', () => {
44
+ const object = {
45
+ a: new File(['foo'], 'foo.txt', {
46
+ type: 'text/plain',
47
+ }),
48
+ };
49
+
50
+ const result = serialize(object, options);
51
+ expect(result.has('a')).toBe(true);
52
+ expect(result.get('a')).toBeInstanceOf(File);
53
+ });
54
+
55
+ it('properly serializes an object with a file array property', () => {
56
+ const foo = new File(['foo'], 'foo.txt', {
57
+ type: 'text/plain',
58
+ });
59
+ const bar = new File(['bar'], 'bar.txt', {
60
+ type: 'text/plain',
61
+ });
62
+ const object = {
63
+ fileArray: [foo, bar],
64
+ };
65
+
66
+ const result = serialize(object, options);
67
+ expect(result.append).toHaveBeenCalledTimes(2);
68
+ expect(result.append).toHaveBeenNthCalledWith(1, 'fileArray', foo);
69
+ expect(result.append).toHaveBeenNthCalledWith(2, 'fileArray', bar);
70
+ expect(result.has('fileArray[]')).toBe(false);
71
+ expect(result.has('fileArray[0]')).toBe(false);
72
+ expect(result.has('fileArray[1]')).toBe(false);
73
+ expect(result.has('fileArray')).toBe(true);
74
+ expect(result.getAll('fileArray')).toEqual(object.fileArray);
75
+ });
76
+ });
@@ -0,0 +1,18 @@
1
+ export const isUndefined = (value) => value === undefined;
2
+ export const isNull = (value) => value === null;
3
+ export const isBoolean = (value) => typeof value === 'boolean';
4
+ export const isObject = (value) => value === Object(value);
5
+ export const isArray = (value) => Array.isArray(value);
6
+ export const isDate = (value) => value instanceof Date;
7
+
8
+ export const isBlob = (value) =>
9
+ value &&
10
+ typeof value.size === 'number' &&
11
+ typeof value.type === 'string' &&
12
+ typeof value.slice === 'function';
13
+
14
+ export const isFile = (value) =>
15
+ isBlob(value) &&
16
+ typeof value.name === 'string' &&
17
+ (typeof value.lastModifiedDate === 'object' ||
18
+ typeof value.lastModified === 'number');
@@ -1,2 +1,2 @@
1
- import * as validators from './validators';
2
- export default validators;
1
+ import * as validators from './validators';
2
+ export default validators;
@@ -1,93 +1,93 @@
1
- export const required = (value) =>
2
- value || value === false || value === 0 ? undefined : 'Required';
3
-
4
- //asserts that the value is a certain number of characters. numbers are coerced to a string
5
- export const length = (len) => (value) => {
6
- let val = value;
7
- const type = typeof val;
8
- switch (type) {
9
- case 'undefined':
10
- return undefined;
11
- case 'string':
12
- break;
13
- case 'number':
14
- val = val.toString();
15
- break;
16
- default:
17
- console.error(`Invalid value type: ${type} passed to length validator`);
18
- }
19
- return val.length === len ? undefined : `Length must be ${len}`;
20
- };
21
-
22
- export const integer = (val) => {
23
- if (!Number.isInteger(parseFloat(val))) {
24
- return 'Must be a whole number';
25
- }
26
- };
27
-
28
- export const maxLength = function maxLength(length) {
29
- return (value) => {
30
- if (value) {
31
- return value.length <= length
32
- ? undefined
33
- : `Maximum length ${length} exceeded`;
34
- } else {
35
- return undefined;
36
- }
37
- };
38
- };
39
-
40
- export function maxCount(count) {
41
- return (value) => {
42
- return !value || value.filter((x) => !x.isDeleted).length <= count
43
- ? undefined
44
- : `Should not have more than ${count}`;
45
- };
46
- }
47
-
48
- export function minCount(count) {
49
- return (value) => {
50
- return value && value.filter((x) => !x.isDeleted).length >= count
51
- ? undefined
52
- : `Should have at least ${count}`;
53
- };
54
- }
55
-
56
- export const maxValue = function maxValue(value) {
57
- return (inputValue) => {
58
- if (inputValue && value) {
59
- return inputValue <= value
60
- ? undefined
61
- : `Maximum value ${value} exceeded`;
62
- } else {
63
- return undefined;
64
- }
65
- };
66
- };
67
-
68
- export const minValue = function minValue(value) {
69
- return (inputValue) => {
70
- if (inputValue && value) {
71
- return inputValue >= value ? undefined : `Minimum value ${value} not met`;
72
- } else {
73
- return undefined;
74
- }
75
- };
76
- };
77
-
78
- export const zipCode = (value) => {
79
- return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
80
- ? 'Invalid ZIP Code'
81
- : undefined;
82
- };
83
-
84
- //one of the validators provided must be true
85
- export const any = (...validatorList) => (value) => {
86
- if (validatorList.length === 0 || !value) {
87
- return;
88
- }
89
- return validatorList.reduce(
90
- (isAnyTrue, any) => (isAnyTrue ? isAnyTrue : any(value)),
91
- false
92
- );
93
- };
1
+ export const required = (value) =>
2
+ value || value === false || value === 0 ? undefined : 'Required';
3
+
4
+ //asserts that the value is a certain number of characters. numbers are coerced to a string
5
+ export const length = (len) => (value) => {
6
+ let val = value;
7
+ const type = typeof val;
8
+ switch (type) {
9
+ case 'undefined':
10
+ return undefined;
11
+ case 'string':
12
+ break;
13
+ case 'number':
14
+ val = val.toString();
15
+ break;
16
+ default:
17
+ console.error(`Invalid value type: ${type} passed to length validator`);
18
+ }
19
+ return val.length === len ? undefined : `Length must be ${len}`;
20
+ };
21
+
22
+ export const integer = (val) => {
23
+ if (!Number.isInteger(parseFloat(val))) {
24
+ return 'Must be a whole number';
25
+ }
26
+ };
27
+
28
+ export const maxLength = function maxLength(length) {
29
+ return (value) => {
30
+ if (value) {
31
+ return value.length <= length
32
+ ? undefined
33
+ : `Maximum length ${length} exceeded`;
34
+ } else {
35
+ return undefined;
36
+ }
37
+ };
38
+ };
39
+
40
+ export function maxCount(count) {
41
+ return (value) => {
42
+ return !value || value.filter((x) => !x.isDeleted).length <= count
43
+ ? undefined
44
+ : `Should not have more than ${count}`;
45
+ };
46
+ }
47
+
48
+ export function minCount(count) {
49
+ return (value) => {
50
+ return value && value.filter((x) => !x.isDeleted).length >= count
51
+ ? undefined
52
+ : `Should have at least ${count}`;
53
+ };
54
+ }
55
+
56
+ export const maxValue = function maxValue(value) {
57
+ return (inputValue) => {
58
+ if (inputValue && value) {
59
+ return inputValue <= value
60
+ ? undefined
61
+ : `Maximum value ${value} exceeded`;
62
+ } else {
63
+ return undefined;
64
+ }
65
+ };
66
+ };
67
+
68
+ export const minValue = function minValue(value) {
69
+ return (inputValue) => {
70
+ if (inputValue && value) {
71
+ return inputValue >= value ? undefined : `Minimum value ${value} not met`;
72
+ } else {
73
+ return undefined;
74
+ }
75
+ };
76
+ };
77
+
78
+ export const zipCode = (value) => {
79
+ return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
80
+ ? 'Invalid ZIP Code'
81
+ : undefined;
82
+ };
83
+
84
+ //one of the validators provided must be true
85
+ export const any = (...validatorList) => (value) => {
86
+ if (validatorList.length === 0 || !value) {
87
+ return;
88
+ }
89
+ return validatorList.reduce(
90
+ (isAnyTrue, any) => (isAnyTrue ? isAnyTrue : any(value)),
91
+ false
92
+ );
93
+ };
@@ -1,79 +1,79 @@
1
- import { integer, length, maxLength, maxValue, minValue } from './validators';
2
-
3
- describe('integer validator', () => {
4
- it('accepts an integer', () => {
5
- const returned = integer(123);
6
- expect(returned).toBe(undefined);
7
- });
8
-
9
- it("doesn't accept a float", () => {
10
- const returned = integer(123.5569);
11
- expect(returned).toBe('Must be a whole number');
12
- });
13
- });
14
-
15
- describe('length validator', () => {
16
- it('fails for invalid Length', () => {
17
- const length10 = length(10);
18
- const tooLong = length10('01234567890');
19
- const tooShort = length10('aaa');
20
- expect(tooLong).toBe('Length must be 10');
21
- expect(tooShort).toBe('Length must be 10');
22
- });
23
-
24
- it('succeeds for correct length', () => {
25
- const length10 = length(10);
26
- const validString = length10('0123456789');
27
- const validNumber = length10(1234567890);
28
- expect(validString).toBe(undefined);
29
- expect(validNumber).toBe(undefined);
30
- });
31
- });
32
-
33
- describe('maxValue validator', () => {
34
- it('fails for invalid value', () => {
35
- const maxValue10 = maxValue(10);
36
- const tooBig = maxValue10(11);
37
- expect(tooBig).toBe('Maximum value 10 exceeded');
38
- });
39
-
40
- it('succeeds for valid value', () => {
41
- const maxValue10 = maxValue(10);
42
- const maxAllowable = maxValue10(10);
43
- const lowAllowable = maxValue10(1);
44
- expect(maxAllowable).toBe(undefined);
45
- expect(lowAllowable).toBe(undefined);
46
- });
47
- });
48
-
49
- describe('minValue validator', () => {
50
- it('fails for invalid value', () => {
51
- const minValue10 = minValue(10);
52
- const tooSmall = minValue10(9);
53
- expect(tooSmall).toBe('Minimum value 10 not met');
54
- });
55
-
56
- it('succeeds for valid value', () => {
57
- const minValue10 = minValue(10);
58
- const minAllowable = minValue10(10);
59
- const highAllowable = minValue10(15);
60
- expect(minAllowable).toBe(undefined);
61
- expect(highAllowable).toBe(undefined);
62
- });
63
- });
64
-
65
- describe('maxLength validator', () => {
66
- it('fails for invalid value', () => {
67
- const maxLength10 = maxLength(10);
68
- const tooLong = maxLength10('012345678910');
69
- expect(tooLong).toBe('Maximum length 10 exceeded');
70
- });
71
-
72
- it('succeeds for valid value', () => {
73
- const maxLength10 = maxLength(10);
74
- const exactMatch = maxLength10('0123456789');
75
- const shortValid = maxLength10('0123');
76
- expect(exactMatch).toBe(undefined);
77
- expect(shortValid).toBe(undefined);
78
- });
79
- });
1
+ import { integer, length, maxLength, maxValue, minValue } from './validators';
2
+
3
+ describe('integer validator', () => {
4
+ it('accepts an integer', () => {
5
+ const returned = integer(123);
6
+ expect(returned).toBe(undefined);
7
+ });
8
+
9
+ it("doesn't accept a float", () => {
10
+ const returned = integer(123.5569);
11
+ expect(returned).toBe('Must be a whole number');
12
+ });
13
+ });
14
+
15
+ describe('length validator', () => {
16
+ it('fails for invalid Length', () => {
17
+ const length10 = length(10);
18
+ const tooLong = length10('01234567890');
19
+ const tooShort = length10('aaa');
20
+ expect(tooLong).toBe('Length must be 10');
21
+ expect(tooShort).toBe('Length must be 10');
22
+ });
23
+
24
+ it('succeeds for correct length', () => {
25
+ const length10 = length(10);
26
+ const validString = length10('0123456789');
27
+ const validNumber = length10(1234567890);
28
+ expect(validString).toBe(undefined);
29
+ expect(validNumber).toBe(undefined);
30
+ });
31
+ });
32
+
33
+ describe('maxValue validator', () => {
34
+ it('fails for invalid value', () => {
35
+ const maxValue10 = maxValue(10);
36
+ const tooBig = maxValue10(11);
37
+ expect(tooBig).toBe('Maximum value 10 exceeded');
38
+ });
39
+
40
+ it('succeeds for valid value', () => {
41
+ const maxValue10 = maxValue(10);
42
+ const maxAllowable = maxValue10(10);
43
+ const lowAllowable = maxValue10(1);
44
+ expect(maxAllowable).toBe(undefined);
45
+ expect(lowAllowable).toBe(undefined);
46
+ });
47
+ });
48
+
49
+ describe('minValue validator', () => {
50
+ it('fails for invalid value', () => {
51
+ const minValue10 = minValue(10);
52
+ const tooSmall = minValue10(9);
53
+ expect(tooSmall).toBe('Minimum value 10 not met');
54
+ });
55
+
56
+ it('succeeds for valid value', () => {
57
+ const minValue10 = minValue(10);
58
+ const minAllowable = minValue10(10);
59
+ const highAllowable = minValue10(15);
60
+ expect(minAllowable).toBe(undefined);
61
+ expect(highAllowable).toBe(undefined);
62
+ });
63
+ });
64
+
65
+ describe('maxLength validator', () => {
66
+ it('fails for invalid value', () => {
67
+ const maxLength10 = maxLength(10);
68
+ const tooLong = maxLength10('012345678910');
69
+ expect(tooLong).toBe('Maximum length 10 exceeded');
70
+ });
71
+
72
+ it('succeeds for valid value', () => {
73
+ const maxLength10 = maxLength(10);
74
+ const exactMatch = maxLength10('0123456789');
75
+ const shortValid = maxLength10('0123');
76
+ expect(exactMatch).toBe(undefined);
77
+ expect(shortValid).toBe(undefined);
78
+ });
79
+ });
package/CHANGELOG.json DELETED
@@ -1,95 +0,0 @@
1
- {
2
- "name": "envoc-form",
3
- "entries": [
4
- {
5
- "version": "2.0.0",
6
- "tag": "envoc-form_v2.0.0",
7
- "date": "Fri, 11 Sep 2020 16:49:17 GMT",
8
- "comments": {}
9
- },
10
- {
11
- "version": "1.3.1",
12
- "tag": "envoc-form_v1.3.1",
13
- "date": "Fri, 04 Sep 2020 19:35:20 GMT",
14
- "comments": {}
15
- },
16
- {
17
- "version": "1.3.0",
18
- "tag": "envoc-form_v1.3.0",
19
- "date": "Tue, 01 Sep 2020 16:02:23 GMT",
20
- "comments": {}
21
- },
22
- {
23
- "version": "1.2.0",
24
- "tag": "envoc-form_v1.2.0",
25
- "date": "Mon, 31 Aug 2020 20:33:06 GMT",
26
- "comments": {
27
- "none": [
28
- {
29
- "comment": "readme change"
30
- },
31
- {
32
- "comment": "Resolves issues with scss not being included, provides support for tree-shaking, adds jest testing"
33
- },
34
- {
35
- "comment": " Prerelease"
36
- },
37
- {
38
- "comment": "Fixes missing destructed prop on ConfirmBaseForm and adds some tests"
39
- },
40
- {
41
- "comment": "build script changes"
42
- },
43
- {
44
- "comment": "Fix issues with validators export"
45
- },
46
- {
47
- "comment": "fixes normalizers"
48
- }
49
- ]
50
- }
51
- },
52
- {
53
- "version": "1.1.26",
54
- "tag": "envoc-form_v1.1.26",
55
- "date": "Mon, 13 Jul 2020 16:17:47 GMT",
56
- "comments": {}
57
- },
58
- {
59
- "version": "1.1.25",
60
- "tag": "envoc-form_v1.1.25",
61
- "date": "Fri, 10 Jul 2020 19:16:12 GMT",
62
- "comments": {
63
- "none": [
64
- {
65
- "comment": "Changing the 'sideEffects' to be false for better tree shaking"
66
- }
67
- ]
68
- }
69
- },
70
- {
71
- "version": "1.1.24",
72
- "tag": "envoc-form_v1.1.24",
73
- "date": "Fri, 10 Jul 2020 18:58:53 GMT",
74
- "comments": {
75
- "none": [
76
- {
77
- "comment": "Resolves issues with scss not being included, provides support for tree-shaking, adds jest testing"
78
- }
79
- ]
80
- }
81
- },
82
- {
83
- "version": "1.1.23",
84
- "tag": "envoc-form_v1.1.23",
85
- "date": "Thu, 25 Jun 2020 19:05:11 GMT",
86
- "comments": {
87
- "none": [
88
- {
89
- "comment": "Initial envoc-form implementation"
90
- }
91
- ]
92
- }
93
- }
94
- ]
95
- }
package/CHANGELOG.md DELETED
@@ -1,58 +0,0 @@
1
- # Change Log - envoc-form
2
-
3
- This log was last generated on Fri, 11 Sep 2020 16:49:17 GMT and should not be manually modified.
4
-
5
- ## 2.0.0
6
- Fri, 11 Sep 2020 16:49:17 GMT
7
-
8
- *Version update only*
9
-
10
- ## 1.3.1
11
- Fri, 04 Sep 2020 19:35:20 GMT
12
-
13
- *Version update only*
14
-
15
- ## 1.3.0
16
- Tue, 01 Sep 2020 16:02:23 GMT
17
-
18
- *Version update only*
19
-
20
- ## 1.2.0
21
- Mon, 31 Aug 2020 20:33:06 GMT
22
-
23
- ### Updates
24
-
25
- - readme change
26
- - Resolves issues with scss not being included, provides support for tree-shaking, adds jest testing
27
- - Prerelease
28
- - Fixes missing destructed prop on ConfirmBaseForm and adds some tests
29
- - build script changes
30
- - Fix issues with validators export
31
- - fixes normalizers
32
-
33
- ## 1.1.26
34
- Mon, 13 Jul 2020 16:17:47 GMT
35
-
36
- *Version update only*
37
-
38
- ## 1.1.25
39
- Fri, 10 Jul 2020 19:16:12 GMT
40
-
41
- ### Updates
42
-
43
- - Changing the 'sideEffects' to be false for better tree shaking
44
-
45
- ## 1.1.24
46
- Fri, 10 Jul 2020 18:58:53 GMT
47
-
48
- ### Updates
49
-
50
- - Resolves issues with scss not being included, provides support for tree-shaking, adds jest testing
51
-
52
- ## 1.1.23
53
- Thu, 25 Jun 2020 19:05:11 GMT
54
-
55
- ### Updates
56
-
57
- - Initial envoc-form implementation
58
-