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
@@ -1,182 +1,182 @@
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
-
|
3
|
-
exports[`AddressInput has matching snapshot 1`] = `
|
4
|
-
<DocumentFragment>
|
5
|
-
<form
|
6
|
-
action="#"
|
7
|
-
class="envoc-form-form"
|
8
|
-
>
|
9
|
-
<div
|
10
|
-
class="envoc-form-string-group envoc-form-input-group envoc-form-group envoc-form-required"
|
11
|
-
>
|
12
|
-
<div
|
13
|
-
id="normaladdressinput.address1-error-scroll-target"
|
14
|
-
style="display: none;"
|
15
|
-
/>
|
16
|
-
<label
|
17
|
-
for="normalAddressInput.address1"
|
18
|
-
>
|
19
|
-
Address 1
|
20
|
-
</label>
|
21
|
-
<input
|
22
|
-
aria-invalid="false"
|
23
|
-
class="envoc-form-string-group envoc-form-input-group"
|
24
|
-
id="normalAddressInput.address1"
|
25
|
-
name="normalAddressInput.address1"
|
26
|
-
placeholder="Address, Line 1"
|
27
|
-
value=""
|
28
|
-
/>
|
29
|
-
</div>
|
30
|
-
<div
|
31
|
-
class="envoc-form-string-group envoc-form-input-group envoc-form-group"
|
32
|
-
>
|
33
|
-
<div
|
34
|
-
id="normaladdressinput.address2-error-scroll-target"
|
35
|
-
style="display: none;"
|
36
|
-
/>
|
37
|
-
<label
|
38
|
-
for="normalAddressInput.address2"
|
39
|
-
>
|
40
|
-
Address 2
|
41
|
-
</label>
|
42
|
-
<input
|
43
|
-
aria-invalid="false"
|
44
|
-
class="envoc-form-string-group envoc-form-input-group"
|
45
|
-
id="normalAddressInput.address2"
|
46
|
-
name="normalAddressInput.address2"
|
47
|
-
placeholder="Address, Line 2"
|
48
|
-
value=""
|
49
|
-
/>
|
50
|
-
</div>
|
51
|
-
<div
|
52
|
-
class="envoc-form-string-group envoc-form-input-group envoc-form-group envoc-form-required"
|
53
|
-
>
|
54
|
-
<div
|
55
|
-
id="normaladdressinput.city-error-scroll-target"
|
56
|
-
style="display: none;"
|
57
|
-
/>
|
58
|
-
<label
|
59
|
-
for="normalAddressInput.city"
|
60
|
-
>
|
61
|
-
City
|
62
|
-
</label>
|
63
|
-
<input
|
64
|
-
aria-invalid="false"
|
65
|
-
class="envoc-form-string-group envoc-form-input-group"
|
66
|
-
id="normalAddressInput.city"
|
67
|
-
name="normalAddressInput.city"
|
68
|
-
placeholder="City"
|
69
|
-
value=""
|
70
|
-
/>
|
71
|
-
</div>
|
72
|
-
<div
|
73
|
-
class="envoc-form-select-group envoc-form-group envoc-form-required"
|
74
|
-
>
|
75
|
-
<div
|
76
|
-
id="normaladdressinput.state-error-scroll-target"
|
77
|
-
style="display: none;"
|
78
|
-
/>
|
79
|
-
<label
|
80
|
-
for="normalAddressInput.state"
|
81
|
-
>
|
82
|
-
State
|
83
|
-
</label>
|
84
|
-
<div
|
85
|
-
class="envoc-form-select-group css-b62m3t-container"
|
86
|
-
>
|
87
|
-
<span
|
88
|
-
class="css-1f43avz-a11yText-A11yText"
|
89
|
-
id="react-select-3-live-region"
|
90
|
-
/>
|
91
|
-
<span
|
92
|
-
aria-atomic="false"
|
93
|
-
aria-live="polite"
|
94
|
-
aria-relevant="additions text"
|
95
|
-
class="css-1f43avz-a11yText-A11yText"
|
96
|
-
/>
|
97
|
-
<div
|
98
|
-
class="react-select__control css-13cymwt-control"
|
99
|
-
>
|
100
|
-
<div
|
101
|
-
class="react-select__value-container css-16674sh-Component"
|
102
|
-
>
|
103
|
-
<div
|
104
|
-
class="react-select__placeholder css-1jqq78o-placeholder"
|
105
|
-
id="react-select-3-placeholder"
|
106
|
-
>
|
107
|
-
State
|
108
|
-
</div>
|
109
|
-
<div
|
110
|
-
class="react-select__input-container css-d9r47t-Component"
|
111
|
-
data-value=""
|
112
|
-
>
|
113
|
-
<input
|
114
|
-
aria-autocomplete="list"
|
115
|
-
aria-describedby="react-select-3-placeholder"
|
116
|
-
aria-expanded="false"
|
117
|
-
aria-haspopup="true"
|
118
|
-
autocapitalize="none"
|
119
|
-
autocomplete="off"
|
120
|
-
autocorrect="off"
|
121
|
-
class="react-select__input"
|
122
|
-
id="normalAddressInput.state"
|
123
|
-
role="combobox"
|
124
|
-
spellcheck="false"
|
125
|
-
style="opacity: 1; width: 100%; grid-area: 1 / 2; min-width: 2px; border: 0px; margin: 0px; outline: 0; padding: 0px;"
|
126
|
-
tabindex="0"
|
127
|
-
type="text"
|
128
|
-
value=""
|
129
|
-
/>
|
130
|
-
</div>
|
131
|
-
</div>
|
132
|
-
<div
|
133
|
-
class="react-select__indicators css-ny0e4k-Component"
|
134
|
-
>
|
135
|
-
<span
|
136
|
-
class="react-select__indicator-separator css-1u9des2-indicatorSeparator"
|
137
|
-
/>
|
138
|
-
<div
|
139
|
-
aria-hidden="true"
|
140
|
-
class="react-select__indicator react-select__dropdown-indicator css-1xc3v61-indicatorContainer"
|
141
|
-
>
|
142
|
-
<svg
|
143
|
-
aria-hidden="true"
|
144
|
-
class="css-tj5bde-Svg"
|
145
|
-
focusable="false"
|
146
|
-
height="20"
|
147
|
-
viewBox="0 0 20 20"
|
148
|
-
width="20"
|
149
|
-
>
|
150
|
-
<path
|
151
|
-
d="M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z"
|
152
|
-
/>
|
153
|
-
</svg>
|
154
|
-
</div>
|
155
|
-
</div>
|
156
|
-
</div>
|
157
|
-
</div>
|
158
|
-
</div>
|
159
|
-
<div
|
160
|
-
class="envoc-form-string-group envoc-form-input-group envoc-form-group envoc-form-required"
|
161
|
-
>
|
162
|
-
<div
|
163
|
-
id="normaladdressinput.zipcode-error-scroll-target"
|
164
|
-
style="display: none;"
|
165
|
-
/>
|
166
|
-
<label
|
167
|
-
for="normalAddressInput.zipCode"
|
168
|
-
>
|
169
|
-
Zip
|
170
|
-
</label>
|
171
|
-
<input
|
172
|
-
aria-invalid="false"
|
173
|
-
class="envoc-form-string-group envoc-form-input-group"
|
174
|
-
id="normalAddressInput.zipCode"
|
175
|
-
name="normalAddressInput.zipCode"
|
176
|
-
placeholder="Zip"
|
177
|
-
value=""
|
178
|
-
/>
|
179
|
-
</div>
|
180
|
-
</form>
|
181
|
-
</DocumentFragment>
|
182
|
-
`;
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`AddressInput has matching snapshot 1`] = `
|
4
|
+
<DocumentFragment>
|
5
|
+
<form
|
6
|
+
action="#"
|
7
|
+
class="envoc-form-form"
|
8
|
+
>
|
9
|
+
<div
|
10
|
+
class="envoc-form-string-group envoc-form-input-group envoc-form-group envoc-form-required"
|
11
|
+
>
|
12
|
+
<div
|
13
|
+
id="normaladdressinput.address1-error-scroll-target"
|
14
|
+
style="display: none;"
|
15
|
+
/>
|
16
|
+
<label
|
17
|
+
for="normalAddressInput.address1"
|
18
|
+
>
|
19
|
+
Address 1
|
20
|
+
</label>
|
21
|
+
<input
|
22
|
+
aria-invalid="false"
|
23
|
+
class="envoc-form-string-group envoc-form-input-group"
|
24
|
+
id="normalAddressInput.address1"
|
25
|
+
name="normalAddressInput.address1"
|
26
|
+
placeholder="Address, Line 1"
|
27
|
+
value=""
|
28
|
+
/>
|
29
|
+
</div>
|
30
|
+
<div
|
31
|
+
class="envoc-form-string-group envoc-form-input-group envoc-form-group"
|
32
|
+
>
|
33
|
+
<div
|
34
|
+
id="normaladdressinput.address2-error-scroll-target"
|
35
|
+
style="display: none;"
|
36
|
+
/>
|
37
|
+
<label
|
38
|
+
for="normalAddressInput.address2"
|
39
|
+
>
|
40
|
+
Address 2
|
41
|
+
</label>
|
42
|
+
<input
|
43
|
+
aria-invalid="false"
|
44
|
+
class="envoc-form-string-group envoc-form-input-group"
|
45
|
+
id="normalAddressInput.address2"
|
46
|
+
name="normalAddressInput.address2"
|
47
|
+
placeholder="Address, Line 2"
|
48
|
+
value=""
|
49
|
+
/>
|
50
|
+
</div>
|
51
|
+
<div
|
52
|
+
class="envoc-form-string-group envoc-form-input-group envoc-form-group envoc-form-required"
|
53
|
+
>
|
54
|
+
<div
|
55
|
+
id="normaladdressinput.city-error-scroll-target"
|
56
|
+
style="display: none;"
|
57
|
+
/>
|
58
|
+
<label
|
59
|
+
for="normalAddressInput.city"
|
60
|
+
>
|
61
|
+
City
|
62
|
+
</label>
|
63
|
+
<input
|
64
|
+
aria-invalid="false"
|
65
|
+
class="envoc-form-string-group envoc-form-input-group"
|
66
|
+
id="normalAddressInput.city"
|
67
|
+
name="normalAddressInput.city"
|
68
|
+
placeholder="City"
|
69
|
+
value=""
|
70
|
+
/>
|
71
|
+
</div>
|
72
|
+
<div
|
73
|
+
class="envoc-form-select-group envoc-form-group envoc-form-required"
|
74
|
+
>
|
75
|
+
<div
|
76
|
+
id="normaladdressinput.state-error-scroll-target"
|
77
|
+
style="display: none;"
|
78
|
+
/>
|
79
|
+
<label
|
80
|
+
for="normalAddressInput.state"
|
81
|
+
>
|
82
|
+
State
|
83
|
+
</label>
|
84
|
+
<div
|
85
|
+
class="envoc-form-select-group css-b62m3t-container"
|
86
|
+
>
|
87
|
+
<span
|
88
|
+
class="css-1f43avz-a11yText-A11yText"
|
89
|
+
id="react-select-3-live-region"
|
90
|
+
/>
|
91
|
+
<span
|
92
|
+
aria-atomic="false"
|
93
|
+
aria-live="polite"
|
94
|
+
aria-relevant="additions text"
|
95
|
+
class="css-1f43avz-a11yText-A11yText"
|
96
|
+
/>
|
97
|
+
<div
|
98
|
+
class="react-select__control css-13cymwt-control"
|
99
|
+
>
|
100
|
+
<div
|
101
|
+
class="react-select__value-container css-16674sh-Component"
|
102
|
+
>
|
103
|
+
<div
|
104
|
+
class="react-select__placeholder css-1jqq78o-placeholder"
|
105
|
+
id="react-select-3-placeholder"
|
106
|
+
>
|
107
|
+
State
|
108
|
+
</div>
|
109
|
+
<div
|
110
|
+
class="react-select__input-container css-d9r47t-Component"
|
111
|
+
data-value=""
|
112
|
+
>
|
113
|
+
<input
|
114
|
+
aria-autocomplete="list"
|
115
|
+
aria-describedby="react-select-3-placeholder"
|
116
|
+
aria-expanded="false"
|
117
|
+
aria-haspopup="true"
|
118
|
+
autocapitalize="none"
|
119
|
+
autocomplete="off"
|
120
|
+
autocorrect="off"
|
121
|
+
class="react-select__input"
|
122
|
+
id="normalAddressInput.state"
|
123
|
+
role="combobox"
|
124
|
+
spellcheck="false"
|
125
|
+
style="opacity: 1; width: 100%; grid-area: 1 / 2; min-width: 2px; border: 0px; margin: 0px; outline: 0; padding: 0px;"
|
126
|
+
tabindex="0"
|
127
|
+
type="text"
|
128
|
+
value=""
|
129
|
+
/>
|
130
|
+
</div>
|
131
|
+
</div>
|
132
|
+
<div
|
133
|
+
class="react-select__indicators css-ny0e4k-Component"
|
134
|
+
>
|
135
|
+
<span
|
136
|
+
class="react-select__indicator-separator css-1u9des2-indicatorSeparator"
|
137
|
+
/>
|
138
|
+
<div
|
139
|
+
aria-hidden="true"
|
140
|
+
class="react-select__indicator react-select__dropdown-indicator css-1xc3v61-indicatorContainer"
|
141
|
+
>
|
142
|
+
<svg
|
143
|
+
aria-hidden="true"
|
144
|
+
class="css-tj5bde-Svg"
|
145
|
+
focusable="false"
|
146
|
+
height="20"
|
147
|
+
viewBox="0 0 20 20"
|
148
|
+
width="20"
|
149
|
+
>
|
150
|
+
<path
|
151
|
+
d="M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z"
|
152
|
+
/>
|
153
|
+
</svg>
|
154
|
+
</div>
|
155
|
+
</div>
|
156
|
+
</div>
|
157
|
+
</div>
|
158
|
+
</div>
|
159
|
+
<div
|
160
|
+
class="envoc-form-string-group envoc-form-input-group envoc-form-group envoc-form-required"
|
161
|
+
>
|
162
|
+
<div
|
163
|
+
id="normaladdressinput.zipcode-error-scroll-target"
|
164
|
+
style="display: none;"
|
165
|
+
/>
|
166
|
+
<label
|
167
|
+
for="normalAddressInput.zipCode"
|
168
|
+
>
|
169
|
+
Zip
|
170
|
+
</label>
|
171
|
+
<input
|
172
|
+
aria-invalid="false"
|
173
|
+
class="envoc-form-string-group envoc-form-input-group"
|
174
|
+
id="normalAddressInput.zipCode"
|
175
|
+
name="normalAddressInput.zipCode"
|
176
|
+
placeholder="Zip"
|
177
|
+
value=""
|
178
|
+
/>
|
179
|
+
</div>
|
180
|
+
</form>
|
181
|
+
</DocumentFragment>
|
182
|
+
`;
|
@@ -1,24 +1,24 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { render } from '@testing-library/react';
|
3
|
-
import { useAxiosRequestProps } from 'envoc-request';
|
4
|
-
import ConfirmBaseForm from './ConfirmBaseForm';
|
5
|
-
|
6
|
-
describe('ConfirmBaseForm', () => {
|
7
|
-
it('Renders without error', () => {
|
8
|
-
render(<ConfirmBaseForm request={confirmBaseFormRequest} />);
|
9
|
-
});
|
10
|
-
|
11
|
-
it('has matching snapshot', () => {
|
12
|
-
const renderResult = render(
|
13
|
-
<ConfirmBaseForm request={confirmBaseFormRequest} />
|
14
|
-
);
|
15
|
-
expect(renderResult.asFragment()).toMatchSnapshot();
|
16
|
-
});
|
17
|
-
});
|
18
|
-
|
19
|
-
const confirmBaseFormRequest = {
|
20
|
-
method: 'get',
|
21
|
-
url: `/boop`,
|
22
|
-
onComplete: () => {},
|
23
|
-
onError: () => {},
|
24
|
-
} as useAxiosRequestProps;
|
1
|
+
import React from 'react';
|
2
|
+
import { render } from '@testing-library/react';
|
3
|
+
import { useAxiosRequestProps } from 'envoc-request';
|
4
|
+
import ConfirmBaseForm from './ConfirmBaseForm';
|
5
|
+
|
6
|
+
describe('ConfirmBaseForm', () => {
|
7
|
+
it('Renders without error', () => {
|
8
|
+
render(<ConfirmBaseForm request={confirmBaseFormRequest} />);
|
9
|
+
});
|
10
|
+
|
11
|
+
it('has matching snapshot', () => {
|
12
|
+
const renderResult = render(
|
13
|
+
<ConfirmBaseForm request={confirmBaseFormRequest} />
|
14
|
+
);
|
15
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
16
|
+
});
|
17
|
+
});
|
18
|
+
|
19
|
+
const confirmBaseFormRequest = {
|
20
|
+
method: 'get',
|
21
|
+
url: `/boop`,
|
22
|
+
onComplete: () => {},
|
23
|
+
onError: () => {},
|
24
|
+
} as useAxiosRequestProps;
|
@@ -1,74 +1,74 @@
|
|
1
|
-
import React, { MouseEventHandler } from 'react';
|
2
|
-
import classNames from 'classnames';
|
3
|
-
import { useAxiosRequest, useAxiosRequestProps } from 'envoc-request';
|
4
|
-
import { FormDefaults } from '../FormDefaults';
|
5
|
-
|
6
|
-
// TODO: change the style prop type to Tailwind type (does this exist before Tailwind 3.1 ???), or
|
7
|
-
// should this just be type 'string'
|
8
|
-
export interface ConfirmBaseFormProps {
|
9
|
-
/** Function to run when cancel button is clicked. */
|
10
|
-
handleCancel?: MouseEventHandler<HTMLButtonElement>;
|
11
|
-
/** Axios request upon confirmation */
|
12
|
-
request: useAxiosRequestProps;
|
13
|
-
style?: React.CSSProperties;
|
14
|
-
/** `<h3/>` title text on top of the form. */
|
15
|
-
title?: string;
|
16
|
-
/** Custom confirm button text.
|
17
|
-
* @defaultValue `Confirm`
|
18
|
-
*/
|
19
|
-
confirmButtonText?: string;
|
20
|
-
/** CSS class for the buttons. */
|
21
|
-
confirmButtonClass?: string;
|
22
|
-
/** Any components to be rendered in between the title and the buttons. */
|
23
|
-
children?: React.ReactNode;
|
24
|
-
}
|
25
|
-
|
26
|
-
// TODO: ask about how we should use 'children'
|
27
|
-
/**
|
28
|
-
* Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
|
29
|
-
* Commonly used for confirming delete and archive.
|
30
|
-
*
|
31
|
-
* See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
|
32
|
-
*/
|
33
|
-
export default function ConfirmBaseForm({
|
34
|
-
handleCancel,
|
35
|
-
request,
|
36
|
-
style,
|
37
|
-
title,
|
38
|
-
confirmButtonText,
|
39
|
-
confirmButtonClass,
|
40
|
-
children,
|
41
|
-
...props
|
42
|
-
}: ConfirmBaseFormProps) {
|
43
|
-
const webRequest = useAxiosRequest(
|
44
|
-
Object.assign({}, request, { autoExecute: false })
|
45
|
-
);
|
46
|
-
const onCancel = handleCancel ?? goBack;
|
47
|
-
|
48
|
-
return (
|
49
|
-
<div style={{ textAlign: 'center', ...style }} {...props}>
|
50
|
-
<h3>{title}</h3>
|
51
|
-
{children}
|
52
|
-
<button
|
53
|
-
className={classNames(
|
54
|
-
confirmButtonClass ??
|
55
|
-
FormDefaults.cssClassPrefix + 'confirm-base-form-confirm-button'
|
56
|
-
)}
|
57
|
-
type="button"
|
58
|
-
onClick={webRequest.submitRequest}>
|
59
|
-
{confirmButtonText ?? 'Confirm'}
|
60
|
-
</button>
|
61
|
-
<button
|
62
|
-
className={classNames(
|
63
|
-
FormDefaults.cssClassPrefix + 'confirm-base-form-cancel-button'
|
64
|
-
)}
|
65
|
-
type="button"
|
66
|
-
onClick={onCancel}>
|
67
|
-
Cancel
|
68
|
-
</button>
|
69
|
-
</div>
|
70
|
-
);
|
71
|
-
function goBack() {
|
72
|
-
window.history.back();
|
73
|
-
}
|
74
|
-
}
|
1
|
+
import React, { MouseEventHandler } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import { useAxiosRequest, useAxiosRequestProps } from 'envoc-request';
|
4
|
+
import { FormDefaults } from '../FormDefaults';
|
5
|
+
|
6
|
+
// TODO: change the style prop type to Tailwind type (does this exist before Tailwind 3.1 ???), or
|
7
|
+
// should this just be type 'string'
|
8
|
+
export interface ConfirmBaseFormProps {
|
9
|
+
/** Function to run when cancel button is clicked. */
|
10
|
+
handleCancel?: MouseEventHandler<HTMLButtonElement>;
|
11
|
+
/** Axios request upon confirmation */
|
12
|
+
request: useAxiosRequestProps;
|
13
|
+
style?: React.CSSProperties;
|
14
|
+
/** `<h3/>` title text on top of the form. */
|
15
|
+
title?: string;
|
16
|
+
/** Custom confirm button text.
|
17
|
+
* @defaultValue `Confirm`
|
18
|
+
*/
|
19
|
+
confirmButtonText?: string;
|
20
|
+
/** CSS class for the buttons. */
|
21
|
+
confirmButtonClass?: string;
|
22
|
+
/** Any components to be rendered in between the title and the buttons. */
|
23
|
+
children?: React.ReactNode;
|
24
|
+
}
|
25
|
+
|
26
|
+
// TODO: ask about how we should use 'children'
|
27
|
+
/**
|
28
|
+
* Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
|
29
|
+
* Commonly used for confirming delete and archive.
|
30
|
+
*
|
31
|
+
* See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
|
32
|
+
*/
|
33
|
+
export default function ConfirmBaseForm({
|
34
|
+
handleCancel,
|
35
|
+
request,
|
36
|
+
style,
|
37
|
+
title,
|
38
|
+
confirmButtonText,
|
39
|
+
confirmButtonClass,
|
40
|
+
children,
|
41
|
+
...props
|
42
|
+
}: ConfirmBaseFormProps) {
|
43
|
+
const webRequest = useAxiosRequest(
|
44
|
+
Object.assign({}, request, { autoExecute: false })
|
45
|
+
);
|
46
|
+
const onCancel = handleCancel ?? goBack;
|
47
|
+
|
48
|
+
return (
|
49
|
+
<div style={{ textAlign: 'center', ...style }} {...props}>
|
50
|
+
<h3>{title}</h3>
|
51
|
+
{children}
|
52
|
+
<button
|
53
|
+
className={classNames(
|
54
|
+
confirmButtonClass ??
|
55
|
+
FormDefaults.cssClassPrefix + 'confirm-base-form-confirm-button'
|
56
|
+
)}
|
57
|
+
type="button"
|
58
|
+
onClick={webRequest.submitRequest}>
|
59
|
+
{confirmButtonText ?? 'Confirm'}
|
60
|
+
</button>
|
61
|
+
<button
|
62
|
+
className={classNames(
|
63
|
+
FormDefaults.cssClassPrefix + 'confirm-base-form-cancel-button'
|
64
|
+
)}
|
65
|
+
type="button"
|
66
|
+
onClick={onCancel}>
|
67
|
+
Cancel
|
68
|
+
</button>
|
69
|
+
</div>
|
70
|
+
);
|
71
|
+
function goBack() {
|
72
|
+
window.history.back();
|
73
|
+
}
|
74
|
+
}
|
@@ -1,23 +1,23 @@
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
-
|
3
|
-
exports[`ConfirmBaseForm has matching snapshot 1`] = `
|
4
|
-
<DocumentFragment>
|
5
|
-
<div
|
6
|
-
style="text-align: center;"
|
7
|
-
>
|
8
|
-
<h3 />
|
9
|
-
<button
|
10
|
-
class="envoc-form-confirm-base-form-confirm-button"
|
11
|
-
type="button"
|
12
|
-
>
|
13
|
-
Confirm
|
14
|
-
</button>
|
15
|
-
<button
|
16
|
-
class="envoc-form-confirm-base-form-cancel-button"
|
17
|
-
type="button"
|
18
|
-
>
|
19
|
-
Cancel
|
20
|
-
</button>
|
21
|
-
</div>
|
22
|
-
</DocumentFragment>
|
23
|
-
`;
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`ConfirmBaseForm has matching snapshot 1`] = `
|
4
|
+
<DocumentFragment>
|
5
|
+
<div
|
6
|
+
style="text-align: center;"
|
7
|
+
>
|
8
|
+
<h3 />
|
9
|
+
<button
|
10
|
+
class="envoc-form-confirm-base-form-confirm-button"
|
11
|
+
type="button"
|
12
|
+
>
|
13
|
+
Confirm
|
14
|
+
</button>
|
15
|
+
<button
|
16
|
+
class="envoc-form-confirm-base-form-cancel-button"
|
17
|
+
type="button"
|
18
|
+
>
|
19
|
+
Cancel
|
20
|
+
</button>
|
21
|
+
</div>
|
22
|
+
</DocumentFragment>
|
23
|
+
`;
|
@@ -1,24 +1,24 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { HashRouter } from 'react-router-dom';
|
3
|
-
import { render } from '@testing-library/react';
|
4
|
-
|
5
|
-
import ConfirmDeleteForm from './ConfirmDeleteForm';
|
6
|
-
|
7
|
-
describe('ConfirmDeleteForm', () => {
|
8
|
-
it('Renders without error', () => {
|
9
|
-
render(
|
10
|
-
<HashRouter>
|
11
|
-
<ConfirmDeleteForm form="foo" />
|
12
|
-
</HashRouter>
|
13
|
-
);
|
14
|
-
});
|
15
|
-
|
16
|
-
it('has matching snapshot', () => {
|
17
|
-
const renderResult = render(
|
18
|
-
<HashRouter>
|
19
|
-
<ConfirmDeleteForm form="foo" />
|
20
|
-
</HashRouter>
|
21
|
-
);
|
22
|
-
expect(renderResult.asFragment()).toMatchSnapshot();
|
23
|
-
});
|
24
|
-
});
|
1
|
+
import React from 'react';
|
2
|
+
import { HashRouter } from 'react-router-dom';
|
3
|
+
import { render } from '@testing-library/react';
|
4
|
+
|
5
|
+
import ConfirmDeleteForm from './ConfirmDeleteForm';
|
6
|
+
|
7
|
+
describe('ConfirmDeleteForm', () => {
|
8
|
+
it('Renders without error', () => {
|
9
|
+
render(
|
10
|
+
<HashRouter>
|
11
|
+
<ConfirmDeleteForm form="foo" />
|
12
|
+
</HashRouter>
|
13
|
+
);
|
14
|
+
});
|
15
|
+
|
16
|
+
it('has matching snapshot', () => {
|
17
|
+
const renderResult = render(
|
18
|
+
<HashRouter>
|
19
|
+
<ConfirmDeleteForm form="foo" />
|
20
|
+
</HashRouter>
|
21
|
+
);
|
22
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
23
|
+
});
|
24
|
+
});
|