@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
|
@@ -1,21 +1,323 @@
|
|
|
1
|
-
|
|
1
|
+
import ActionListener from "./index";
|
|
2
|
+
import { ACTION_TYPE_SET_VISIBILITY, ACTION_TYPE_SET_VALUE, ACTION_TYPE_TRANSFORM, ACTION_SET_VALUE_COPY_FROM, ACTION_RULE_TYPE_ONE_OF } from "./constants";
|
|
3
|
+
jest.mock('@shopgate/pwa-core/helpers', () => ({
|
|
4
|
+
logger: {
|
|
5
|
+
error: () => {}
|
|
6
|
+
}
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* Mock for provinces
|
|
3
11
|
* @returns {{ST: string}}
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
*/
|
|
13
|
+
const mockGetProvincesList = () => ({
|
|
14
|
+
ST: 'State',
|
|
15
|
+
DF: 'Default-State'
|
|
16
|
+
});
|
|
17
|
+
describe('ActionListener', () => {
|
|
18
|
+
describe('createSetVisibilityHandler', () => {
|
|
19
|
+
it('should handle visibility changes correctly', () => {
|
|
20
|
+
// -------------------------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
const element = {
|
|
23
|
+
id: 'province'
|
|
24
|
+
};
|
|
25
|
+
const action = {
|
|
26
|
+
type: ACTION_TYPE_SET_VISIBILITY,
|
|
27
|
+
rules: [{
|
|
28
|
+
context: 'country',
|
|
29
|
+
type: ACTION_RULE_TYPE_ONE_OF,
|
|
30
|
+
data: ['US']
|
|
31
|
+
}]
|
|
32
|
+
};
|
|
33
|
+
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
34
|
+
const handler = actionListener.createSetVisibilityHandler(element, action);
|
|
35
|
+
let nextState;
|
|
36
|
+
let expected;
|
|
37
|
+
|
|
38
|
+
// Perform "make visible" test
|
|
39
|
+
nextState = {
|
|
40
|
+
formData: {
|
|
41
|
+
country: 'US'
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
expected = {
|
|
45
|
+
formData: {
|
|
46
|
+
country: 'US'
|
|
47
|
+
},
|
|
48
|
+
elementVisibility: {
|
|
49
|
+
province: true
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
expect(handler({}, nextState)).toEqual(expected);
|
|
53
|
+
|
|
54
|
+
// Perform "make invisible" test
|
|
55
|
+
nextState = {
|
|
56
|
+
formData: {
|
|
57
|
+
country: ''
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
expected = {
|
|
61
|
+
formData: {
|
|
62
|
+
country: ''
|
|
63
|
+
},
|
|
64
|
+
elementVisibility: {
|
|
65
|
+
province: false
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
expect(handler({}, nextState)).toEqual(expected);
|
|
69
|
+
});
|
|
70
|
+
it('should handle call follow up changes correctly when visibility changed', () => {
|
|
71
|
+
// -------------------------------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
const element = {
|
|
74
|
+
id: 'province'
|
|
75
|
+
};
|
|
76
|
+
const action = {
|
|
77
|
+
type: ACTION_TYPE_SET_VISIBILITY,
|
|
78
|
+
rules: [{
|
|
79
|
+
context: 'country',
|
|
80
|
+
type: ACTION_RULE_TYPE_ONE_OF,
|
|
81
|
+
data: ['US']
|
|
82
|
+
}]
|
|
83
|
+
};
|
|
84
|
+
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
85
|
+
const handleVisibility = actionListener.createSetVisibilityHandler(element, action);
|
|
86
|
+
|
|
87
|
+
// Province element is supposed to be hidden and therefore the follow up
|
|
88
|
+
const followUpHandler = jest.fn();
|
|
89
|
+
actionListener.register('province', followUpHandler);
|
|
90
|
+
const prevState = {
|
|
91
|
+
formData: {
|
|
92
|
+
province: 'to be changed'
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const nextStateBeforeVisibilityChange = {
|
|
96
|
+
formData: {
|
|
97
|
+
country: '',
|
|
98
|
+
province: 'to be changed'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const nextStateAfterVisibilityChange = {
|
|
102
|
+
elementVisibility: {
|
|
103
|
+
province: false
|
|
104
|
+
},
|
|
105
|
+
formData: {
|
|
106
|
+
country: ''
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
handleVisibility(prevState, nextStateBeforeVisibilityChange);
|
|
110
|
+
expect(followUpHandler).toHaveBeenCalledWith(prevState, nextStateAfterVisibilityChange);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('updateProvinceElementHandler', () => {
|
|
114
|
+
it('should select the first province in the list, when country changes and no default is ' + 'available', () => {
|
|
115
|
+
// -------------------------------------------------------------------------------------------
|
|
116
|
+
|
|
117
|
+
const element = {
|
|
118
|
+
id: 'province',
|
|
119
|
+
required: true
|
|
120
|
+
};
|
|
121
|
+
const action = {
|
|
122
|
+
type: 'update',
|
|
123
|
+
rules: [{
|
|
124
|
+
context: 'country'
|
|
125
|
+
}]
|
|
126
|
+
};
|
|
127
|
+
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
128
|
+
const handler = actionListener.createUpdateProvinceElementHandler(element, action);
|
|
129
|
+
const prevState = {
|
|
130
|
+
formData: {
|
|
131
|
+
province: ''
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const nextState = {
|
|
135
|
+
formData: {
|
|
136
|
+
country: 'US'
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
140
|
+
const expected = {
|
|
141
|
+
formData: {
|
|
142
|
+
country: 'US',
|
|
143
|
+
province: 'ST'
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
expect(handler(prevState, nextState)).toEqual(expected);
|
|
147
|
+
});
|
|
148
|
+
it('should select the default province in the list on country changes when a match with ' + 'default is available', () => {
|
|
149
|
+
// -------------------------------------------------------------------------------------------
|
|
150
|
+
|
|
151
|
+
const provinceElement = {
|
|
152
|
+
id: 'province',
|
|
153
|
+
default: 'DF',
|
|
154
|
+
required: true
|
|
155
|
+
};
|
|
156
|
+
const countryElement = {
|
|
157
|
+
id: 'country',
|
|
158
|
+
default: 'US'
|
|
159
|
+
};
|
|
160
|
+
const action = {
|
|
161
|
+
type: 'update',
|
|
162
|
+
rules: [{
|
|
163
|
+
context: countryElement.id
|
|
164
|
+
}]
|
|
165
|
+
};
|
|
166
|
+
const prevState = {};
|
|
167
|
+
const nextState = {
|
|
168
|
+
formData: {
|
|
169
|
+
[countryElement.id]: countryElement.default
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const expected = {
|
|
173
|
+
formData: {
|
|
174
|
+
[provinceElement.id]: provinceElement.default,
|
|
175
|
+
[countryElement.id]: countryElement.default
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Defaults matches the same object structure as 'formData'
|
|
180
|
+
const actionListener = new ActionListener(mockGetProvincesList, expected.formData);
|
|
181
|
+
const handler = actionListener.createUpdateProvinceElementHandler(provinceElement, action);
|
|
182
|
+
|
|
183
|
+
// Expects the handler to take over the defaults in this test
|
|
184
|
+
expect(handler(prevState, nextState)).toEqual(expected);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
describe('setValueHandler', () => {
|
|
188
|
+
it('should create copy the referenced element value into the current element', () => {
|
|
189
|
+
// -------------------------------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
const element = {
|
|
192
|
+
id: 'street2'
|
|
193
|
+
};
|
|
194
|
+
const action = {
|
|
195
|
+
type: ACTION_TYPE_SET_VALUE,
|
|
196
|
+
params: {
|
|
197
|
+
type: ACTION_SET_VALUE_COPY_FROM,
|
|
198
|
+
value: 'street'
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
202
|
+
const handler = actionListener.createSetValueHandler(element, action);
|
|
203
|
+
|
|
204
|
+
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
205
|
+
const prevState = {
|
|
206
|
+
formData: {
|
|
207
|
+
street: '',
|
|
208
|
+
street2: ''
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
212
|
+
const nextState = {
|
|
213
|
+
formData: {
|
|
214
|
+
street: 'Street 1',
|
|
215
|
+
street2: ''
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
219
|
+
const expected = {
|
|
220
|
+
formData: {
|
|
221
|
+
street: 'Street 1',
|
|
222
|
+
street2: 'Street 1'
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
expect(handler(prevState, nextState)).toEqual(expected);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
describe('transformHandler', () => {
|
|
229
|
+
it('should apply the transformHandler correctly for "String" operations', () => {
|
|
230
|
+
// -------------------------------------------------------------------------------------------
|
|
231
|
+
|
|
232
|
+
const element = {
|
|
233
|
+
id: 'street'
|
|
234
|
+
};
|
|
235
|
+
const action = {
|
|
236
|
+
type: ACTION_TYPE_TRANSFORM,
|
|
237
|
+
params: {
|
|
238
|
+
type: 'toUpperCase'
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
242
|
+
const handler = actionListener.createTransformHandler(element, action);
|
|
243
|
+
const prevState = {
|
|
244
|
+
formData: {
|
|
245
|
+
street: ''
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const nextState = {
|
|
249
|
+
formData: {
|
|
250
|
+
street: 'Street'
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const expected = {
|
|
254
|
+
formData: {
|
|
255
|
+
street: 'STREET'
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
expect(handler(prevState, nextState)).toEqual(expected);
|
|
259
|
+
});
|
|
260
|
+
it('should apply the transformHandler correctly for "Boolean" operations', () => {
|
|
261
|
+
// -------------------------------------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
const element = {
|
|
264
|
+
id: 'boolTest'
|
|
265
|
+
};
|
|
266
|
+
const action = {
|
|
267
|
+
type: ACTION_TYPE_TRANSFORM,
|
|
268
|
+
params: {
|
|
269
|
+
type: 'toString'
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
273
|
+
const handler = actionListener.createTransformHandler(element, action);
|
|
274
|
+
const prevState = {
|
|
275
|
+
formData: {
|
|
276
|
+
boolTest: true
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const nextState = {
|
|
280
|
+
formData: {
|
|
281
|
+
boolTest: true
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const expected = {
|
|
285
|
+
formData: {
|
|
286
|
+
boolTest: 'true'
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
expect(handler(prevState, nextState)).toEqual(expected);
|
|
290
|
+
});
|
|
291
|
+
it('should apply the transformHandler correctly for "Number" operations', () => {
|
|
292
|
+
// -------------------------------------------------------------------------------------------
|
|
293
|
+
|
|
294
|
+
const element = {
|
|
295
|
+
id: 'numberTest'
|
|
296
|
+
};
|
|
297
|
+
const action = {
|
|
298
|
+
type: ACTION_TYPE_TRANSFORM,
|
|
299
|
+
params: {
|
|
300
|
+
type: 'isInteger'
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const actionListener = new ActionListener(mockGetProvincesList, {});
|
|
304
|
+
const handler = actionListener.createTransformHandler(element, action);
|
|
305
|
+
const prevState = {
|
|
306
|
+
formData: {
|
|
307
|
+
numberTest: 7.88
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
const nextState = {
|
|
311
|
+
formData: {
|
|
312
|
+
numberTest: 7.88
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const expected = {
|
|
316
|
+
formData: {
|
|
317
|
+
numberTest: false
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
expect(handler(prevState, nextState)).toEqual(expected);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
});
|
|
@@ -1,7 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Checkbox from "../../Checkbox";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Takes an element and renders it, if the type matches
|
|
3
7
|
* @param {Object} element The data of the element to be rendered
|
|
4
8
|
* @returns {JSX}
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
class CheckboxElement extends PureComponent {
|
|
11
|
+
/**
|
|
6
12
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
render() {
|
|
15
|
+
const {
|
|
16
|
+
element,
|
|
17
|
+
style,
|
|
18
|
+
errorText,
|
|
19
|
+
value,
|
|
20
|
+
name
|
|
21
|
+
} = this.props;
|
|
22
|
+
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
23
|
+
name: name,
|
|
24
|
+
errorText: errorText,
|
|
25
|
+
checked: value,
|
|
26
|
+
className: style.fields,
|
|
27
|
+
label: element.label,
|
|
28
|
+
onChange: element.handleChange,
|
|
29
|
+
translateErrorText: false
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
CheckboxElement.defaultProps = {
|
|
34
|
+
value: false,
|
|
35
|
+
style: {
|
|
36
|
+
fields: ''
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export default CheckboxElement;
|
|
@@ -1,7 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Select from "../../Select";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* React component that takes the element and additional data and renders a select box
|
|
3
7
|
* with a list of countries to select from.
|
|
4
8
|
* @returns {JSX}
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
class CountryElement extends PureComponent {
|
|
11
|
+
/**
|
|
6
12
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
render() {
|
|
15
|
+
const {
|
|
16
|
+
countryList,
|
|
17
|
+
element,
|
|
18
|
+
errorText,
|
|
19
|
+
name,
|
|
20
|
+
style,
|
|
21
|
+
value
|
|
22
|
+
} = this.props;
|
|
23
|
+
return /*#__PURE__*/React.createElement(Select, {
|
|
24
|
+
name: name,
|
|
25
|
+
className: style.fields,
|
|
26
|
+
label: element.label,
|
|
27
|
+
placeholder: element.placeholder,
|
|
28
|
+
value: value,
|
|
29
|
+
options: countryList,
|
|
30
|
+
onChange: element.handleChange,
|
|
31
|
+
errorText: errorText,
|
|
32
|
+
isControlled: true,
|
|
33
|
+
translateErrorText: false
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
CountryElement.defaultProps = {
|
|
38
|
+
countryList: {},
|
|
39
|
+
value: '',
|
|
40
|
+
style: {
|
|
41
|
+
fields: ''
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export default CountryElement;
|
|
@@ -1,7 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Select from "../../Select";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* React component that takes the element and additional data and renders a select box
|
|
3
7
|
* with a list of provinces to select from.
|
|
4
8
|
* @returns {JSX}
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
class ProvinceElement extends PureComponent {
|
|
11
|
+
/**
|
|
6
12
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
render() {
|
|
15
|
+
const {
|
|
16
|
+
provincesList,
|
|
17
|
+
element,
|
|
18
|
+
errorText,
|
|
19
|
+
name,
|
|
20
|
+
style,
|
|
21
|
+
value
|
|
22
|
+
} = this.props;
|
|
23
|
+
return /*#__PURE__*/React.createElement(Select, {
|
|
24
|
+
name: name,
|
|
25
|
+
className: style.fields,
|
|
26
|
+
label: element.label,
|
|
27
|
+
placeholder: element.placeholder,
|
|
28
|
+
value: value,
|
|
29
|
+
options: provincesList,
|
|
30
|
+
onChange: element.handleChange,
|
|
31
|
+
errorText: errorText,
|
|
32
|
+
isControlled: true,
|
|
33
|
+
translateErrorText: false
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
ProvinceElement.defaultProps = {
|
|
38
|
+
provincesList: {},
|
|
39
|
+
value: '',
|
|
40
|
+
style: {
|
|
41
|
+
fields: ''
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export default ProvinceElement;
|
|
@@ -1,7 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import RadioGroup from "../../RadioGroup";
|
|
4
|
+
import RadioItem from "../../RadioGroup/components/Item";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* React component that takes the element and additional data and renders a radio group
|
|
3
8
|
* with a list of radio items.
|
|
4
9
|
* @returns {JSX}
|
|
5
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
class RadioElement extends PureComponent {
|
|
12
|
+
/**
|
|
6
13
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
render() {
|
|
16
|
+
const {
|
|
17
|
+
element,
|
|
18
|
+
errorText,
|
|
19
|
+
name,
|
|
20
|
+
style,
|
|
21
|
+
value
|
|
22
|
+
} = this.props;
|
|
23
|
+
return /*#__PURE__*/React.createElement(RadioGroup, {
|
|
24
|
+
name: name,
|
|
25
|
+
className: style.fields,
|
|
26
|
+
label: element.label,
|
|
27
|
+
value: value,
|
|
28
|
+
onChange: element.handleChange,
|
|
29
|
+
errorText: errorText,
|
|
30
|
+
isControlled: true,
|
|
31
|
+
translateErrorText: false
|
|
32
|
+
}, Object.keys(element.options).map(itemName => /*#__PURE__*/React.createElement(RadioItem, {
|
|
33
|
+
key: itemName,
|
|
34
|
+
name: itemName,
|
|
35
|
+
label: element.options[itemName]
|
|
36
|
+
})));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
RadioElement.defaultProps = {
|
|
40
|
+
value: '',
|
|
41
|
+
style: {
|
|
42
|
+
fields: ''
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export default RadioElement;
|
|
@@ -1,6 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { PureComponent, Fragment } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Chevron from "../../../icons/CheckIcon";
|
|
4
|
+
import Select from "../../Select";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* React component that takes the element and additional data and renders a configured select box.
|
|
3
8
|
* @returns {JSX}
|
|
4
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
class SelectElement extends PureComponent {
|
|
11
|
+
/**
|
|
5
12
|
* @returns {JSX}
|
|
6
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
render() {
|
|
15
|
+
const {
|
|
16
|
+
element,
|
|
17
|
+
errorText,
|
|
18
|
+
name,
|
|
19
|
+
style,
|
|
20
|
+
value
|
|
21
|
+
} = this.props;
|
|
22
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Select, {
|
|
23
|
+
name: name,
|
|
24
|
+
className: style.fields,
|
|
25
|
+
label: element.label,
|
|
26
|
+
placeholder: element.placeholder,
|
|
27
|
+
value: value,
|
|
28
|
+
options: element.options,
|
|
29
|
+
onChange: element.handleChange,
|
|
30
|
+
errorText: errorText,
|
|
31
|
+
isControlled: true,
|
|
32
|
+
translateErrorText: false
|
|
33
|
+
}), /*#__PURE__*/React.createElement(Chevron, null));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
SelectElement.defaultProps = {
|
|
37
|
+
value: '',
|
|
38
|
+
style: {
|
|
39
|
+
fields: ''
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export default SelectElement;
|