@shopgate/pwa-ui-shared 7.30.0-alpha.8 → 7.30.0-alpha.9

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.
@@ -44,17 +44,21 @@ describe('<ActionButton />', () => {
44
44
  });
45
45
  });
46
46
  describe('Given the component gets clicked', () => {
47
+ let timeoutSpy;
47
48
  beforeEach(() => {
49
+ timeoutSpy = jest.spyOn(global, 'setTimeout');
48
50
  renderedElement.find(RippleButton).simulate('click');
49
51
  });
52
+ afterEach(() => {
53
+ timeoutSpy.mockRestore();
54
+ });
50
55
  it('should use setTimeout for delaying the onClick handler', () => {
51
- expect(setTimeout.mock.calls.length).toBe(1);
52
- expect(setTimeout.mock.calls[0][1]).toBe(ActionButton.clickDelay);
56
+ expect(timeoutSpy).toHaveBeenCalledTimes(1);
57
+ expect(timeoutSpy.mock.calls[0][1]).toBe(ActionButton.clickDelay);
53
58
  });
54
59
  it('should eventually call the onClick handler', () => {
55
60
  jest.runOnlyPendingTimers();
56
- expect(mockOnClick).toBeCalled();
57
- expect(mockOnClick.mock.calls.length).toBe(1);
61
+ expect(mockOnClick).toHaveBeenCalledTimes(1);
58
62
  });
59
63
  });
60
64
  });
@@ -1,52 +1,66 @@
1
- import "core-js/modules/web.immediate.js";
2
1
  import React from 'react';
3
2
  import { mount } from 'enzyme';
3
+ import { act } from 'react-dom/test-utils';
4
4
  import AddToCartButton from "./index";
5
5
 
6
6
  /**
7
7
  * Flushes the promise queue.
8
8
  * @returns {Promise}
9
9
  */
10
- const flushPromises = () => new Promise(resolve => setImmediate(resolve));
10
+ const flushMicrotasks = () => Promise.resolve();
11
11
  describe('<AddToCartButton />', () => {
12
12
  it('should render in loading state and should not be clickable', () => {
13
- const spy = jest.fn(() => new Promise(resolve => resolve()));
13
+ const spy = jest.fn(() => Promise.resolve());
14
14
  const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
15
15
  onClick: spy,
16
16
  isLoading: true,
17
17
  isOrderable: true,
18
18
  isDisabled: false
19
19
  }));
20
+
21
+ // Click shouldn’t fire when loading
20
22
  wrapper.find('button').prop('onClick')();
21
23
  expect(wrapper).toMatchSnapshot();
22
24
  expect(spy).toHaveBeenCalledTimes(0);
23
25
  });
24
26
  it('should render with checkmark icon and should not be clickable the second time', async () => {
25
- const spy = jest.fn(() => new Promise(resolve => resolve()));
27
+ const spy = jest.fn(() => Promise.resolve());
26
28
  const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
27
29
  onClick: spy,
28
30
  isLoading: false,
29
31
  isOrderable: true,
30
32
  isDisabled: false
31
33
  }));
32
- wrapper.find('button').prop('onClick')();
34
+
35
+ // First click triggers async work
36
+ await act(async () => {
37
+ wrapper.find('button').prop('onClick')();
38
+ await flushMicrotasks();
39
+ });
33
40
  wrapper.update();
34
- await flushPromises();
35
- wrapper.find('button').prop('onClick')();
41
+
42
+ // Second click should be ignored
43
+ await act(async () => {
44
+ wrapper.find('button').prop('onClick')();
45
+ await flushMicrotasks();
46
+ });
36
47
  wrapper.update();
37
- await flushPromises();
38
48
  expect(wrapper).toMatchSnapshot();
39
49
  expect(spy).toHaveBeenCalledTimes(1);
40
50
  });
41
- it('should render with cart icon and should be clickable', () => {
42
- const spy = jest.fn(() => new Promise(resolve => resolve()));
51
+ it('should render with cart icon and should be clickable', async () => {
52
+ const spy = jest.fn(() => Promise.resolve());
43
53
  const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
44
54
  onClick: spy,
45
55
  isLoading: false,
46
56
  isOrderable: true,
47
57
  isDisabled: false
48
58
  }));
49
- wrapper.find('button').prop('onClick')();
59
+ await act(async () => {
60
+ wrapper.find('button').prop('onClick')();
61
+ await flushMicrotasks();
62
+ });
63
+ wrapper.update();
50
64
  expect(wrapper).toMatchSnapshot();
51
65
  expect(spy).toHaveBeenCalledTimes(1);
52
66
  });
@@ -2,6 +2,7 @@
2
2
  import React from 'react';
