envoc-form 5.0.3 → 5.0.5

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 (113) hide show
  1. package/README.md +158 -15
  2. package/es/Input/CheckboxGroup.d.ts +6 -0
  3. package/es/Input/CheckboxGroup.js +14 -0
  4. package/es/Input/CheckboxInputGroup.d.ts +13 -0
  5. package/es/Input/CheckboxInputGroup.js +41 -0
  6. package/es/index.d.ts +2 -0
  7. package/es/index.js +1 -0
  8. package/lib/Input/CheckboxGroup.d.ts +6 -0
  9. package/lib/Input/CheckboxGroup.js +20 -0
  10. package/lib/Input/CheckboxInputGroup.d.ts +13 -0
  11. package/lib/Input/CheckboxInputGroup.js +46 -0
  12. package/lib/index.d.ts +2 -0
  13. package/lib/index.js +3 -1
  14. package/package.json +111 -111
  15. package/src/AddressInput/AddressInput.test.tsx +27 -27
  16. package/src/AddressInput/AddressInput.tsx +82 -82
  17. package/src/AddressInput/UsStates.ts +55 -55
  18. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +182 -182
  19. package/src/ConfirmBaseForm/ConfirmBaseForm.test.tsx +24 -24
  20. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +74 -74
  21. package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +23 -23
  22. package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.tsx +24 -24
  23. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +87 -87
  24. package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +25 -25
  25. package/src/DatePicker/DatePicker.test.tsx +48 -48
  26. package/src/DatePicker/DatePickerGroup.tsx +115 -115
  27. package/src/DatePicker/DatePickerHelper.ts +4 -4
  28. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +28 -28
  29. package/src/DatePicker/StringDatePickerGroup.tsx +20 -20
  30. package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +152 -152
  31. package/src/Field/CustomFieldInputProps.ts +10 -10
  32. package/src/Field/CustomFieldMetaProps.ts +5 -5
  33. package/src/Field/Field.tsx +113 -113
  34. package/src/Field/FieldErrorScrollTarget.tsx +12 -12
  35. package/src/Field/FieldNameContext.ts +6 -6
  36. package/src/Field/FieldSection.tsx +18 -18
  37. package/src/Field/InjectedFieldProps.ts +8 -8
  38. package/src/Field/StandAloneInput.tsx +55 -55
  39. package/src/Field/useStandardField.ts +125 -125
  40. package/src/FieldArray/FieldArray.tsx +154 -154
  41. package/src/File/FileGroup.test.tsx +35 -35
  42. package/src/File/FileGroup.tsx +85 -85
  43. package/src/File/FileList.tsx +21 -21
  44. package/src/File/__snapshots__/FileGroup.test.tsx.snap +34 -34
  45. package/src/File/humanFileSize.ts +8 -8
  46. package/src/Form/FocusError.tsx +55 -55
  47. package/src/Form/Form.test.tsx +14 -14
  48. package/src/Form/Form.tsx +237 -237
  49. package/src/Form/FormBasedPreventNavigation.tsx +56 -56
  50. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -77
  51. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -59
  52. package/src/Form/ServerErrorContext.ts +18 -18
  53. package/src/Form/__snapshots__/Form.test.tsx.snap +10 -10
  54. package/src/FormActions.tsx +47 -47
  55. package/src/FormDefaults.ts +2 -2
  56. package/src/Group.tsx +62 -62
  57. package/src/Input/CheckboxGroup.tsx +60 -0
  58. package/src/Input/CheckboxInputGroup.tsx +78 -0
  59. package/src/Input/IconInputGroup.tsx +54 -54
  60. package/src/Input/InputGroup.tsx +72 -72
  61. package/src/Input/MoneyInputGroup.tsx +50 -50
  62. package/src/Input/NumberInputGroup.tsx +48 -48
  63. package/src/Input/PhoneNumberInputGroup.tsx +45 -45
  64. package/src/Input/StringInputGroup.tsx +53 -53
  65. package/src/Input/__Tests__/CheckboxInputGroup.test.tsx +26 -0
  66. package/src/Input/__Tests__/IconInputGroup.test.tsx +35 -35
  67. package/src/Input/__Tests__/MoneyInputGroup.test.tsx +37 -37
  68. package/src/Input/__Tests__/NumberInputGroup.test.tsx +35 -35
  69. package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +36 -36
  70. package/src/Input/__Tests__/StringInputGroup.test.tsx +27 -27
  71. package/src/Input/__Tests__/__snapshots__/CheckboxInputGroup.test.tsx.snap +33 -0
  72. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +32 -32
  73. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +34 -34
  74. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +32 -32
  75. package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -33
  76. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +31 -31
  77. package/src/Normalization/NormalizationFunction.ts +4 -4
  78. package/src/Normalization/normalizers.ts +44 -44
  79. package/src/Select/BooleanSelectGroup.tsx +28 -28
  80. package/src/Select/NumberSelectGroup.tsx +16 -16
  81. package/src/Select/SelectGroup.tsx +124 -124
  82. package/src/Select/SelectGroupPropsHelper.ts +4 -4
  83. package/src/Select/StringSelectGroup.tsx +16 -16
  84. package/src/Select/__tests__/BooleanSelectGroup.test.tsx +35 -35
  85. package/src/Select/__tests__/NumberSelectGroup.test.tsx +87 -87
  86. package/src/Select/__tests__/StringSelectGroup.test.tsx +89 -89
  87. package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +98 -98
  88. package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +195 -195
  89. package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +195 -195
  90. package/src/StandardFormActions.tsx +41 -41
  91. package/src/SubmitFormButton.tsx +54 -54
  92. package/src/TextArea/TextAreaGroup.tsx +64 -64
  93. package/src/Validation/ValidatedApiResult.ts +8 -8
  94. package/src/Validation/ValidationError.ts +6 -6
  95. package/src/Validation/ValidationFunction.ts +4 -4
  96. package/src/Validation/validators.test.tsx +81 -81
  97. package/src/Validation/validators.ts +97 -97
  98. package/src/__Tests__/FormTestBase.tsx +65 -64
  99. package/src/__Tests__/RealisticForm.test.tsx +82 -82
  100. package/src/__Tests__/StandardFormActions.test.tsx +17 -17
  101. package/src/__Tests__/SubmitFormButton.test.tsx +17 -17
  102. package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +27 -27
  103. package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +20 -20
  104. package/src/__Tests__/index.ts +3 -3
  105. package/src/_variables.scss +11 -11
  106. package/src/index.ts +156 -153
  107. package/src/react-app-env.d.ts +1 -1
  108. package/src/setupTests.ts +1 -1
  109. package/src/utils/objectContainsNonSerializableProperty.test.tsx +49 -49
  110. package/src/utils/objectContainsNonSerializableProperty.ts +17 -17
  111. package/src/utils/objectToFormData.test.tsx +76 -76
  112. package/src/utils/objectToFormData.ts +105 -105
  113. package/src/utils/typeChecks.ts +18 -18
