@shopgate/pwa-ui-shared 7.32.0-beta.8 → 7.32.0

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 (54) hide show
  1. package/DiscountBadge/index.js +1 -1
  2. package/FavoritesButton/FavoritesButton.d.ts +74 -0
  3. package/FavoritesButton/FavoritesButton.d.ts.map +1 -0
  4. package/FavoritesButton/FavoritesButton.js +87 -0
  5. package/FavoritesButton/connector.d.ts +3 -0
  6. package/FavoritesButton/connector.d.ts.map +1 -0
  7. package/FavoritesButton/index.d.ts +3 -0
  8. package/FavoritesButton/index.d.ts.map +1 -0
  9. package/FavoritesButton/index.js +1 -134
  10. package/Glow/index.js +4 -3
  11. package/NoResults/components/Icon/index.js +4 -1
  12. package/Price/index.js +11 -4
  13. package/PriceStriked/index.js +7 -1
  14. package/package.json +5 -5
  15. package/AccordionContainer/spec.js +0 -35
  16. package/ActionButton/spec.js +0 -66
  17. package/AddToCartButton/spec.js +0 -68
  18. package/Availability/spec.js +0 -42
  19. package/Button/spec.js +0 -38
  20. package/ButtonLink/spec.js +0 -29
  21. package/Chip/spec.js +0 -27
  22. package/ContextMenu/spec.js +0 -113
  23. package/Dialog/components/HtmlContentDialog/spec.js +0 -107
  24. package/Dialog/components/PipelineErrorDialog/spec.js +0 -105
  25. package/Dialog/components/TextMessageDialog/spec.js +0 -62
  26. package/Dialog/components/VariantSelectModal/spec.js +0 -55
  27. package/Dialog/spec.js +0 -84
  28. package/DiscountBadge/spec.js +0 -20
  29. package/FavoritesButton/spec.js +0 -131
  30. package/Form/Builder/classes/ActionListener/spec.js +0 -323
  31. package/Form/Builder/spec.js +0 -309
  32. package/Form/InfoField/spec.js +0 -12
  33. package/Form/Password/spec.js +0 -39
  34. package/Form/RadioGroup/spec.js +0 -97
  35. package/Form/Select/spec.js +0 -39
  36. package/Form/SelectContextChoices/spec.js +0 -36
  37. package/Form/TextField/spec.js +0 -124
  38. package/FormElement/spec.js +0 -68
  39. package/Glow/spec.js +0 -14
  40. package/IndicatorCircle/spec.js +0 -26
  41. package/PlaceholderLabel/spec.js +0 -26
  42. package/PlaceholderParagraph/spec.js +0 -26
  43. package/ProgressBar/spec.js +0 -14
  44. package/RadioButton/spec.js +0 -22
  45. package/RatingStars/spec.js +0 -94
  46. package/RippleButton/spec.js +0 -58
  47. package/Sheet/components/Header/components/SearchBar/spec.js +0 -22
  48. package/Sheet/components/Header/spec.js +0 -17
  49. package/Sheet/spec.js +0 -100
  50. package/TaxDisclaimer/spec.js +0 -44
  51. package/TextField/spec.js +0 -146
  52. package/ToggleIcon/spec.js +0 -39
  53. package/tsconfig.build.json +0 -16
  54. package/tsconfig.json +0 -3
