@shopgate/pwa-ui-shared 7.30.0-alpha.7 → 7.30.0-alpha.8
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/AccordionContainer/index.js +39 -5
- package/AccordionContainer/spec.js +25 -2
- package/ActionButton/index.js +63 -7
- package/ActionButton/spec.js +59 -2
- package/ActionButton/style.js +22 -1
- package/AddToCartButton/index.js +184 -27
- package/AddToCartButton/mock.js +18 -4
- package/AddToCartButton/spec.js +51 -2
- package/AddToCartButton/style.js +127 -11
- package/Availability/index.js +34 -2
- package/Availability/spec.js +41 -1
- package/Availability/style.js +19 -1
- package/Button/index.js +76 -5
- package/Button/spec.js +33 -1
- package/Button/style.js +130 -21
- package/ButtonLink/connector.js +11 -2
- package/ButtonLink/index.js +44 -6
- package/ButtonLink/spec.js +23 -1
- package/Card/index.js +19 -2
- package/Card/style.js +11 -1
- package/CardList/components/Item/index.js +26 -2
- package/CardList/components/Item/style.js +7 -1
- package/CardList/index.js +34 -3
- package/CartTotalLine/components/Amount/index.js +28 -2
- package/CartTotalLine/components/Amount/style.js +8 -1
- package/CartTotalLine/components/Hint/index.js +23 -2
- package/CartTotalLine/components/Hint/style.js +12 -1
- package/CartTotalLine/components/Label/index.js +36 -2
- package/CartTotalLine/components/Label/style.js +17 -1
- package/CartTotalLine/components/Spacer/index.js +16 -2
- package/CartTotalLine/index.js +39 -2
- package/CartTotalLine/style.js +31 -1
- package/Checkbox/index.js +31 -2
- package/Checkbox/style.js +18 -1
- package/Chip/index.js +61 -2
- package/Chip/spec.js +24 -1
- package/Chip/style.js +71 -3
- package/ContextMenu/ContextMenu.hooks.js +6 -2
- package/ContextMenu/ContextMenuProvider.context.js +9 -3
- package/ContextMenu/ContextMenuProvider.js +21 -2
- package/ContextMenu/components/Item/index.js +67 -5
- package/ContextMenu/components/Item/style.js +32 -3
- package/ContextMenu/components/Position/index.js +61 -10
- package/ContextMenu/components/Position/style.js +11 -1
- package/ContextMenu/index.js +124 -3
- package/ContextMenu/spec.js +101 -2
- package/ContextMenu/style.js +45 -1
- package/Dialog/components/BasicDialog/index.js +5 -1
- package/Dialog/components/HtmlContentDialog/index.js +22 -2
- package/Dialog/components/HtmlContentDialog/spec.js +59 -1
- package/Dialog/components/PipelineErrorDialog/index.js +114 -25
- package/Dialog/components/PipelineErrorDialog/spec.js +92 -12
- package/Dialog/components/TextMessageDialog/index.js +28 -2
- package/Dialog/components/TextMessageDialog/spec.js +59 -1
- package/Dialog/components/VariantSelectModal/connector.js +11 -2
- package/Dialog/components/VariantSelectModal/index.js +65 -6
- package/Dialog/components/VariantSelectModal/spec.js +51 -2
- package/Dialog/constants.js +6 -1
- package/Dialog/index.js +114 -7
- package/Dialog/spec.js +81 -3
- package/DiscountBadge/index.js +30 -2
- package/DiscountBadge/spec.js +19 -1
- package/DiscountBadge/style.js +34 -2
- package/FavoritesButton/connector.js +18 -3
- package/FavoritesButton/index.js +118 -15
- package/FavoritesButton/mock.js +50 -4
- package/FavoritesButton/spec.js +120 -2
- package/FavoritesButton/style.js +26 -1
- package/Form/Builder/builders/buildCountryList.js +40 -6
- package/Form/Builder/builders/buildFormDefaults.js +35 -6
- package/Form/Builder/builders/buildFormElements.js +68 -10
- package/Form/Builder/builders/buildProvinceList.js +19 -2
- package/Form/Builder/builders/buildValidationErrorList.js +7 -2
- package/Form/Builder/classes/ActionListener/constants.js +22 -2
- package/Form/Builder/classes/ActionListener/index.js +441 -93
- package/Form/Builder/classes/ActionListener/spec.js +321 -19
- package/Form/Builder/components/CheckboxElement.js +35 -3
- package/Form/Builder/components/CountryElement.js +40 -3
- package/Form/Builder/components/ProvinceElement.js +40 -3
- package/Form/Builder/components/RadioElement.js +41 -3
- package/Form/Builder/components/SelectElement.js +39 -3
- package/Form/Builder/components/TextElement.js +49 -4
- package/Form/Builder/elementTypes.js +11 -1
- package/Form/Builder/index.js +298 -52
- package/Form/Builder/iso-3166-2.js +4943 -1
- package/Form/Builder/spec.js +300 -16
- package/Form/Checkbox/index.js +66 -4
- package/Form/Checkbox/style.js +25 -2
- package/Form/InfoField/index.js +50 -2
- package/Form/InfoField/spec.js +9 -1
- package/Form/InfoField/style.js +11 -1
- package/Form/Password/index.js +51 -6
- package/Form/Password/spec.js +34 -1
- package/Form/Password/style.js +11 -1
- package/Form/RadioGroup/components/Item/index.js +59 -3
- package/Form/RadioGroup/components/Item/style.js +32 -2
- package/Form/RadioGroup/index.js +101 -9
- package/Form/RadioGroup/spec.js +83 -3
- package/Form/RadioGroup/style.js +18 -2
- package/Form/Select/index.js +158 -10
- package/Form/Select/spec.js +36 -5
- package/Form/Select/style.js +27 -1
- package/Form/SelectContextChoices/index.js +77 -3
- package/Form/SelectContextChoices/spec.js +33 -4
- package/Form/SelectContextChoices/style.js +23 -1
- package/Form/TextField/index.js +92 -8
- package/Form/TextField/spec.js +110 -1
- package/Form/TextField/style.js +66 -8
- package/Form/index.js +54 -13
- package/FormElement/components/ErrorText/index.js +31 -2
- package/FormElement/components/ErrorText/style.js +13 -1
- package/FormElement/components/Label/index.js +35 -2
- package/FormElement/components/Label/style.js +76 -8
- package/FormElement/components/Placeholder/index.js +26 -2
- package/FormElement/components/Placeholder/style.js +48 -6
- package/FormElement/components/Underline/index.js +18 -2
- package/FormElement/components/Underline/style.js +51 -4
- package/FormElement/index.js +91 -6
- package/FormElement/spec.js +67 -2
- package/FormElement/style.js +13 -2
- package/Glow/index.js +90 -7
- package/Glow/spec.js +9 -1
- package/Glow/style.js +18 -1
- package/IndicatorCircle/index.js +33 -3
- package/IndicatorCircle/spec.js +28 -1
- package/IndicatorCircle/style.js +57 -3
- package/LoadingIndicator/index.js +29 -2
- package/LoadingIndicator/style.js +20 -1
- package/Manufacturer/index.js +20 -2
- package/Manufacturer/style.js +5 -1
- package/MessageBar/index.js +36 -2
- package/MessageBar/spec.js +79 -1
- package/MessageBar/style.js +38 -1
- package/NoResults/components/Icon/index.js +130 -2
- package/NoResults/components/Icon/style.js +17 -1
- package/NoResults/index.js +46 -2
- package/NoResults/style.js +31 -1
- package/Placeholder/index.js +25 -3
- package/Placeholder/style.js +11 -1
- package/PlaceholderLabel/index.js +27 -2
- package/PlaceholderLabel/spec.js +19 -1
- package/PlaceholderLabel/style.js +12 -1
- package/PlaceholderParagraph/index.js +36 -2
- package/PlaceholderParagraph/spec.js +19 -1
- package/Price/index.js +88 -7
- package/Price/style.js +22 -1
- package/PriceInfo/index.js +20 -2
- package/PriceInfo/style.js +5 -1
- package/PriceStriked/index.js +83 -12
- package/PriceStriked/style.js +33 -3
- package/ProductProperties/index.js +32 -2
- package/ProgressBar/index.js +101 -13
- package/ProgressBar/spec.js +13 -1
- package/ProgressBar/style.js +83 -2
- package/RadioButton/index.js +18 -2
- package/RadioButton/spec.js +21 -1
- package/RadioButton/style.js +21 -1
- package/RatingNumber/index.js +29 -2
- package/RatingStars/constants.js +2 -1
- package/RatingStars/index.js +130 -12
- package/RatingStars/spec.js +90 -3
- package/RatingStars/style.js +51 -2
- package/Ripple/components/RippleAnimation/index.js +88 -6
- package/Ripple/index.js +218 -40
- package/Ripple/style.js +18 -1
- package/RippleButton/index.js +52 -5
- package/RippleButton/spec.js +45 -1
- package/ScannerOverlay/components/CameraOverlay/index.js +13 -2
- package/ScannerOverlay/components/CameraOverlay/style.js +41 -1
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +34 -2
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/style.js +28 -1
- package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +11 -2
- package/ScannerOverlay/components/ScannerBar/index.js +31 -2
- package/ScannerOverlay/components/ScannerBar/style.js +20 -1
- package/ScannerOverlay/index.js +47 -7
- package/Sheet/components/Header/components/SearchBar/index.js +46 -2
- package/Sheet/components/Header/components/SearchBar/spec.js +21 -3
- package/Sheet/components/Header/components/SearchBar/style.js +47 -1
- package/Sheet/components/Header/index.js +75 -7
- package/Sheet/components/Header/spec.js +14 -1
- package/Sheet/components/Header/style.js +50 -1
- package/Sheet/index.js +170 -17
- package/Sheet/spec.js +85 -5
- package/Sheet/style.js +143 -2
- package/TaxDisclaimer/index.js +34 -4
- package/TaxDisclaimer/spec.js +31 -3
- package/TaxDisclaimer/style.js +9 -1
- package/TextField/components/ErrorText/index.js +33 -2
- package/TextField/components/ErrorText/style.js +25 -3
- package/TextField/components/FormElement/index.js +19 -2
- package/TextField/components/FormElement/style.js +32 -4
- package/TextField/components/Hint/index.js +21 -2
- package/TextField/components/Hint/style.js +40 -5
- package/TextField/components/Label/index.js +32 -3
- package/TextField/components/Label/style.js +68 -8
- package/TextField/components/Underline/index.js +19 -2
- package/TextField/components/Underline/style.js +51 -4
- package/TextField/index.js +189 -27
- package/TextField/spec.js +128 -3
- package/TextField/style.js +34 -4
- package/ToggleIcon/index.js +58 -8
- package/ToggleIcon/spec.js +35 -1
- package/icons/AccountBoxIcon.js +11 -2
- package/icons/AddMoreIcon.js +11 -2
- package/icons/ArrowDropIcon.js +11 -2
- package/icons/ArrowIcon.js +21 -2
- package/icons/BarcodeScannerIcon.js +11 -2
- package/icons/BoxIcon.js +11 -2
- package/icons/BrowseIcon.js +11 -2
- package/icons/BurgerIcon.js +11 -2
- package/icons/CalendarIcon.js +15 -3
- package/icons/CartCouponIcon.js +72 -2
- package/icons/CartIcon.js +11 -2
- package/icons/CartPlusIcon.js +11 -2
- package/icons/CheckIcon.js +11 -2
- package/icons/CheckedIcon.js +11 -2
- package/icons/ChevronIcon.js +11 -2
- package/icons/CreditCardIcon.js +11 -2
- package/icons/CrossIcon.js +11 -2
- package/icons/DescriptionIcon.js +11 -2
- package/icons/FilterIcon.js +11 -2
- package/icons/FlashDisabledIcon.js +11 -2
- package/icons/FlashEnabledIcon.js +11 -2
- package/icons/GridIcon.js +11 -2
- package/icons/HeartIcon.js +11 -2
- package/icons/HeartOutlineIcon.js +11 -2
- package/icons/HeartPlusIcon.js +12 -2
- package/icons/HeartPlusOutlineIcon.js +12 -2
- package/icons/HomeIcon.js +11 -2
- package/icons/InfoIcon.js +11 -2
- package/icons/InfoOutlineIcon.js +11 -2
- package/icons/ListIcon.js +11 -2
- package/icons/LocalShippingIcon.js +11 -2
- package/icons/LocationIcon.js +13 -3
- package/icons/LocatorIcon.js +11 -2
- package/icons/LockIcon.js +11 -2
- package/icons/LogoutIcon.js +11 -2
- package/icons/MagnifierIcon.js +11 -2
- package/icons/MapMarkerIcon.js +24 -3
- package/icons/MoreIcon.js +11 -2
- package/icons/MoreVertIcon.js +11 -2
- package/icons/NotificationIcon.js +14 -3
- package/icons/PersonIcon.js +12 -2
- package/icons/PhoneIcon.js +13 -3
- package/icons/PlaceholderIcon.js +11 -2
- package/icons/RadioCheckedIcon.js +11 -2
- package/icons/RadioUncheckedIcon.js +11 -2
- package/icons/SecurityIcon.js +11 -2
- package/icons/ShippingMethodIcon.js +18 -3
- package/icons/ShoppingCartIcon.js +11 -2
- package/icons/SortIcon.js +11 -2
- package/icons/StarHalfIcon.js +18 -2
- package/icons/StarIcon.js +18 -2
- package/icons/StarOutlineIcon.js +11 -2
- package/icons/StopIcon.js +11 -2
- package/icons/TickIcon.js +11 -2
- package/icons/TimeIcon.js +14 -3
- package/icons/TrashIcon.js +11 -2
- package/icons/TrashOutlineIcon.js +12 -2
- package/icons/UncheckedIcon.js +11 -2
- package/icons/ViewListIcon.js +11 -2
- package/icons/VisibilityIcon.js +11 -2
- package/icons/VisibilityOffIcon.js +11 -2
- package/icons/WarningIcon.js +11 -2
- package/index.js +13 -1
- package/package.json +5 -5
package/Form/Builder/spec.js
CHANGED
|
@@ -1,16 +1,300 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/* eslint-disable extra-rules/no-single-line-objects */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { mount } from 'enzyme';
|
|
4
|
+
import FormBuilder from '.';
|
|
5
|
+
describe('<FormBuilder />', () => {
|
|
6
|
+
it('should render empty form', () => {
|
|
7
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(FormBuilder, {
|
|
8
|
+
config: {
|
|
9
|
+
fields: {}
|
|
10
|
+
},
|
|
11
|
+
name: "foo",
|
|
12
|
+
handleUpdate: () => {}
|
|
13
|
+
}));
|
|
14
|
+
expect(wrapper).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
it('should render two text fields', () => {
|
|
17
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(FormBuilder, {
|
|
18
|
+
config: {
|
|
19
|
+
fields: {
|
|
20
|
+
firstName: {
|
|
21
|
+
label: 'foo',
|
|
22
|
+
type: 'text',
|
|
23
|
+
visible: true
|
|
24
|
+
},
|
|
25
|
+
lastName: {
|
|
26
|
+
label: 'bar',
|
|
27
|
+
type: 'text',
|
|
28
|
+
visible: true
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
name: "foo",
|
|
33
|
+
handleUpdate: () => {}
|
|
34
|
+
}));
|
|
35
|
+
expect(wrapper).toMatchSnapshot();
|
|
36
|
+
expect(wrapper.find('TextField').length).toEqual(2);
|
|
37
|
+
});
|
|
38
|
+
it('should not render invisible field', () => {
|
|
39
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(FormBuilder, {
|
|
40
|
+
config: {
|
|
41
|
+
fields: {
|
|
42
|
+
firstName: {
|
|
43
|
+
label: 'foo',
|
|
44
|
+
type: 'text',
|
|
45
|
+
visible: false
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
name: "foo",
|
|
50
|
+
handleUpdate: () => {}
|
|
51
|
+
}));
|
|
52
|
+
expect(wrapper).toMatchSnapshot();
|
|
53
|
+
expect(wrapper.find('TextField').length).toEqual(0);
|
|
54
|
+
});
|
|
55
|
+
it('should hide element if setVisibilty rule applies', () => {
|
|
56
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(FormBuilder, {
|
|
57
|
+
config: {
|
|
58
|
+
fields: {
|
|
59
|
+
foo: {
|
|
60
|
+
label: 'foo',
|
|
61
|
+
type: 'text',
|
|
62
|
+
visible: true
|
|
63
|
+
},
|
|
64
|
+
bar: {
|
|
65
|
+
label: 'bar',
|
|
66
|
+
type: 'text',
|
|
67
|
+
actions: [{
|
|
68
|
+
type: 'setVisibility',
|
|
69
|
+
rules: [{
|
|
70
|
+
context: 'foo',
|
|
71
|
+
type: 'notIn',
|
|
72
|
+
data: ['abc']
|
|
73
|
+
}]
|
|
74
|
+
}]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
name: "foo",
|
|
79
|
+
handleUpdate: () => {}
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
// Both should be visible at the beginning.
|
|
83
|
+
expect(wrapper).toMatchSnapshot();
|
|
84
|
+
expect(wrapper.find('TextField').length).toEqual(2);
|
|
85
|
+
|
|
86
|
+
// Simulate user input to the text field.
|
|
87
|
+
wrapper.find('input').first().simulate('change', {
|
|
88
|
+
target: {
|
|
89
|
+
value: 'abc'
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Second field should be hidden now.
|
|
94
|
+
expect(wrapper).toMatchSnapshot();
|
|
95
|
+
expect(wrapper.find('TextField').length).toEqual(1);
|
|
96
|
+
});
|
|
97
|
+
it('should reset value when rule applies', () => {
|
|
98
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(FormBuilder, {
|
|
99
|
+
config: {
|
|
100
|
+
fields: {
|
|
101
|
+
foo: {
|
|
102
|
+
label: 'foo',
|
|
103
|
+
type: 'text',
|
|
104
|
+
visible: true,
|
|
105
|
+
default: 'default'
|
|
106
|
+
},
|
|
107
|
+
bar: {
|
|
108
|
+
label: 'bar',
|
|
109
|
+
type: 'text',
|
|
110
|
+
default: 'default',
|
|
111
|
+
actions: [{
|
|
112
|
+
type: 'setValue',
|
|
113
|
+
params: {
|
|
114
|
+
value: 'cheat',
|
|
115
|
+
type: 'fixed'
|
|
116
|
+
},
|
|
117
|
+
rules: [{
|
|
118
|
+
context: 'foo',
|
|
119
|
+
type: 'notIn',
|
|
120
|
+
data: ['default']
|
|
121
|
+
}]
|
|
122
|
+
}]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
name: "foo",
|
|
127
|
+
handleUpdate: () => {}
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
// Default values should be in the inputs.
|
|
131
|
+
expect(wrapper).toMatchSnapshot();
|
|
132
|
+
expect(wrapper.find('TextField').length).toEqual(2);
|
|
133
|
+
expect(wrapper.find('input').at(0).props().value).toEqual('default');
|
|
134
|
+
expect(wrapper.find('input').at(1).props().value).toEqual('default');
|
|
135
|
+
|
|
136
|
+
// Simulate text input to trigger rule.
|
|
137
|
+
wrapper.find('input').first().simulate('change', {
|
|
138
|
+
target: {
|
|
139
|
+
value: 'abc'
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
wrapper.update();
|
|
143
|
+
|
|
144
|
+
// Second field should be hidden now.
|
|
145
|
+
expect(wrapper).toMatchSnapshot();
|
|
146
|
+
expect(wrapper.find('TextField').length).toEqual(2);
|
|
147
|
+
expect(wrapper.find('input').at(0).props().value).toEqual('abc');
|
|
148
|
+
expect(wrapper.find('input').at(1).props().value).toEqual('cheat');
|
|
149
|
+
});
|
|
150
|
+
it('should call onChange callback when input is changed', () => {
|
|
151
|
+
const handleUpdate = jest.fn();
|
|
152
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(FormBuilder, {
|
|
153
|
+
config: {
|
|
154
|
+
fields: {
|
|
155
|
+
foo: {
|
|
156
|
+
label: 'foo',
|
|
157
|
+
type: 'text',
|
|
158
|
+
visible: true,
|
|
159
|
+
default: 'default'
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
name: "foo",
|
|
164
|
+
id: "foo",
|
|
165
|
+
handleUpdate: handleUpdate
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
// Should call with initial state.
|
|
169
|
+
expect(wrapper).toMatchSnapshot();
|
|
170
|
+
expect(handleUpdate).toHaveBeenCalledWith({
|
|
171
|
+
foo: 'default'
|
|
172
|
+
}, false);
|
|
173
|
+
handleUpdate.mockClear();
|
|
174
|
+
|
|
175
|
+
// Update input
|
|
176
|
+
wrapper.find('input').first().simulate('change', {
|
|
177
|
+
target: {
|
|
178
|
+
value: 'abc'
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Should call with updated state.
|
|
183
|
+
expect(handleUpdate).toHaveBeenCalledWith({
|
|
184
|
+
foo: 'abc'
|
|
185
|
+
}, false);
|
|
186
|
+
});
|
|
187
|
+
describe('FormBuilder::elementChangeHandler', () => {
|
|
188
|
+
it('should take the updated state from action listener', () => {
|
|
189
|
+
// Create mocked Form builder.
|
|
190
|
+
const handleUpdate = jest.fn();
|
|
191
|
+
const builder = new FormBuilder({
|
|
192
|
+
validationErrors: [],
|
|
193
|
+
config: {
|
|
194
|
+
fields: {
|
|
195
|
+
foo: {
|
|
196
|
+
label: 'foo',
|
|
197
|
+
type: 'text',
|
|
198
|
+
visible: true,
|
|
199
|
+
default: 'default'
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
handleUpdate
|
|
204
|
+
});
|
|
205
|
+
builder.actionListener.notify = () => ({
|
|
206
|
+
formData: {
|
|
207
|
+
foo: 'bar'
|
|
208
|
+
},
|
|
209
|
+
errors: {},
|
|
210
|
+
elementVisibility: {
|
|
211
|
+
foo: true
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Trigger update
|
|
216
|
+
builder.elementChangeHandler('foo', 'bar');
|
|
217
|
+
|
|
218
|
+
// Test
|
|
219
|
+
expect(handleUpdate).toHaveBeenCalledWith({
|
|
220
|
+
foo: 'bar'
|
|
221
|
+
}, false);
|
|
222
|
+
});
|
|
223
|
+
it('should consider backend validations', () => {
|
|
224
|
+
// Create mocked Form builder.
|
|
225
|
+
const handleUpdate = jest.fn();
|
|
226
|
+
const builder = new FormBuilder({
|
|
227
|
+
validationErrors: [{}],
|
|
228
|
+
config: {
|
|
229
|
+
fields: {
|
|
230
|
+
foo: {
|
|
231
|
+
label: 'foo',
|
|
232
|
+
type: 'text',
|
|
233
|
+
visible: true,
|
|
234
|
+
default: 'default'
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
handleUpdate
|
|
239
|
+
});
|
|
240
|
+
builder.actionListener.notify = () => ({
|
|
241
|
+
formData: {
|
|
242
|
+
foo: 'bar'
|
|
243
|
+
},
|
|
244
|
+
errors: {},
|
|
245
|
+
elementVisibility: {
|
|
246
|
+
foo: true
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Trigger update
|
|
251
|
+
builder.elementChangeHandler('foo', 'bar');
|
|
252
|
+
|
|
253
|
+
// Test
|
|
254
|
+
expect(handleUpdate).toHaveBeenCalledWith({
|
|
255
|
+
foo: 'bar'
|
|
256
|
+
}, true);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
describe('FormBuilder::elementSortFunc', () => {
|
|
260
|
+
const builder = new FormBuilder({
|
|
261
|
+
validationErrors: [{}],
|
|
262
|
+
config: {
|
|
263
|
+
fields: {}
|
|
264
|
+
},
|
|
265
|
+
handleUpdate: jest.fn()
|
|
266
|
+
});
|
|
267
|
+
const field1 = {
|
|
268
|
+
id: 'foo',
|
|
269
|
+
label: 'foo'
|
|
270
|
+
};
|
|
271
|
+
const field2 = {
|
|
272
|
+
id: 'foo2',
|
|
273
|
+
label: 'foo2'
|
|
274
|
+
};
|
|
275
|
+
it('should keep sortOrder for undefined', () => {
|
|
276
|
+
expect([field2, field1].sort(builder.elementSortFunc)).toEqual([field2, field1]);
|
|
277
|
+
});
|
|
278
|
+
it('should sort elements', () => {
|
|
279
|
+
const fields = [{
|
|
280
|
+
...field1,
|
|
281
|
+
sortOrder: 2
|
|
282
|
+
}, {
|
|
283
|
+
...field2,
|
|
284
|
+
sortOrder: 1
|
|
285
|
+
}];
|
|
286
|
+
expect(fields.sort(builder.elementSortFunc)).toEqual(fields.reverse());
|
|
287
|
+
});
|
|
288
|
+
it('should keep sortOrder', () => {
|
|
289
|
+
const fields = [{
|
|
290
|
+
...field2,
|
|
291
|
+
sortOrder: 1
|
|
292
|
+
}, {
|
|
293
|
+
...field1,
|
|
294
|
+
sortOrder: 2
|
|
295
|
+
}];
|
|
296
|
+
expect(fields.sort(builder.elementSortFunc)).toEqual([...fields]);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
/* eslint-enable extra-rules/no-single-line-objects */
|
package/Form/Checkbox/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { PureComponent } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import I18n from '@shopgate/pwa-common/components/I18n';
|
|
6
|
+
import UICheckbox from '@shopgate/pwa-ui-shared/Checkbox';
|
|
7
|
+
import FormElement from '@shopgate/pwa-ui-shared/FormElement';
|
|
8
|
+
import style from "./style";
|
|
9
|
+
|
|
10
|
+
/**
|
|
2
11
|
* @typedef {Object} Props
|
|
3
12
|
* @property {string} label Label for the checkbox
|
|
4
13
|
* @property {string} name Name for the form element that's used as "htmlFor" attribute to create
|
|
@@ -11,10 +20,63 @@ var _excluded=["name","label","onChange","className","errorText","translateError
|
|
|
11
20
|
* @property {boolean} [showErrorText] Whether to show the error text when present (default `true`)
|
|
12
21
|
* @property {boolean} [translateErrorText] Whether `errorText` is a translation key
|
|
13
22
|
* @property {Function} [onChange] Change handler for the checkbox
|
|
14
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
15
26
|
* A component that provides a styled checkbox field.
|
|
16
27
|
* @extends {React.Component<Props>}
|
|
17
28
|
* @returns {JSX.Element}
|
|
18
|
-
*/
|
|
29
|
+
*/
|
|
30
|
+
class Checkbox extends PureComponent {
|
|
31
|
+
/**
|
|
19
32
|
* @return {JSX}
|
|
20
|
-
*/
|
|
33
|
+
*/
|
|
34
|
+
render() {
|
|
35
|
+
const {
|
|
36
|
+
name,
|
|
37
|
+
label,
|
|
38
|
+
onChange,
|
|
39
|
+
className,
|
|
40
|
+
errorText,
|
|
41
|
+
translateErrorText,
|
|
42
|
+
showErrorText,
|
|
43
|
+
checkboxClassName,
|
|
44
|
+
...restProps
|
|
45
|
+
} = this.props;
|
|
46
|
+
return /*#__PURE__*/React.createElement(FormElement, {
|
|
47
|
+
className: classNames(className, style.root, 'checkbox', 'ui-shared__form__checkbox'),
|
|
48
|
+
htmlFor: name,
|
|
49
|
+
errorText: errorText,
|
|
50
|
+
translateErrorText: translateErrorText,
|
|
51
|
+
hasUnderline: false,
|
|
52
|
+
hasPlaceholder: false,
|
|
53
|
+
disabled: restProps.disabled,
|
|
54
|
+
showErrorText: showErrorText
|
|
55
|
+
}, /*#__PURE__*/React.createElement(UICheckbox, _extends({}, restProps, {
|
|
56
|
+
className: checkboxClassName,
|
|
57
|
+
name: name,
|
|
58
|
+
onCheck: onChange,
|
|
59
|
+
checkedClassName: `${className} ${style.checked}`,
|
|
60
|
+
unCheckedClassName: className,
|
|
61
|
+
labelPosition: "right",
|
|
62
|
+
label: typeof label === 'string' ? /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
className: classNames(style.labelWrapper, 'label')
|
|
64
|
+
}, /*#__PURE__*/React.createElement(I18n.Text, {
|
|
65
|
+
className: style.label,
|
|
66
|
+
string: label
|
|
67
|
+
})) : label
|
|
68
|
+
})));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
Checkbox.defaultProps = {
|
|
72
|
+
className: '',
|
|
73
|
+
checkboxClassName: undefined,
|
|
74
|
+
defaultChecked: undefined,
|
|
75
|
+
errorText: '',
|
|
76
|
+
label: '',
|
|
77
|
+
onChange: () => {},
|
|
78
|
+
translateErrorText: true,
|
|
79
|
+
disabled: false,
|
|
80
|
+
showErrorText: true
|
|
81
|
+
};
|
|
82
|
+
export default Checkbox;
|
package/Form/Checkbox/style.js
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
2
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
const root = css({
|
|
4
|
+
marginLeft: -2,
|
|
5
|
+
// Removes margin caused by svg.
|
|
6
|
+
cursor: 'pointer',
|
|
7
|
+
'& svg': {
|
|
8
|
+
float: 'left'
|
|
9
|
+
}
|
|
10
|
+
}).toString();
|
|
11
|
+
const label = css({
|
|
12
|
+
lineHeight: 1.6
|
|
13
|
+
}).toString();
|
|
14
|
+
const labelWrapper = css({
|
|
15
|
+
marginLeft: themeConfig.variables.gap.xbig
|
|
16
|
+
}).toString();
|
|
17
|
+
const checked = css({
|
|
18
|
+
color: `var(--color-primary, ${themeConfig.colors.primary})`
|
|
19
|
+
}).toString();
|
|
20
|
+
export default {
|
|
21
|
+
root,
|
|
22
|
+
label,
|
|
23
|
+
labelWrapper,
|
|
24
|
+
checked
|
|
25
|
+
};
|
package/Form/InfoField/index.js
CHANGED
|
@@ -1,4 +1,52 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Grid from '@shopgate/pwa-common/components/Grid';
|
|
4
|
+
import FormElement from "../../FormElement";
|
|
5
|
+
import style from "./style";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* @param {Object} props .
|
|
3
9
|
* @returns {JSX}
|
|
4
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
const InfoField = props => {
|
|
12
|
+
const {
|
|
13
|
+
className,
|
|
14
|
+
label,
|
|
15
|
+
errorText,
|
|
16
|
+
leftElement,
|
|
17
|
+
rightElement,
|
|
18
|
+
hasUnderline,
|
|
19
|
+
children,
|
|
20
|
+
hasValue,
|
|
21
|
+
showErrorText
|
|
22
|
+
} = props;
|
|
23
|
+
return /*#__PURE__*/React.createElement(FormElement, {
|
|
24
|
+
className: className,
|
|
25
|
+
label: label,
|
|
26
|
+
errorText: errorText,
|
|
27
|
+
hasUnderline: hasUnderline,
|
|
28
|
+
isFocused: false,
|
|
29
|
+
hasValue: hasValue,
|
|
30
|
+
showErrorText: showErrorText
|
|
31
|
+
}, /*#__PURE__*/React.createElement(Grid, null, leftElement && /*#__PURE__*/React.createElement(Grid.Item, {
|
|
32
|
+
grow: 0,
|
|
33
|
+
className: style.element
|
|
34
|
+
}, leftElement), /*#__PURE__*/React.createElement(Grid.Item, {
|
|
35
|
+
grow: 1,
|
|
36
|
+
className: `${style.info} info-field`
|
|
37
|
+
}, children), rightElement && /*#__PURE__*/React.createElement(Grid.Item, {
|
|
38
|
+
grow: 0,
|
|
39
|
+
className: style.element
|
|
40
|
+
}, rightElement)));
|
|
41
|
+
};
|
|
42
|
+
InfoField.defaultProps = {
|
|
43
|
+
className: '',
|
|
44
|
+
errorText: '',
|
|
45
|
+
hasUnderline: true,
|
|
46
|
+
hasValue: false,
|
|
47
|
+
label: '',
|
|
48
|
+
leftElement: null,
|
|
49
|
+
rightElement: null,
|
|
50
|
+
showErrorText: true
|
|
51
|
+
};
|
|
52
|
+
export default InfoField;
|
package/Form/InfoField/spec.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import InfoField from "./index";
|
|
4
|
+
describe('<InfoField>', () => {
|
|
5
|
+
it('should render info field', () => {
|
|
6
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(InfoField, null, 'Some info text'));
|
|
7
|
+
expect(wrapper).toMatchSnapshot();
|
|
8
|
+
});
|
|
9
|
+
});
|
package/Form/InfoField/style.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
const info = css({
|
|
3
|
+
paddingTop: 24
|
|
4
|
+
}).toString();
|
|
5
|
+
const element = css({
|
|
6
|
+
marginTop: 16
|
|
7
|
+
}).toString();
|
|
8
|
+
export default {
|
|
9
|
+
info,
|
|
10
|
+
element
|
|
11
|
+
};
|
package/Form/Password/index.js
CHANGED
|
@@ -1,10 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import ToggleIcon from "../../ToggleIcon";
|
|
4
|
+
import VisibilityIcon from "../../icons/VisibilityIcon";
|
|
5
|
+
import VisibilityOffIcon from "../../icons/VisibilityOffIcon";
|
|
6
|
+
import TextField from "../TextField";
|
|
7
|
+
import style from "./style";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* A component that provides a password field with visibility toggle.
|
|
3
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
class Password extends Component {
|
|
13
|
+
/**
|
|
4
14
|
* Initializes the component.
|
|
5
15
|
* @param {Object} props The components props.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
*/
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
/**
|
|
20
|
+
* @param {boolean} isVisible The next isVisible state.
|
|
21
|
+
*/
|
|
22
|
+
this.togglePasswordVisibility = isVisible => {
|
|
23
|
+
this.setState({
|
|
24
|
+
isVisible
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
this.state = {
|
|
28
|
+
isVisible: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
9
32
|
* @return {*}
|
|
10
|
-
*/
|
|
33
|
+
*/
|
|
34
|
+
render() {
|
|
35
|
+
const {
|
|
36
|
+
isVisible
|
|
37
|
+
} = this.state;
|
|
38
|
+
return /*#__PURE__*/React.createElement(TextField, _extends({}, this.props, {
|
|
39
|
+
className: `ui-shared__form__password ${this.props.className}`,
|
|
40
|
+
rightElement: /*#__PURE__*/React.createElement(ToggleIcon, {
|
|
41
|
+
on: isVisible,
|
|
42
|
+
onIcon: /*#__PURE__*/React.createElement(VisibilityIcon, {
|
|
43
|
+
size: 24
|
|
44
|
+
}),
|
|
45
|
+
offIcon: /*#__PURE__*/React.createElement(VisibilityOffIcon, {
|
|
46
|
+
size: 24,
|
|
47
|
+
className: style.visOff
|
|
48
|
+
}),
|
|
49
|
+
toggleHandler: this.togglePasswordVisibility
|
|
50
|
+
}),
|
|
51
|
+
type: isVisible ? 'text' : 'password'
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default Password;
|
package/Form/Password/spec.js
CHANGED
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { mount } from 'enzyme';
|
|
4
|
+
import Password from "./index";
|
|
5
|
+
const inputProps = {
|
|
6
|
+
name: 'test-input'
|
|
7
|
+
};
|
|
8
|
+
describe('<Password>', () => {
|
|
9
|
+
it('should render a password field', () => {
|
|
10
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Password, inputProps));
|
|
11
|
+
expect(wrapper).toMatchSnapshot();
|
|
12
|
+
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
13
|
+
});
|
|
14
|
+
it('should trigger the onChange callback', () => {
|
|
15
|
+
const onChangeMock = jest.fn();
|
|
16
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Password, _extends({}, inputProps, {
|
|
17
|
+
onChange: onChangeMock
|
|
18
|
+
})));
|
|
19
|
+
wrapper.find('input').simulate('change', {
|
|
20
|
+
target: {
|
|
21
|
+
value: 'a'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
25
|
+
expect(wrapper.find('input').props().value).toEqual('a');
|
|
26
|
+
});
|
|
27
|
+
it('should toggle password visibility', () => {
|
|
28
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Password, inputProps));
|
|
29
|
+
const input = wrapper.find('ToggleIcon');
|
|
30
|
+
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
31
|
+
input.simulate('click');
|
|
32
|
+
expect(wrapper.find('input[type="text"]').length).toBe(1);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/Form/Password/style.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
const {
|
|
4
|
+
colors
|
|
5
|
+
} = themeConfig;
|
|
6
|
+
const visOff = css({
|
|
7
|
+
color: colors.shade4
|
|
8
|
+
}).toString();
|
|
9
|
+
export default {
|
|
10
|
+
visOff
|
|
11
|
+
};
|