package/src/index.ts CHANGED
@@ -1,153 +1,156 @@
1
- // Address
2
- export { default as AddressInput } from './AddressInput/AddressInput';
3
- export type { AddressInputProps } from './AddressInput/AddressInput';
4
-
5
- // Button
6
- export { default as SubmitFormButton } from './SubmitFormButton';
7
- export type { SubmitFormButtonProps } from './SubmitFormButton';
8
-
9
- // ConfirmBaseForm
10
- export { default as ConfirmBaseForm } from './ConfirmBaseForm/ConfirmBaseForm';
11
- export type { ConfirmBaseFormProps } from './ConfirmBaseForm/ConfirmBaseForm';
12
-
13
- // ConfirmDeleteForm
14
- export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteForm';
15
- export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteForm';
16
-
17
- // Date
18
- export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
19
- export type { DatePickerGroupProps } from './DatePicker/DatePickerGroup';
20
- export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
21
-
22
- export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
23
-
24
- export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
25
- export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGroup';
26
-
27
- export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
28
- export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
29
-
30
- // Field
31
- export { default as Field } from './Field/Field';
32
- export type { FieldProps } from './Field/Field';
33
-
34
- export type { RenderComponent } from './Field/Field';
35
- export type { RenderComponentProps } from './Field/Field';
36
-
37
- export { default as FieldErrorScrollTarget } from './Field/FieldErrorScrollTarget';
38
-
39
- export { FieldNameContext } from './Field/FieldNameContext';
40
-
41
- export type { InjectedFieldProps } from './Field/InjectedFieldProps';
42
-
43
- export { default as StandAloneInput } from './Field/StandAloneInput';
44
-
45
- export type { StandAloneInputProps } from './Field/StandAloneInput';
46
-
47
- export { default as useStandardField } from './Field/useStandardField';
48
- export type { useStandardFieldProps } from './Field/useStandardField';
49
-
50
- // Field Array
51
- export { default as FieldArray } from './FieldArray/FieldArray';
52
- export type {
53
- FieldArrayProps,
54
- ArrayFormBuilderProp,
55
- } from './FieldArray/FieldArray';
56
-
57
- // File
58
- export { default as FileGroup } from './File/FileGroup';
59
- export type { FileGroupProps } from './File/FileGroup';
60
-
61
- // Form
62
- export { default as Form } from './Form/Form';
63
- export type { FormBuilderProp, FormProps } from './Form/Form';
64
- export { ServerErrorContext } from './Form/ServerErrorContext';
65
- export type {
66
- ServerErrorContextProps,
67
- ServerErrors,
68
- } from './Form/ServerErrorContext';
69
-
70
- export { default as FormActions } from './FormActions';
71
- export type { FormActionsProps } from './FormActions';
72
-
73
- export { default as StandardFormActions } from './StandardFormActions';
74
- export type { StandardFormActionsProps } from './StandardFormActions';
75
-
76
- // FormDefaults
77
- export { FormDefaults } from './FormDefaults';
78
-
79
- // Input
80
- export { default as Group } from './Group';
81
- export type { GroupProps } from './Group';
82
-
83
- export { default as IconInputGroup } from './Input/IconInputGroup';
84
- export type { IconInputGroupProps } from './Input/IconInputGroup';
85
-
86
- export { default as InputGroup } from './Input/InputGroup';
87
- export type { InputGroupProps } from './Input/InputGroup';
88
-
89
- export { default as MoneyInputGroup } from './Input/MoneyInputGroup';
90
- export type { MoneyInputGroupProps } from './Input/MoneyInputGroup';
91
-
92
- export { default as NumberInputGroup } from './Input/NumberInputGroup';
93
- export type { NumberInputGroupProps } from './Input/NumberInputGroup';
94
-
95
- export { default as PhoneNumberInputGroup } from './Input/PhoneNumberInputGroup';
96
- export type { PhoneNumberInputGroupProps } from './Input/PhoneNumberInputGroup';
97
-
98
- export { default as StringInputGroup } from './Input/StringInputGroup';
99
- export type { StringInputGroupProps } from './Input/StringInputGroup';
100
-
101
- // Normalization
102
- export type { NormalizationFunction } from './Normalization/NormalizationFunction';
103
- export * as normalizers from './Normalization/normalizers';
104
-
105
- // Select
106
- export { default as SelectGroup } from './Select/SelectGroup';
107
- export type { SelectGroupProps, SelectOption } from './Select/SelectGroup';
108
-
109
- export { BooleanSelectGroup } from './Select/BooleanSelectGroup';
110
- export type { BooleanSelectGroupProps } from './Select/BooleanSelectGroup';
111
-
112
- export {
113
- MultiNumberSelectGroup,
114
- SingleNumberSelectGroup,
115
- } from './Select/NumberSelectGroup';
116
- export type {
117
- MultiNumberSelectGroupProps,
118
- SingleNumberSelectGroupProps,
119
- } from './Select/NumberSelectGroup';
120
-
121
- export type { SelectGroupPropsHelper } from './Select/SelectGroupPropsHelper';
122
-
123
- export {
124
- MultiStringSelectGroup,
125
- SingleStringSelectGroup,
126
- } from './Select/StringSelectGroup';
127
- export type {
128
- MultiStringSelectGroupProps,
129
- SingleStringSelectGroupProps,
130
- } from './Select/StringSelectGroup';
131
-
132
- // Text Area
133
-
134
- export { default as TextAreaGroup } from './TextArea/TextAreaGroup';
135
-
136
- export type { TextAreaGroupProps } from './TextArea/TextAreaGroup';
137
-
138
- // Utils
139
- export { default as objectContainsNonSerializableProperty } from './utils/objectContainsNonSerializableProperty';
140
-
141
- export { default as serialize } from './utils/objectToFormData';
142
- export type { ObjectToFormDataCfgProps } from './utils/objectToFormData';
143
-
144
- export * from './utils/typeChecks';
145
-
146
- // Validation
147
- export type { ValidatedApiResult } from './Validation/ValidatedApiResult';
148
-
149
- export type { ValidationError } from './Validation/ValidationError';
150
-
151
- export type { ValidationFunction } from './Validation/ValidationFunction';
152
-
153
- export * as validators from './Validation/validators';
1
+ // Address
2
+ export { default as AddressInput } from './AddressInput/AddressInput';
3
+ export type { AddressInputProps } from './AddressInput/AddressInput';
4
+
5
+ // Button
6
+ export { default as SubmitFormButton } from './SubmitFormButton';
7
+ export type { SubmitFormButtonProps } from './SubmitFormButton';
8
+
9
+ // ConfirmBaseForm
10
+ export { default as ConfirmBaseForm } from './ConfirmBaseForm/ConfirmBaseForm';
11
+ export type { ConfirmBaseFormProps } from './ConfirmBaseForm/ConfirmBaseForm';
12
+
13
+ // ConfirmDeleteForm
14
+ export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteForm';
15
+ export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteForm';
16
+
17
+ // Date
18
+ export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
19
+ export type { DatePickerGroupProps } from './DatePicker/DatePickerGroup';
20
+ export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
21
+
22
+ export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
23
+
24
+ export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
25
+ export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGroup';
26
+
27
+ export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
28
+ export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
29
+
30
+ // Field
31
+ export { default as Field } from './Field/Field';
32
+ export type { FieldProps } from './Field/Field';
33
+
34
+ export type { RenderComponent } from './Field/Field';
35
+ export type { RenderComponentProps } from './Field/Field';
36
+
37
+ export { default as FieldErrorScrollTarget } from './Field/FieldErrorScrollTarget';
38
+
39
+ export { FieldNameContext } from './Field/FieldNameContext';
40
+
41
+ export type { InjectedFieldProps } from './Field/InjectedFieldProps';
42
+
43
+ export { default as StandAloneInput } from './Field/StandAloneInput';
44
+
45
+ export type { StandAloneInputProps } from './Field/StandAloneInput';
46
+
47
+ export { default as useStandardField } from './Field/useStandardField';
48
+ export type { useStandardFieldProps } from './Field/useStandardField';
49
+
50
+ // Field Array
51
+ export { default as FieldArray } from './FieldArray/FieldArray';
52
+ export type {
53
+ FieldArrayProps,
54
+ ArrayFormBuilderProp,
55
+ } from './FieldArray/FieldArray';
56
+
57
+ // File
58
+ export { default as FileGroup } from './File/FileGroup';
59
+ export type { FileGroupProps } from './File/FileGroup';
60
+
61
+ // Form
62
+ export { default as Form } from './Form/Form';
63
+ export type { FormBuilderProp, FormProps } from './Form/Form';
64
+ export { ServerErrorContext } from './Form/ServerErrorContext';
65
+ export type {
66
+ ServerErrorContextProps,
67
+ ServerErrors,
68
+ } from './Form/ServerErrorContext';
69
+
70
+ export { default as FormActions } from './FormActions';
71
+ export type { FormActionsProps } from './FormActions';
72
+
73
+ export { default as StandardFormActions } from './StandardFormActions';
74
+ export type { StandardFormActionsProps } from './StandardFormActions';
75
+
76
+ // FormDefaults
77
+ export { FormDefaults } from './FormDefaults';
78
+
79
+ // Input
80
+ export { default as Group } from './Group';
81
+ export type { GroupProps } from './Group';
82
+
83
+ export { default as IconInputGroup } from './Input/IconInputGroup';
84
+ export type { IconInputGroupProps } from './Input/IconInputGroup';
85
+
86
+ export { default as InputGroup } from './Input/InputGroup';
87
+ export type { InputGroupProps } from './Input/InputGroup';
88
+
89
+ export { default as MoneyInputGroup } from './Input/MoneyInputGroup';
90
+ export type { MoneyInputGroupProps } from './Input/MoneyInputGroup';
91
+
92
+ export { default as NumberInputGroup } from './Input/NumberInputGroup';
93
+ export type { NumberInputGroupProps } from './Input/NumberInputGroup';
94
+
95
+ export { default as PhoneNumberInputGroup } from './Input/PhoneNumberInputGroup';
96
+ export type { PhoneNumberInputGroupProps } from './Input/PhoneNumberInputGroup';
97
+
98
+ export { default as StringInputGroup } from './Input/StringInputGroup';
99
+ export type { StringInputGroupProps } from './Input/StringInputGroup';
100
+
101
+ // Normalization
102
+ export type { NormalizationFunction } from './Normalization/NormalizationFunction';
103
+ export * as normalizers from './Normalization/normalizers';
104
+
105
+ // Select
106
+ export { default as SelectGroup } from './Select/SelectGroup';
107
+ export type { SelectGroupProps, SelectOption } from './Select/SelectGroup';
108
+
109
+ export { BooleanSelectGroup } from './Select/BooleanSelectGroup';
110
+ export type { BooleanSelectGroupProps } from './Select/BooleanSelectGroup';
111
+
112
+ export { default as CheckboxInputGroup } from './Input/CheckboxInputGroup';
113
+ export type { CheckboxInputGroupProps } from './Input/CheckboxInputGroup';
114
+
115
+ export {
116
+ MultiNumberSelectGroup,
117
+ SingleNumberSelectGroup,
118
+ } from './Select/NumberSelectGroup';
119
+ export type {
120
+ MultiNumberSelectGroupProps,
121
+ SingleNumberSelectGroupProps,
122
+ } from './Select/NumberSelectGroup';
123
+
124
+ export type { SelectGroupPropsHelper } from './Select/SelectGroupPropsHelper';
125
+
126
+ export {
127
+ MultiStringSelectGroup,
128
+ SingleStringSelectGroup,
129
+ } from './Select/StringSelectGroup';
130
+ export type {
131
+ MultiStringSelectGroupProps,
132
+ SingleStringSelectGroupProps,
133
+ } from './Select/StringSelectGroup';
134
+
135
+ // Text Area
136
+
137
+ export { default as TextAreaGroup } from './TextArea/TextAreaGroup';
138
+
139
+ export type { TextAreaGroupProps } from './TextArea/TextAreaGroup';
140
+
141
+ // Utils
142
+ export { default as objectContainsNonSerializableProperty } from './utils/objectContainsNonSerializableProperty';
143
+
144
+ export { default as serialize } from './utils/objectToFormData';
145
+ export type { ObjectToFormDataCfgProps } from './utils/objectToFormData';
146
+
147
+ export * from './utils/typeChecks';
148
+
149
+ // Validation
150
+ export type { ValidatedApiResult } from './Validation/ValidatedApiResult';
151
+
152
+ export type { ValidationError } from './Validation/ValidationError';
153
+
154
+ export type { ValidationFunction } from './Validation/ValidationFunction';
155
+
156
+ export * as validators from './Validation/validators';
@@ -1 +1 @@
1
- /// <reference types="react-scripts" />
1
+ /// <reference types="react-scripts" />
package/src/setupTests.ts CHANGED
@@ -1 +1 @@
1
- import '@testing-library/jest-dom/extend-expect';
1
+ import '@testing-library/jest-dom/extend-expect';
@@ -1,49 +1,49 @@
1
- import check from './objectContainsNonSerializableProperty';
2
-
3
- describe('Object contains non serializable property checker', () => {
4
- it('Should return true for simple object', () => {
5
- const object = {
6
- name: 'Bob',
7
- age: 20,
8
- favoriteFoods: ['Hamburger', 'Pizza'],
9
- homeAddress: {
10
- addressLine1: '12345 Test Place',
11
- addressLine2: null,
12
- city: 'SomePlace',
13
- state: 'LA',
14
- zip: 12345,
15
- },
16
- };
17
-
18
- const result = check(object);
19
- expect(result).toBe(false);
20
- });
21
-
22
- it('Should return false for direct file property', () => {
23
- const object = {
24
- name: 'Bob',
25
- age: 20,
26
- profilePhoto: new File(['foo'], 'foo.txt', {
27
- type: 'text/plain',
28
- }),
29
- };
30
-
31
- const result = check(object);
32
- expect(result).toBe(true);
33
- });
34
-
35
- it('Should return false for deeply nested file property', () => {
36
- const object = {
37
- a: {
38
- b: {
39
- c: new File(['foo'], 'foo.txt', {
40
- type: 'text/plain',
41
- }),
42
- },
43
- },
44
- };
45
-
46
- const result = check(object);
47
- expect(result).toBe(true);
48
- });
49
- });
1
+ import check from './objectContainsNonSerializableProperty';
2
+
3
+ describe('Object contains non serializable property checker', () => {
4
+ it('Should return true for simple object', () => {
5
+ const object = {
6
+ name: 'Bob',
7
+ age: 20,
8
+ favoriteFoods: ['Hamburger', 'Pizza'],
9
+ homeAddress: {
10
+ addressLine1: '12345 Test Place',
11
+ addressLine2: null,
12
+ city: 'SomePlace',
13
+ state: 'LA',
14
+ zip: 12345,
15
+ },
16
+ };
17
+
18
+ const result = check(object);
19
+ expect(result).toBe(false);
20
+ });
21
+
22
+ it('Should return false for direct file property', () => {
23
+ const object = {
24
+ name: 'Bob',
25
+ age: 20,
26
+ profilePhoto: new File(['foo'], 'foo.txt', {
27
+ type: 'text/plain',
28
+ }),
29
+ };
30
+
31
+ const result = check(object);
32
+ expect(result).toBe(true);
33
+ });
34
+
35
+ it('Should return false for deeply nested file property', () => {
36
+ const object = {
37
+ a: {
38
+ b: {
39
+ c: new File(['foo'], 'foo.txt', {
40
+ type: 'text/plain',
41
+ }),
42
+ },
43
+ },
44
+ };
45
+
46
+ const result = check(object);
47
+ expect(result).toBe(true);
48
+ });
49
+ });
@@ -1,17 +1,17 @@
1
- import { isBlob, isFile, isObject } from './typeChecks';
2
-
3
- export default function objectContainsNonSerializableProperty(
4
- object: any
5
- ): boolean {
6
- return Object.entries(object).some((value) => {
7
- if (value) {
8
- if (isBlob(value[1]) || isFile(value[1])) {
9
- return true;
10
- }
11
- if (isObject(value[1])) {
12
- return objectContainsNonSerializableProperty(value[1]);
13
- }
14
- }
15
- return false;
16
- });
17
- }
1
+ import { isBlob, isFile, isObject } from './typeChecks';
2
+
3
+ export default function objectContainsNonSerializableProperty(
4
+ object: any
5
+ ): boolean {
6
+ return Object.entries(object).some((value) => {
7
+ if (value) {
8
+ if (isBlob(value[1]) || isFile(value[1])) {
9
+ return true;
10
+ }
11
+ if (isObject(value[1])) {
12
+ return objectContainsNonSerializableProperty(value[1]);
13
+ }
14
+ }
15
+ return false;
16
+ });
17
+ }
@@ -1,76 +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) as any;
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
- });
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) as any;
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
+ });