@@ -1,131 +0,0 @@
1
- import React from 'react';
2
- import { act } from 'react-dom/test-utils';
3
- import { Provider } from 'react-redux';
4
- import configureStore from 'redux-mock-store';
5
- import { mount } from 'enzyme';
6
- import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
7
- import appConfig from '@shopgate/pwa-common/helpers/config';
8
- import FavoritesButton from "./index";
9
- import { mockedStateEmpty, mockedStateOnList, mockedStateNotOnList } from "./mock";
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- const mockedStore = configureStore();
12
- const dispatcher = jest.fn();
13
- jest.mock('@shopgate/pwa-common/helpers/config');
14
- jest.mock('@shopgate/pwa-common-commerce/favorites/selectors/index', () => ({
15
- isFetching: () => false
16
- }));
17
- beforeEach(() => {
18
- jest.resetModules();
19
- });
20
- describe('<FavoritesButton />', () => {
21
- let component = null;
22
-
23
- /**
24
- * Creates component with provided store state.
25
- * @param {Object} mockedState Mocked stage.
26
- * @param {Object} props Additional props.
27
- * @return {ReactWrapper}
28
- */
29
- const createComponent = (mockedState, props = {
30
- active: false
31
- }) => {
32
- const store = mockedStore(mockedState);
33
- store.dispatch = dispatcher;
34
- return mount(/*#__PURE__*/_jsx(Provider, {
35
- store: store,
36
- children: /*#__PURE__*/_jsx(FavoritesButton, {
37
- ...props
38
- })
39
- }), mockRenderOptions);
40
- };
41
- beforeEach(() => {
42
- dispatcher.mockReset();
43
- });
44
- it('should only render when no favorites set', () => {
45
- component = createComponent(mockedStateEmpty);
46
- expect(component).toMatchSnapshot();
47
- expect(component.find('Heart').exists()).toBe(false);
48
- expect(component.find('HeartOutline').exists()).toBe(true);
49
- component.find('button').simulate('click');
50
- });
51
- it('should render when favorites set', () => {
52
- component = createComponent(mockedStateOnList, {
53
- active: true
54
- });
55
- expect(component).toMatchSnapshot();
56
- expect(component.find('Heart').exists()).toBe(true);
57
- expect(component.find('HeartOutline').exists()).toBe(false);
58
- });
59
- it('should add to favorites on click', () => {
60
- component = createComponent(mockedStateNotOnList, {
61
- productId: '1',
62
- active: false
63
- });
64
- expect(component.find('Heart').exists()).toBe(false);
65
- expect(component.find('HeartOutline').exists()).toBe(true);
66
- component.find('button').simulate('click');
67
- component.update();
68
- expect(dispatcher).toHaveBeenCalled();
69
- });
70
- it('should remove from favorites on click', done => {
71
- component = createComponent(mockedStateOnList, {
72
- productId: '1',
73
- active: true
74
- });
75
- expect(component.find('Heart').exists()).toBe(true);
76
- expect(component.find('HeartOutline').exists()).toBe(false);
77
- component.find('button').simulate('click');
78
- component.update();
79
- setTimeout(() => {
80
- expect(dispatcher).toHaveBeenCalled();
81
- done();
82
- }, 0);
83
- });
84
- it('should process ripple complete callback', async () => {
85
- const onRippleComplete = jest.fn();
86
- component = createComponent(mockedStateOnList, {
87
- productId: '1',
88
- active: true,
89
- onRippleComplete
90
- });
91
- await act(async () => {
92
- component.find('Ripple').invoke('onComplete')();
93
- });
94
- component.update();
95
- expect(onRippleComplete).toHaveBeenCalled();
96
- });
97
- it('should only react on first click', done => {
98
- component = createComponent(mockedStateOnList, {
99
- once: true,
100
- productId: '1',
101
- active: false
102
- });
103
- component.find('button').simulate('click');
104
- component.update();
105
- component.find('button').simulate('click');
106
- component.update();
107
- setTimeout(() => {
108
- expect(dispatcher.mock.calls.length).toBe(1);
109
- done();
110
- }, 1);
111
- });
112
- it('should only react on both clicks', done => {
113
- component = createComponent(mockedStateOnList, {
114
- productId: '1',
115
- active: false
116
- });
117
- component.find('button').simulate('click');
118
- component.update();
119
- component.find('button').simulate('click');
120
- component.update();
121
- setTimeout(() => {
122
- expect(dispatcher.mock.calls.length).toBe(2);
123
- done();
124
- }, 1);
125
- });
126
- it('should render null when feature flag is off', () => {
127
- jest.spyOn(appConfig, 'hasFavorites', 'get').mockReturnValue(false);
128
- component = createComponent(mockedStateOnList);
129
- expect(component.isEmptyRender()).toBe(true);
130
- });
131
- });
@@ -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
- });