@shopgate/pwa-ui-shared 7.32.0-beta.2 → 7.32.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/ActionButton/index.js +4 -0
  2. package/AddToCartButton/index.js +4 -1
  3. package/Button/index.js +10 -3
  4. package/ButtonLink/index.js +4 -0
  5. package/Card/index.js +13 -34
  6. package/CardList/components/Item/index.js +26 -20
  7. package/CardList/index.js +2 -1
  8. package/CartTotalLine/index.js +1 -1
  9. package/Dialog/components/PipelineErrorDialog/index.js +2 -1
  10. package/DiscountBadge/index.js +1 -1
  11. package/FavoritesButton/FavoritesButton.d.ts +74 -0
  12. package/FavoritesButton/FavoritesButton.d.ts.map +1 -0
  13. package/FavoritesButton/FavoritesButton.js +87 -0
  14. package/FavoritesButton/connector.d.ts +3 -0
  15. package/FavoritesButton/connector.d.ts.map +1 -0
  16. package/FavoritesButton/index.d.ts +3 -0
  17. package/FavoritesButton/index.d.ts.map +1 -0
  18. package/FavoritesButton/index.js +1 -134
  19. package/Glow/index.js +4 -3
  20. package/NoResults/components/Icon/index.js +4 -1
  21. package/NoResults/index.js +1 -1
  22. package/Price/index.js +11 -4
  23. package/PriceStriked/index.js +7 -1
  24. package/RatingStars/index.js +16 -5
  25. package/RippleButton/index.js +5 -1
  26. package/Sheet/index.js +11 -1
  27. package/TaxDisclaimer/index.js +0 -1
  28. package/package.json +5 -5
  29. package/AccordionContainer/spec.js +0 -35
  30. package/ActionButton/spec.js +0 -66
  31. package/AddToCartButton/spec.js +0 -68
  32. package/Availability/spec.js +0 -42
  33. package/Button/spec.js +0 -38
  34. package/ButtonLink/spec.js +0 -29
  35. package/Chip/spec.js +0 -27
  36. package/ContextMenu/spec.js +0 -113
  37. package/Dialog/components/HtmlContentDialog/spec.js +0 -107
  38. package/Dialog/components/PipelineErrorDialog/spec.js +0 -89
  39. package/Dialog/components/TextMessageDialog/spec.js +0 -62
  40. package/Dialog/components/VariantSelectModal/spec.js +0 -55
  41. package/Dialog/spec.js +0 -84
  42. package/DiscountBadge/spec.js +0 -20
  43. package/FavoritesButton/spec.js +0 -131
  44. package/Form/Builder/classes/ActionListener/spec.js +0 -323
  45. package/Form/Builder/spec.js +0 -309
  46. package/Form/InfoField/spec.js +0 -12
  47. package/Form/Password/spec.js +0 -39
  48. package/Form/RadioGroup/spec.js +0 -97
  49. package/Form/Select/spec.js +0 -39
  50. package/Form/SelectContextChoices/spec.js +0 -36
  51. package/Form/TextField/spec.js +0 -124
  52. package/FormElement/spec.js +0 -68
  53. package/Glow/spec.js +0 -14
  54. package/IndicatorCircle/spec.js +0 -26
  55. package/PlaceholderLabel/spec.js +0 -26
  56. package/PlaceholderParagraph/spec.js +0 -26
  57. package/ProgressBar/spec.js +0 -14
  58. package/RadioButton/spec.js +0 -22
  59. package/RatingStars/spec.js +0 -91
  60. package/RippleButton/spec.js +0 -58
  61. package/Sheet/components/Header/components/SearchBar/spec.js +0 -22
  62. package/Sheet/components/Header/spec.js +0 -17
  63. package/Sheet/spec.js +0 -100
  64. package/TaxDisclaimer/spec.js +0 -44
  65. package/TextField/spec.js +0 -146
  66. package/ToggleIcon/spec.js +0 -39
  67. package/tsconfig.build.json +0 -16
  68. package/tsconfig.json +0 -3
