envoc-form 5.0.2 → 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.
- package/README.md +158 -15
- package/es/Input/CheckboxGroup.d.ts +6 -0
- package/es/Input/CheckboxGroup.js +14 -0
- package/es/Input/CheckboxInputGroup.d.ts +13 -0
- package/es/Input/CheckboxInputGroup.js +41 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +1 -0
- package/lib/Input/CheckboxGroup.d.ts +6 -0
- package/lib/Input/CheckboxGroup.js +20 -0
- package/lib/Input/CheckboxInputGroup.d.ts +13 -0
- package/lib/Input/CheckboxInputGroup.js +46 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/package.json +111 -111
- package/src/AddressInput/AddressInput.test.tsx +27 -27
- package/src/AddressInput/AddressInput.tsx +82 -82
- package/src/AddressInput/UsStates.ts +55 -55
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +182 -182
- package/src/ConfirmBaseForm/ConfirmBaseForm.test.tsx +24 -24
- package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +74 -74
- package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +23 -23
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.tsx +24 -24
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +87 -87
- package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +25 -25
- package/src/DatePicker/DatePicker.test.tsx +48 -48
- package/src/DatePicker/DatePickerGroup.tsx +115 -115
- package/src/DatePicker/DatePickerHelper.ts +4 -4
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +28 -28
- package/src/DatePicker/StringDatePickerGroup.tsx +20 -20
- package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +152 -152
- package/src/Field/CustomFieldInputProps.ts +10 -10
- package/src/Field/CustomFieldMetaProps.ts +5 -5
- package/src/Field/Field.tsx +113 -113
- package/src/Field/FieldErrorScrollTarget.tsx +12 -12
- package/src/Field/FieldNameContext.ts +6 -6
- package/src/Field/FieldSection.tsx +18 -18
- package/src/Field/InjectedFieldProps.ts +8 -8
- package/src/Field/StandAloneInput.tsx +55 -55
- package/src/Field/useStandardField.ts +125 -125
- package/src/FieldArray/FieldArray.tsx +154 -154
- package/src/File/FileGroup.test.tsx +35 -35
- package/src/File/FileGroup.tsx +85 -85
- package/src/File/FileList.tsx +21 -21
- package/src/File/__snapshots__/FileGroup.test.tsx.snap +34 -34
- package/src/File/humanFileSize.ts +8 -8
- package/src/Form/FocusError.tsx +55 -55
- package/src/Form/Form.test.tsx +14 -14
- package/src/Form/Form.tsx +237 -237
- package/src/Form/FormBasedPreventNavigation.tsx +56 -56
- package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -77
- package/src/Form/NewFormBasedPreventNavigation.tsx +59 -59
- package/src/Form/ServerErrorContext.ts +18 -18
- package/src/Form/__snapshots__/Form.test.tsx.snap +10 -10
- package/src/FormActions.tsx +47 -47
- package/src/FormDefaults.ts +2 -2
- package/src/Group.tsx +62 -62
- package/src/Input/CheckboxGroup.tsx +60 -0
- package/src/Input/CheckboxInputGroup.tsx +78 -0
- package/src/Input/IconInputGroup.tsx +54 -54
- package/src/Input/InputGroup.tsx +72 -72
- package/src/Input/MoneyInputGroup.tsx +50 -50
- package/src/Input/NumberInputGroup.tsx +48 -48
- package/src/Input/PhoneNumberInputGroup.tsx +45 -45
- package/src/Input/StringInputGroup.tsx +53 -53
- package/src/Input/__Tests__/CheckboxInputGroup.test.tsx +26 -0
- package/src/Input/__Tests__/IconInputGroup.test.tsx +35 -35
- package/src/Input/__Tests__/MoneyInputGroup.test.tsx +37 -37
- package/src/Input/__Tests__/NumberInputGroup.test.tsx +35 -35
- package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +36 -36
- package/src/Input/__Tests__/StringInputGroup.test.tsx +27 -27
- package/src/Input/__Tests__/__snapshots__/CheckboxInputGroup.test.tsx.snap +33 -0
- package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +32 -32
- package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +34 -34
- package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +32 -32
- package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -33
- package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +31 -31
- package/src/Normalization/NormalizationFunction.ts +4 -4
- package/src/Normalization/normalizers.ts +44 -44
- package/src/Select/BooleanSelectGroup.tsx +28 -28
- package/src/Select/NumberSelectGroup.tsx +16 -16
- package/src/Select/SelectGroup.tsx +124 -124
- package/src/Select/SelectGroupPropsHelper.ts +4 -4
- package/src/Select/StringSelectGroup.tsx +16 -16
- package/src/Select/__tests__/BooleanSelectGroup.test.tsx +35 -35
- package/src/Select/__tests__/NumberSelectGroup.test.tsx +87 -87
- package/src/Select/__tests__/StringSelectGroup.test.tsx +89 -89
- package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +98 -98
- package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +195 -195
- package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +195 -195
- package/src/StandardFormActions.tsx +41 -41
- package/src/SubmitFormButton.tsx +54 -54
- package/src/TextArea/TextAreaGroup.tsx +64 -64
- package/src/Validation/ValidatedApiResult.ts +8 -8
- package/src/Validation/ValidationError.ts +6 -6
- package/src/Validation/ValidationFunction.ts +4 -4
- package/src/Validation/validators.test.tsx +81 -81
- package/src/Validation/validators.ts +97 -97
- package/src/__Tests__/FormTestBase.tsx +65 -64
- package/src/__Tests__/RealisticForm.test.tsx +82 -82
- package/src/__Tests__/StandardFormActions.test.tsx +17 -17
- package/src/__Tests__/SubmitFormButton.test.tsx +17 -17
- package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +27 -27
- package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +20 -20
- package/src/__Tests__/index.ts +3 -3
- package/src/_variables.scss +11 -11
- package/src/index.ts +156 -153
- package/src/react-app-env.d.ts +1 -1
- package/src/setupTests.ts +1 -1
- package/src/utils/objectContainsNonSerializableProperty.test.tsx +49 -49
- package/src/utils/objectContainsNonSerializableProperty.ts +17 -17
- package/src/utils/objectToFormData.test.tsx +76 -76
- package/src/utils/objectToFormData.ts +105 -105
- 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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
export {
|
140
|
-
|
141
|
-
|
142
|
-
export
|
143
|
-
|
144
|
-
export
|
145
|
-
|
146
|
-
|
147
|
-
export
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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';
|
package/src/react-app-env.d.ts
CHANGED
@@ -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
|
+
});
|