3
3
  import { mount } from 'enzyme';
4
4
  import FormBuilder from '.';
5
+ jest.mock('@shopgate/engage/components');
5
6
  describe('<FormBuilder />', () => {
6
7
  it('should render empty form', () => {
7
8
  const wrapper = mount(/*#__PURE__*/React.createElement(FormBuilder, {
@@ -186,9 +187,10 @@ describe('<FormBuilder />', () => {
186
187
  });
187
188
  describe('FormBuilder::elementChangeHandler', () => {
188
189
  it('should take the updated state from action listener', () => {
189
- // Create mocked Form builder.
190
190
  const handleUpdate = jest.fn();
191
- const builder = new FormBuilder({
191
+ const ref = /*#__PURE__*/React.createRef();
192
+ mount(/*#__PURE__*/React.createElement(FormBuilder, {
193
+ ref: ref,
192
194
  validationErrors: [],
193
195
  config: {
194
196
  fields: {
@@ -200,9 +202,11 @@ describe('<FormBuilder />', () => {
200
202
  }
201
203
  }
202
204
  },
203
- handleUpdate
204
- });
205
- builder.actionListener.notify = () => ({
205
+ name: "foo",
206
+ id: "foo",
207
+ handleUpdate: handleUpdate
208
+ }));
209
+ ref.current.actionListener.notify = () => ({
206
210
  formData: {
207
211
  foo: 'bar'
208
212
  },
@@ -213,7 +217,7 @@ describe('<FormBuilder />', () => {
213
217
  });
214
218
 
215
219
  // Trigger update
216
- builder.elementChangeHandler('foo', 'bar');
220
+ ref.current.elementChangeHandler('foo', 'bar');
217
221
 
218
222
  // Test
219
223
  expect(handleUpdate).toHaveBeenCalledWith({
@@ -223,7 +227,9 @@ describe('<FormBuilder />', () => {
223
227
  it('should consider backend validations', () => {
224
228
  // Create mocked Form builder.
225
229
  const handleUpdate = jest.fn();
226
- const builder = new FormBuilder({
230
+ const ref = /*#__PURE__*/React.createRef();
231
+ mount(/*#__PURE__*/React.createElement(FormBuilder, {
232
+ ref: ref,
227
233
  validationErrors: [{}],
228
234
  config: {
229
235
  fields: {
@@ -235,9 +241,11 @@ describe('<FormBuilder />', () => {
235
241
  }
236
242
  }
237
243
  },
238
- handleUpdate
239
- });
240
- builder.actionListener.notify = () => ({
244
+ name: "foo",
245
+ id: "foo",
246
+ handleUpdate: handleUpdate
247
+ }));
248
+ ref.current.actionListener.notify = () => ({
241
249
  formData: {
242
250
  foo: 'bar'
243
251
  },
@@ -248,7 +256,7 @@ describe('<FormBuilder />', () => {
248
256
  });
249
257
 
250
258
  // Trigger update
251
- builder.elementChangeHandler('foo', 'bar');
259
+ ref.current.elementChangeHandler('foo', 'bar');
252
260
 
253
261
  // Test
254
262
  expect(handleUpdate).toHaveBeenCalledWith({
@@ -6,7 +6,6 @@ const edgeBorderWidth = 3;
6
6
  const edgeOffsetHorizontal = themeVariables.gap.xbig;
7
7
  const edgeOffsetVertical = themeVariables.gap.xxbig;
8
8
  export default css({
9
- position: 'relative',
10
9
  height: '90%',
11
10
  width: '100%',
12
11
  ':before,:after,>:before,>:after': {
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-ui-shared",
3
- "version": "7.30.0-alpha.8",
3
+ "version": "7.30.0-alpha.9",
4
4
  "description": "Shopgate's shared UI components.",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
- "@shopgate/pwa-ui-ios": "7.30.0-alpha.8",
9
- "@shopgate/pwa-ui-material": "7.30.0-alpha.8",
8
+ "@shopgate/pwa-ui-ios": "7.30.0-alpha.9",
9
+ "@shopgate/pwa-ui-material": "7.30.0-alpha.9",
10
10
  "react-day-picker": "^7.4.8"
11
11
  },
12
12
  "devDependencies": {
13
- "@shopgate/pwa-common": "7.30.0-alpha.8",
14
- "@shopgate/pwa-common-commerce": "7.30.0-alpha.8",
13
+ "@shopgate/pwa-common": "7.30.0-alpha.9",
14
+ "@shopgate/pwa-common-commerce": "7.30.0-alpha.9",
15
15
  "classnames": "2.5.1",
16
16
  "react": "~16.14.0"
17
17
  },