@@ -1,323 +0,0 @@
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
- /**
10
- * Mock for provinces
11
- * @returns {{ST: string}}
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,309 +0,0 @@
1
- /* eslint-disable extra-rules/no-single-line-objects */
2
- import React from 'react';
3
- import { mount } from 'enzyme';
4
- import FormBuilder from '.';
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- jest.mock('@shopgate/engage/components');
7
- describe('<FormBuilder />', () => {
8
- it('should render empty form', () => {
9
- const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
10
- config: {
11
- fields: {}
12
- },
13
- name: "foo",
14
- handleUpdate: () => {}
15
- }));
16
- expect(wrapper).toMatchSnapshot();
17
- });
18
- it('should render two text fields', () => {
19
- const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
20
- config: {
21
- fields: {
22
- firstName: {
23
- label: 'foo',
24
- type: 'text',
25
- visible: true
26
- },
27
- lastName: {
28
- label: 'bar',
29
- type: 'text',
30
- visible: true
31
- }
32
- }
33
- },
34
- name: "foo",
35
- handleUpdate: () => {}
36
- }));
37
- expect(wrapper).toMatchSnapshot();
38
- expect(wrapper.find('TextField').length).toEqual(2);
39
- });
40
- it('should not render invisible field', () => {
41
- const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
42
- config: {
43
- fields: {
44
- firstName: {
45
- label: 'foo',
46
- type: 'text',
47
- visible: false
48
- }
49
- }
50
- },
51
- name: "foo",
52
- handleUpdate: () => {}
53
- }));
54
- expect(wrapper).toMatchSnapshot();
55
- expect(wrapper.find('TextField').length).toEqual(0);
56
- });
57
- it('should hide element if setVisibilty rule applies', () => {
58
- const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
59
- config: {
60
- fields: {
61
- foo: {
62
- label: 'foo',
63
- type: 'text',
64
- visible: true
65
- },
66
- bar: {
67
- label: 'bar',
68
- type: 'text',
69
- actions: [{
70
- type: 'setVisibility',
71
- rules: [{
72
- context: 'foo',
73
- type: 'notIn',
74
- data: ['abc']
75
- }]
76
- }]
77
- }
78
- }
79
- },
80
- name: "foo",
81
- handleUpdate: () => {}
82
- }));
83
-
84
- // Both should be visible at the beginning.
85
- expect(wrapper).toMatchSnapshot();
86
- expect(wrapper.find('TextField').length).toEqual(2);
87
-
88
- // Simulate user input to the text field.
89
- wrapper.find('input').first().simulate('change', {
90
- target: {
91
- value: 'abc'
92
- }
93
- });
94
-
95
- // Second field should be hidden now.
96
- expect(wrapper).toMatchSnapshot();
97
- expect(wrapper.find('TextField').length).toEqual(1);
98
- });
99
- it('should reset value when rule applies', () => {
100
- const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
101
- config: {
102
- fields: {
103
- foo: {
104
- label: 'foo',
105
- type: 'text',
106
- visible: true,
107
- default: 'default'
108
- },
109
- bar: {
110
- label: 'bar',
111
- type: 'text',
112
- default: 'default',
113
- actions: [{
114
- type: 'setValue',
115
- params: {
116
- value: 'cheat',
117
- type: 'fixed'
118
- },
119
- rules: [{
120
- context: 'foo',
121
- type: 'notIn',
122
- data: ['default']
123
- }]
124
- }]
125
- }
126
- }
127
- },
128
- name: "foo",
129
- handleUpdate: () => {}
130
- }));
131
-
132
- // Default values should be in the inputs.
133
- expect(wrapper).toMatchSnapshot();
134
- expect(wrapper.find('TextField').length).toEqual(2);
135
- expect(wrapper.find('input').at(0).props().value).toEqual('default');
136
- expect(wrapper.find('input').at(1).props().value).toEqual('default');
137
-
138
- // Simulate text input to trigger rule.
139
- wrapper.find('input').first().simulate('change', {
140
- target: {
141
- value: 'abc'
142
- }
143
- });
144
- wrapper.update();
145
-
146
- // Second field should be hidden now.
147
- expect(wrapper).toMatchSnapshot();
148
- expect(wrapper.find('TextField').length).toEqual(2);
149
- expect(wrapper.find('input').at(0).props().value).toEqual('abc');
150
- expect(wrapper.find('input').at(1).props().value).toEqual('cheat');
151
- });
152
- it('should call onChange callback when input is changed', () => {
153
- const handleUpdate = jest.fn();
154
- const wrapper = mount(/*#__PURE__*/_jsx(FormBuilder, {
155
- config: {
156
- fields: {
157
- foo: {
158
- label: 'foo',
159
- type: 'text',
160
- visible: true,
161
- default: 'default'
162
- }
163
- }
164
- },
165
- name: "foo",
166
- id: "foo",
167
- handleUpdate: handleUpdate
168
- }));
169
-
170
- // Should call with initial state.
171
- expect(wrapper).toMatchSnapshot();
172
- expect(handleUpdate).toHaveBeenCalledWith({
173
- foo: 'default'
174
- }, false);
175
- handleUpdate.mockClear();
176
-
177
- // Update input
178
- wrapper.find('input').first().simulate('change', {
179
- target: {
180
- value: 'abc'
181
- }
182
- });
183
-
184
- // Should call with updated state.
185
- expect(handleUpdate).toHaveBeenCalledWith({
186
- foo: 'abc'
187
- }, false);
188
- });
189
- describe('FormBuilder::elementChangeHandler', () => {
190
- it('should take the updated state from action listener', () => {
191
- const handleUpdate = jest.fn();
192
- const ref = /*#__PURE__*/React.createRef();
193
- mount(/*#__PURE__*/_jsx(FormBuilder, {
194
- ref: ref,
195
- validationErrors: [],
196
- config: {
197
- fields: {
198
- foo: {
199
- label: 'foo',
200
- type: 'text',
201
- visible: true,
202
- default: 'default'
203
- }
204
- }
205
- },
206
- name: "foo",
207
- id: "foo",
208
- handleUpdate: handleUpdate
209
- }));
210
- ref.current.actionListener.notify = () => ({
211
- formData: {
212
- foo: 'bar'
213
- },
214
- errors: {},
215
- elementVisibility: {
216
- foo: true
217
- }
218
- });
219
-
220
- // Trigger update
221
- ref.current.elementChangeHandler('foo', 'bar');
222
-
223
- // Test
224
- expect(handleUpdate).toHaveBeenCalledWith({
225
- foo: 'bar'
226
- }, false);
227
- });
228
- it('should consider backend validations', () => {
229
- // Create mocked Form builder.
230
- const handleUpdate = jest.fn();
231
- const ref = /*#__PURE__*/React.createRef();
232
- mount(/*#__PURE__*/_jsx(FormBuilder, {
233
- ref: ref,
234
- validationErrors: [{}],
235
- config: {
236
- fields: {
237
- foo: {
238
- label: 'foo',
239
- type: 'text',
240
- visible: true,
241
- default: 'default'
242
- }
243
- }
244
- },
245
- name: "foo",
246
- id: "foo",
247
- handleUpdate: handleUpdate
248
- }));
249
- ref.current.actionListener.notify = () => ({
250
- formData: {
251
- foo: 'bar'
252
- },
253
- errors: {},
254
- elementVisibility: {
255
- foo: true
256
- }
257
- });
258
-
259
- // Trigger update
260
- ref.current.elementChangeHandler('foo', 'bar');
261
-
262
- // Test
263
- expect(handleUpdate).toHaveBeenCalledWith({
264
- foo: 'bar'
265
- }, true);
266
- });
267
- });
268
- describe('FormBuilder::elementSortFunc', () => {
269
- const builder = new FormBuilder({
270
- validationErrors: [{}],
271
- config: {
272
- fields: {}
273
- },
274
- handleUpdate: jest.fn()
275
- });
276
- const field1 = {
277
- id: 'foo',
278
- label: 'foo'
279
- };
280
- const field2 = {
281
- id: 'foo2',
282
- label: 'foo2'
283
- };
284
- it('should keep sortOrder for undefined', () => {
285
- expect([field2, field1].sort(builder.elementSortFunc)).toEqual([field2, field1]);
286
- });
287
- it('should sort elements', () => {
288
- const fields = [{
289
- ...field1,
290
- sortOrder: 2
291
- }, {
292
- ...field2,
293
- sortOrder: 1
294
- }];
295
- expect(fields.sort(builder.elementSortFunc)).toEqual(fields.reverse());
296
- });
297
- it('should keep sortOrder', () => {
298
- const fields = [{
299
- ...field2,
300
- sortOrder: 1
301
- }, {
302
- ...field1,
303
- sortOrder: 2
304
- }];
305
- expect(fields.sort(builder.elementSortFunc)).toEqual([].concat(fields));
306
- });
307
- });
308
- });
309
- /* eslint-enable extra-rules/no-single-line-objects */
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import InfoField from "./index";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- describe('<InfoField>', () => {
6
- it('should render info field', () => {
7
- const wrapper = render(/*#__PURE__*/_jsx(InfoField, {
8
- children: "Some info text"
9
- }));
10
- expect(wrapper.asFragment()).toMatchSnapshot();
11
- });
12
- });
@@ -1,39 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import Password from "./index";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- const inputProps = {
6
- name: 'test-input'
7
- };
8
- describe('<Password>', () => {
9
- it('should render a password field', () => {
10
- const wrapper = mount(/*#__PURE__*/_jsx(Password, {
11
- ...inputProps
12
- }));
13
- expect(wrapper).toMatchSnapshot();
14
- expect(wrapper.find('input[type="password"]').length).toBe(1);
15
- });
16
- it('should trigger the onChange callback', () => {
17
- const onChangeMock = jest.fn();
18
- const wrapper = mount(/*#__PURE__*/_jsx(Password, {
19
- ...inputProps,
20
- onChange: onChangeMock
21
- }));
22
- wrapper.find('input').simulate('change', {
23
- target: {
24
- value: 'a'
25
- }
26
- });
27
- expect(onChangeMock).toHaveBeenCalledTimes(2);
28
- expect(wrapper.find('input').props().value).toEqual('a');
29
- });
30
- it('should toggle password visibility', () => {
31
- const wrapper = mount(/*#__PURE__*/_jsx(Password, {
32
- ...inputProps
33
- }));
34
- const input = wrapper.find('ToggleIcon');
35
- expect(wrapper.find('input[type="password"]').length).toBe(1);
36
- input.simulate('click');
37
- expect(wrapper.find('input[type="text"]').length).toBe(1);
38
- });
39
- });