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

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 (189) hide show
  1. package/AccordionContainer/index.js +17 -11
  2. package/AccordionContainer/spec.js +12 -3
  3. package/ActionButton/index.js +51 -32
  4. package/ActionButton/spec.js +13 -5
  5. package/AddToCartButton/index.js +44 -33
  6. package/AddToCartButton/mock.js +20 -8
  7. package/AddToCartButton/spec.js +29 -14
  8. package/Availability/index.js +5 -3
  9. package/Availability/spec.js +6 -5
  10. package/Button/index.js +73 -58
  11. package/Button/spec.js +16 -10
  12. package/ButtonLink/index.js +20 -12
  13. package/ButtonLink/spec.js +5 -3
  14. package/Card/index.js +5 -3
  15. package/CardList/components/Item/index.js +5 -3
  16. package/CardList/index.js +21 -12
  17. package/CartTotalLine/components/Amount/index.js +10 -8
  18. package/CartTotalLine/components/Hint/index.js +7 -5
  19. package/CartTotalLine/components/Label/index.js +12 -10
  20. package/CartTotalLine/components/Spacer/index.js +5 -3
  21. package/CartTotalLine/index.js +5 -3
  22. package/Checkbox/index.js +6 -5
  23. package/Chip/index.js +28 -22
  24. package/Chip/spec.js +9 -6
  25. package/ContextMenu/ContextMenuProvider.js +5 -3
  26. package/ContextMenu/components/Item/index.js +14 -11
  27. package/ContextMenu/components/Position/index.js +20 -12
  28. package/ContextMenu/index.js +54 -44
  29. package/ContextMenu/spec.js +31 -20
  30. package/Dialog/components/HtmlContentDialog/index.js +9 -7
  31. package/Dialog/components/HtmlContentDialog/spec.js +9 -6
  32. package/Dialog/components/PipelineErrorDialog/index.js +106 -47
  33. package/Dialog/components/PipelineErrorDialog/spec.js +5 -4
  34. package/Dialog/components/TextMessageDialog/index.js +9 -7
  35. package/Dialog/components/TextMessageDialog/spec.js +9 -6
  36. package/Dialog/components/VariantSelectModal/index.js +7 -5
  37. package/Dialog/components/VariantSelectModal/spec.js +6 -3
  38. package/Dialog/index.js +12 -8
  39. package/Dialog/spec.js +7 -6
  40. package/DiscountBadge/index.js +10 -8
  41. package/DiscountBadge/spec.js +3 -2
  42. package/FavoritesButton/index.js +40 -31
  43. package/FavoritesButton/spec.js +7 -3
  44. package/Form/Builder/classes/ActionListener/index.js +400 -401
  45. package/Form/Builder/components/CheckboxElement.js +13 -5
  46. package/Form/Builder/components/CountryElement.js +13 -5
  47. package/Form/Builder/components/ProvinceElement.js +13 -5
  48. package/Form/Builder/components/RadioElement.js +19 -11
  49. package/Form/Builder/components/SelectElement.js +26 -16
  50. package/Form/Builder/components/TextElement.js +13 -5
  51. package/Form/Builder/index.js +70 -60
  52. package/Form/Builder/spec.js +27 -18
  53. package/Form/Checkbox/index.js +31 -21
  54. package/Form/InfoField/index.js +19 -12
  55. package/Form/InfoField/spec.js +4 -1
  56. package/Form/Password/index.js +22 -15
  57. package/Form/Password/spec.js +10 -5
  58. package/Form/RadioGroup/components/Item/index.js +34 -25
  59. package/Form/RadioGroup/index.js +37 -28
  60. package/Form/RadioGroup/spec.js +45 -31
  61. package/Form/Select/index.js +52 -43
  62. package/Form/Select/spec.js +5 -2
  63. package/Form/SelectContextChoices/index.js +26 -22
  64. package/Form/SelectContextChoices/spec.js +4 -1
  65. package/Form/TextField/index.js +40 -27
  66. package/Form/TextField/spec.js +34 -21
  67. package/Form/index.js +23 -15
  68. package/FormElement/components/ErrorText/index.js +7 -5
  69. package/FormElement/components/Label/index.js +6 -4
  70. package/FormElement/components/Placeholder/index.js +7 -5
  71. package/FormElement/components/Underline/index.js +8 -6
  72. package/FormElement/index.js +62 -46
  73. package/FormElement/spec.js +10 -9
  74. package/Glow/index.js +30 -22
  75. package/Glow/spec.js +6 -1
  76. package/IndicatorCircle/index.js +10 -8
  77. package/IndicatorCircle/spec.js +3 -2
  78. package/LoadingIndicator/index.js +8 -6
  79. package/Manufacturer/index.js +9 -7
  80. package/MessageBar/index.js +20 -17
  81. package/MessageBar/spec.js +6 -5
  82. package/NoResults/components/Icon/index.js +134 -110
  83. package/NoResults/index.js +27 -21
  84. package/Placeholder/index.js +13 -5
  85. package/PlaceholderLabel/index.js +2 -1
  86. package/PlaceholderLabel/spec.js +13 -6
  87. package/PlaceholderParagraph/index.js +13 -12
  88. package/PlaceholderParagraph/spec.js +13 -6
  89. package/Price/index.js +46 -28
  90. package/PriceInfo/index.js +2 -1
  91. package/PriceStriked/index.js +41 -29
  92. package/ProductProperties/index.js +13 -10
  93. package/ProgressBar/index.js +28 -19
  94. package/ProgressBar/spec.js +2 -1
  95. package/RadioButton/index.js +6 -5
  96. package/RadioButton/spec.js +3 -2
  97. package/RatingNumber/index.js +2 -1
  98. package/RatingStars/index.js +50 -34
  99. package/RatingStars/spec.js +7 -6
  100. package/Ripple/components/RippleAnimation/index.js +48 -52
  101. package/Ripple/index.js +72 -62
  102. package/RippleButton/index.js +44 -27
  103. package/RippleButton/spec.js +20 -13
  104. package/ScannerOverlay/components/CameraOverlay/index.js +8 -5
  105. package/ScannerOverlay/components/CameraOverlay/style.js +0 -1
  106. package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +25 -21
  107. package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +7 -5
  108. package/ScannerOverlay/components/ScannerBar/index.js +17 -12
  109. package/ScannerOverlay/index.js +24 -15
  110. package/Sheet/components/Header/components/SearchBar/index.js +35 -28
  111. package/Sheet/components/Header/components/SearchBar/spec.js +2 -1
  112. package/Sheet/components/Header/index.js +47 -34
  113. package/Sheet/components/Header/spec.js +2 -1
  114. package/Sheet/index.js +80 -65
  115. package/Sheet/spec.js +27 -14
  116. package/TaxDisclaimer/index.js +13 -10
  117. package/TaxDisclaimer/spec.js +3 -2
  118. package/TextField/components/ErrorText/index.js +7 -5
  119. package/TextField/components/FormElement/index.js +4 -3
  120. package/TextField/components/Hint/index.js +7 -5
  121. package/TextField/components/Label/index.js +6 -4
  122. package/TextField/components/Underline/index.js +8 -6
  123. package/TextField/index.js +102 -85
  124. package/TextField/spec.js +37 -23
  125. package/ToggleIcon/index.js +23 -15
  126. package/ToggleIcon/spec.js +12 -8
  127. package/icons/AccountBoxIcon.js +5 -4
  128. package/icons/AddMoreIcon.js +5 -4
  129. package/icons/ArrowDropIcon.js +5 -4
  130. package/icons/ArrowIcon.js +5 -4
  131. package/icons/BarcodeScannerIcon.js +5 -4
  132. package/icons/BoxIcon.js +5 -4
  133. package/icons/BrowseIcon.js +5 -4
  134. package/icons/BurgerIcon.js +5 -4
  135. package/icons/CalendarIcon.js +5 -5
  136. package/icons/CartCouponIcon.js +5 -4
  137. package/icons/CartIcon.js +5 -4
  138. package/icons/CartPlusIcon.js +5 -4
  139. package/icons/CheckIcon.js +5 -4
  140. package/icons/CheckedIcon.js +5 -4
  141. package/icons/ChevronIcon.js +5 -4
  142. package/icons/CreditCardIcon.js +5 -4
  143. package/icons/CrossIcon.js +5 -4
  144. package/icons/DescriptionIcon.js +5 -4
  145. package/icons/FilterIcon.js +5 -4
  146. package/icons/FlashDisabledIcon.js +5 -4
  147. package/icons/FlashEnabledIcon.js +5 -4
  148. package/icons/GridIcon.js +5 -4
  149. package/icons/HeartIcon.js +5 -4
  150. package/icons/HeartOutlineIcon.js +5 -4
  151. package/icons/HeartPlusIcon.js +5 -4
  152. package/icons/HeartPlusOutlineIcon.js +5 -4
  153. package/icons/HomeIcon.js +5 -4
  154. package/icons/InfoIcon.js +5 -4
  155. package/icons/InfoOutlineIcon.js +5 -4
  156. package/icons/ListIcon.js +5 -4
  157. package/icons/LocalShippingIcon.js +5 -4
  158. package/icons/LocationIcon.js +5 -4
  159. package/icons/LocatorIcon.js +5 -4
  160. package/icons/LockIcon.js +5 -4
  161. package/icons/LogoutIcon.js +5 -4
  162. package/icons/MagnifierIcon.js +5 -4
  163. package/icons/MapMarkerIcon.js +5 -4
  164. package/icons/MoreIcon.js +5 -4
  165. package/icons/MoreVertIcon.js +5 -4
  166. package/icons/NotificationIcon.js +5 -4
  167. package/icons/PersonIcon.js +5 -4
  168. package/icons/PhoneIcon.js +5 -4
  169. package/icons/PlaceholderIcon.js +5 -4
  170. package/icons/RadioCheckedIcon.js +5 -4
  171. package/icons/RadioUncheckedIcon.js +5 -4
  172. package/icons/SecurityIcon.js +5 -4
  173. package/icons/ShippingMethodIcon.js +5 -4
  174. package/icons/ShoppingCartIcon.js +5 -4
  175. package/icons/SortIcon.js +5 -4
  176. package/icons/StarHalfIcon.js +5 -4
  177. package/icons/StarIcon.js +5 -4
  178. package/icons/StarOutlineIcon.js +5 -4
  179. package/icons/StopIcon.js +5 -4
  180. package/icons/TickIcon.js +5 -4
  181. package/icons/TimeIcon.js +5 -4
  182. package/icons/TrashIcon.js +5 -4
  183. package/icons/TrashOutlineIcon.js +5 -4
  184. package/icons/UncheckedIcon.js +5 -4
  185. package/icons/ViewListIcon.js +5 -4
  186. package/icons/VisibilityIcon.js +5 -4
  187. package/icons/VisibilityOffIcon.js +5 -4
  188. package/icons/WarningIcon.js +5 -4
  189. package/package.json +7 -8
@@ -1,41 +1,47 @@
1
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
1
2
  import { Component } from 'react';
2
3
  import PropTypes from 'prop-types';
3
4
 
4
5
  /**
5
6
  * The Accordion container component.
6
7
  */
7
- class AccordionContainer extends Component {
8
+ let AccordionContainer = /*#__PURE__*/function (_Component) {
8
9
  /**
9
10
  * Init
10
11
  * @param {Object} props Props
11
12
  */
12
- constructor(props) {
13
- super(props);
14
- this.open = () => {
15
- this.setState({
13
+ function AccordionContainer(props) {
14
+ var _this;
15
+ _this = _Component.call(this, props) || this;
16
+ _this.open = () => {
17
+ _this.setState({
16
18
  open: true
17
19
  });
18
20
  };
19
- this.close = () => {
20
- this.setState({
21
+ _this.close = () => {
22
+ _this.setState({
21
23
  open: false
22
24
  });
23
25
  };
24
- this.state = {
26
+ _this.state = {
25
27
  open: props.open
26
28
  };
29
+ return _this;
27
30
  }
31
+ _inheritsLoose(AccordionContainer, _Component);
32
+ var _proto = AccordionContainer.prototype;
28
33
  /**
29
34
  * @returns {JSX}
30
35
  */
31
- render() {
36
+ _proto.render = function render() {
32
37
  return this.props.children({
33
38
  handleClose: this.close,
34
39
  open: this.state.open,
35
40
  handleOpen: this.open
36
41
  });
37
- }
38
- }
42
+ };
43
+ return AccordionContainer;
44
+ }(Component);
39
45
  AccordionContainer.defaultProps = {
40
46
  open: false
41
47
  };
@@ -5,10 +5,15 @@ import AccordionContainer from "./index";
5
5
  /**
6
6
  * @returns {JSX}
7
7
  */
8
- const Child = () => /*#__PURE__*/React.createElement("div", null);
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const Child = () => /*#__PURE__*/_jsx("div", {});
9
10
  describe('<AccordionContainer />', () => {
10
11
  it('should render children with props', () => {
11
- const wrapper = shallow(/*#__PURE__*/React.createElement(AccordionContainer, null, props => /*#__PURE__*/React.createElement(Child, props)));
12
+ const wrapper = shallow(/*#__PURE__*/_jsx(AccordionContainer, {
13
+ children: props => /*#__PURE__*/_jsx(Child, {
14
+ ...props
15
+ })
16
+ }));
12
17
  const props = wrapper.find('Child').props();
13
18
  expect(wrapper).toMatchSnapshot();
14
19
  expect(props.open).toEqual(false);
@@ -16,7 +21,11 @@ describe('<AccordionContainer />', () => {
16
21
  expect(typeof props.handleClose).toEqual('function');
17
22
  });
18
23
  it('should update children props when state changes', () => {
19
- const wrapper = shallow(/*#__PURE__*/React.createElement(AccordionContainer, null, props => /*#__PURE__*/React.createElement(Child, props)));
24
+ const wrapper = shallow(/*#__PURE__*/_jsx(AccordionContainer, {
25
+ children: props => /*#__PURE__*/_jsx(Child, {
26
+ ...props
27
+ })
28
+ }));
20
29
  wrapper.setState({
21
30
  open: true
22
31
  });
@@ -1,4 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/extends";
1
+ import _createClass from "@babel/runtime/helpers/createClass";
2
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
2
3
  import React, { Component } from 'react';
3
4
  import PropTypes from 'prop-types';
4
5
  import IndicatorCircle from "../IndicatorCircle";
@@ -8,54 +9,71 @@ import styles from "./style";
8
9
  /**
9
10
  * The action button component.
10
11
  */
11
- class ActionButton extends Component {
12
- constructor(...args) {
13
- super(...args);
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ let ActionButton = /*#__PURE__*/function (_Component) {
14
+ function ActionButton(...args) {
15
+ var _this;
16
+ _this = _Component.call.apply(_Component, [this].concat(args)) || this;
14
17
  /**
15
18
  * The click handler
16
19
  * @param {Object} event The event object for the click handler
17
20
  */
18
- this.handleClick = event => {
21
+ _this.handleClick = event => {
19
22
  const {
20
23
  clickDelay
21
- } = this.constructor;
24
+ } = _this.constructor;
25
+ if (_this.props.disableClickDelay) {
26
+ _this.props.onClick(event);
27
+ return;
28
+ }
22
29
  setTimeout(() => {
23
- this.props.onClick(event);
30
+ _this.props.onClick(event);
24
31
  }, clickDelay);
25
32
  };
33
+ return _this;
26
34
  }
27
- /**
28
- * Getter for the calculated button props.
29
- * @returns {Object}
30
- */
31
- get buttonProps() {
32
- const buttonProps = {
33
- className: this.props.className,
34
- disabled: this.props.disabled,
35
- flat: this.props.flat,
36
- type: this.props.type
37
- };
38
- return buttonProps;
39
- }
35
+ _inheritsLoose(ActionButton, _Component);
36
+ var _proto = ActionButton.prototype;
40
37
  /**
41
38
  * The render function.
42
39
  * @returns {JSX}
43
40
  */
44
- render() {
41
+ _proto.render = function render() {
45
42
  const containerClass = this.props.noGap ? styles.noGapContainer : styles.container;
46
43
  if (this.props.loading) {
47
- return /*#__PURE__*/React.createElement("div", {
48
- className: styles.containerCircle
49
- }, /*#__PURE__*/React.createElement(IndicatorCircle, null));
44
+ return /*#__PURE__*/_jsx("div", {
45
+ className: styles.containerCircle,
46
+ children: /*#__PURE__*/_jsx(IndicatorCircle, {})
47
+ });
50
48
  }
51
- return /*#__PURE__*/React.createElement("div", {
49
+ return /*#__PURE__*/_jsx("div", {
52
50
  className: `ui-shared__action-button ${containerClass}`,
53
- "data-test-id": this.props.testId
54
- }, /*#__PURE__*/React.createElement(RippleButton, _extends({}, this.buttonProps, {
55
- onClick: this.handleClick
56
- }), this.props.children));
57
- }
58
- }
51
+ "data-test-id": this.props.testId,
52
+ children: /*#__PURE__*/_jsx(RippleButton, {
53
+ ...this.buttonProps,
54
+ onClick: this.handleClick,
55
+ children: this.props.children
56
+ })
57
+ });
58
+ };
59
+ return _createClass(ActionButton, [{
60
+ key: "buttonProps",
61
+ get:
62
+ /**
63
+ * Getter for the calculated button props.
64
+ * @returns {Object}
65
+ */
66
+ function () {
67
+ const buttonProps = {
68
+ className: this.props.className,
69
+ disabled: this.props.disabled,
70
+ flat: this.props.flat,
71
+ type: this.props.type
72
+ };
73
+ return buttonProps;
74
+ }
75
+ }]);
76
+ }(Component);
59
77
  ActionButton.clickDelay = 300;
60
78
  ActionButton.defaultProps = {
61
79
  ...RippleButton.defaultProps,
@@ -63,6 +81,7 @@ ActionButton.defaultProps = {
63
81
  type: 'primary',
64
82
  flat: true,
65
83
  noGap: false,
66
- testId: null
84
+ testId: null,
85
+ disableClickDelay: false
67
86
  };
68
87
  export default ActionButton;
@@ -3,6 +3,7 @@ import { shallow } from 'enzyme';
3
3
  import IndicatorCircle from "../IndicatorCircle";
4
4
  import RippleButton from "../RippleButton";
5
5
  import ActionButton from "./index";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
6
7
  describe('<ActionButton />', () => {
7
8
  let renderedElement;
8
9
  let mockOnClick;
@@ -13,7 +14,10 @@ describe('<ActionButton />', () => {
13
14
  * @param {Object} props The component props.
14
15
  */
15
16
  const renderComponent = (props = {}) => {
16
- renderedElement = shallow(/*#__PURE__*/React.createElement(ActionButton, props, "Action Button"));
17
+ renderedElement = shallow(/*#__PURE__*/_jsx(ActionButton, {
18
+ ...props,
19
+ children: "Action Button"
20
+ }));
17
21
  };
18
22
  describe('Given the component was mounted to the DOM', () => {
19
23
  beforeEach(() => {
@@ -44,17 +48,21 @@ describe('<ActionButton />', () => {
44
48
  });
45
49
  });
46
50
  describe('Given the component gets clicked', () => {
51
+ let timeoutSpy;
47
52
  beforeEach(() => {
53
+ timeoutSpy = jest.spyOn(global, 'setTimeout');
48
54
  renderedElement.find(RippleButton).simulate('click');
49
55
  });
56
+ afterEach(() => {
57
+ timeoutSpy.mockRestore();
58
+ });
50
59
  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);
60
+ expect(timeoutSpy).toHaveBeenCalledTimes(1);
61
+ expect(timeoutSpy.mock.calls[0][1]).toBe(ActionButton.clickDelay);
53
62
  });
54
63
  it('should eventually call the onClick handler', () => {
55
64
  jest.runOnlyPendingTimers();
56
- expect(mockOnClick).toBeCalled();
57
- expect(mockOnClick.mock.calls.length).toBe(1);
65
+ expect(mockOnClick).toHaveBeenCalledTimes(1);
58
66
  });
59
67
  });
60
68
  });
@@ -1,3 +1,4 @@
1
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
1
2
  import React, { Component } from 'react';
2
3
  import PropTypes from 'prop-types';
3
4
  import { themeConfig } from '@shopgate/pwa-common/helpers/config';
@@ -10,13 +11,15 @@ import styles from "./style";
10
11
  /**
11
12
  * AddToCartButton component.
12
13
  */
13
- class AddToCartButton extends Component {
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
+ let AddToCartButton = /*#__PURE__*/function (_Component) {
14
16
  /**
15
17
  * Constructor for the AddToCartButton component.
16
18
  * @param {Object} props Props for the component.
17
19
  */
18
- constructor(props) {
19
- super(props);
20
+ function AddToCartButton(props) {
21
+ var _this;
22
+ _this = _Component.call(this, props) || this;
20
23
  /**
21
24
  * Handles the button click.
22
25
  * - Show checkmark.
@@ -25,24 +28,24 @@ class AddToCartButton extends Component {
25
28
  * - Show cart icon again.
26
29
  * @param {Event} e Event
27
30
  */
28
- this.handleClick = e => {
31
+ _this.handleClick = e => {
29
32
  // Ignore clicks when check mark or loading spinner is shown or the button is disabled.
30
- if (this.state.showCheckmark || this.props.isLoading || this.props.isDisabled) {
33
+ if (_this.state.showCheckmark || _this.props.isLoading || _this.props.isDisabled) {
31
34
  return;
32
35
  }
33
36
 
34
37
  /** */
35
38
  const handleCompletion = () => {
36
- this.setState({
39
+ _this.setState({
37
40
  showCheckmark: true
38
41
  });
39
42
  setTimeout(() => {
40
- this.setState({
43
+ _this.setState({
41
44
  showCheckmark: false
42
45
  });
43
46
  }, 900);
44
47
  };
45
- const result = this.props.onClick(e);
48
+ const result = _this.props.onClick(e);
46
49
  if (result === false) {
47
50
  // Do not trigger animation when adding to cart was aborted by the parent component (PWA-2764)
48
51
  return;
@@ -68,23 +71,26 @@ class AddToCartButton extends Component {
68
71
  * This is caused by CSS animations that get re-applied when
69
72
  * setting an element from hidden (display: none) to visible.
70
73
  */
71
- this.handleCartAnimationEnd = () => {
72
- if (this.state.showCheckmark === false) {
73
- this.setState({
74
+ _this.handleCartAnimationEnd = () => {
75
+ if (_this.state.showCheckmark === false) {
76
+ _this.setState({
74
77
  showCheckmark: null
75
78
  });
76
79
  }
77
- this.props.onReset();
80
+ _this.props.onReset();
78
81
  };
79
- this.state = {
82
+ _this.state = {
80
83
  showCheckmark: null
81
84
  };
85
+ return _this;
82
86
  }
87
+ _inheritsLoose(AddToCartButton, _Component);
88
+ var _proto = AddToCartButton.prototype;
83
89
  /**
84
90
  * Renders the component
85
91
  * @returns {JSX}
86
92
  */
87
- render() {
93
+ _proto.render = function render() {
88
94
  // Set initial base styles
89
95
  let buttonStyle = styles.buttonReady;
90
96
  let tickIconStyle = styles.icon;
@@ -162,7 +168,7 @@ class AddToCartButton extends Component {
162
168
  if (this.props.noShadow) {
163
169
  className = styles.buttonWrapperNoShadow(this.props.buttonSize, this.props.iconSize);
164
170
  }
165
- return /*#__PURE__*/React.createElement("button", {
171
+ return /*#__PURE__*/_jsxs("button", {
166
172
  "data-test-id": "addToCartButton",
167
173
  className: `ui-shared__add-to-cart-button ${this.props.className} ${className} ${buttonStyle}`,
168
174
  onClick: this.handleClick,
@@ -170,24 +176,29 @@ class AddToCartButton extends Component {
170
176
  "aria-label": this.props['aria-label'],
171
177
  "aria-disabled": this.props.isDisabled,
172
178
  ref: this.props.forwardedRef,
173
- type: "button"
174
- }, this.props.isLoading && /*#__PURE__*/React.createElement("div", {
175
- className: `${styles.icon} ${styles.spinnerIcon}`,
176
- style: spinnerInlineStyle
177
- }, /*#__PURE__*/React.createElement(IndicatorCircle, {
178
- color: themeConfig.colors.primaryContrast,
179
- strokeWidth: 5,
180
- paused: !this.props.isLoading
181
- })), /*#__PURE__*/React.createElement("div", {
182
- className: tickIconStyle,
183
- style: tickInlineStyle
184
- }, /*#__PURE__*/React.createElement(TickIcon, null)), /*#__PURE__*/React.createElement("div", {
185
- className: cartPlusIconStyle,
186
- style: cartInlineStyle,
187
- onAnimationEnd: this.handleCartAnimationEnd
188
- }, /*#__PURE__*/React.createElement(CartPlusIcon, null)));
189
- }
190
- }
179
+ type: "button",
180
+ children: [this.props.isLoading && /*#__PURE__*/_jsx("div", {
181
+ className: `${styles.icon} ${styles.spinnerIcon}`,
182
+ style: spinnerInlineStyle,
183
+ children: /*#__PURE__*/_jsx(IndicatorCircle, {
184
+ color: themeConfig.colors.primaryContrast,
185
+ strokeWidth: 5,
186
+ paused: !this.props.isLoading
187
+ })
188
+ }), /*#__PURE__*/_jsx("div", {
189
+ className: tickIconStyle,
190
+ style: tickInlineStyle,
191
+ children: /*#__PURE__*/_jsx(TickIcon, {})
192
+ }), /*#__PURE__*/_jsx("div", {
193
+ className: cartPlusIconStyle,
194
+ style: cartInlineStyle,
195
+ onAnimationEnd: this.handleCartAnimationEnd,
196
+ children: /*#__PURE__*/_jsx(CartPlusIcon, {})
197
+ })]
198
+ });
199
+ };
200
+ return AddToCartButton;
201
+ }(Component);
191
202
  AddToCartButton.defaultProps = {
192
203
  'aria-hidden': false,
193
204
  'aria-label': null,
@@ -1,3 +1,4 @@
1
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
1
2
  var _Class;
2
3
  import React, { Component } from 'react';
3
4
  import PropTypes from 'prop-types';
@@ -7,17 +8,28 @@ import PropTypes from 'prop-types';
7
8
  * @deprecated
8
9
  */
9
10
  // eslint-disable-next-line react/prefer-stateless-function
10
- export const MockedAddToCartButton = (_Class = class MockedAddToCartButton extends Component {
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ export const MockedAddToCartButton = (_Class = /*#__PURE__*/function (_Component) {
13
+ function MockedAddToCartButton() {
14
+ return _Component.apply(this, arguments) || this;
15
+ }
16
+ _inheritsLoose(MockedAddToCartButton, _Component);
17
+ var _proto = MockedAddToCartButton.prototype;
11
18
  /**
12
19
  * Renders mocked button.
13
20
  * @return {JSX}
14
21
  */
15
- render() {
16
- return /*#__PURE__*/React.createElement("button", {
17
- onClick: this.props.onClick,
18
- type: "button"
19
- });
20
- }
21
- }, _Class.defaultProps = {
22
+ _proto.render = function render() {
23
+ return (
24
+ /*#__PURE__*/
25
+ // eslint-disable-next-line jsx-a11y/control-has-associated-label
26
+ _jsx("button", {
27
+ onClick: this.props.onClick,
28
+ type: "button"
29
+ })
30
+ );
31
+ };
32
+ return MockedAddToCartButton;
33
+ }(Component), _Class.defaultProps = {
22
34
  onClick: () => {}
23
35
  }, _Class);
@@ -1,52 +1,67 @@
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
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ const flushMicrotasks = () => Promise.resolve();
11
12
  describe('<AddToCartButton />', () => {
12
13
  it('should render in loading state and should not be clickable', () => {
13
- const spy = jest.fn(() => new Promise(resolve => resolve()));
14
- const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
14
+ const spy = jest.fn(() => Promise.resolve());
15
+ const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
15
16
  onClick: spy,
16
17
  isLoading: true,
17
18
  isOrderable: true,
18
19
  isDisabled: false
19
20
  }));
21
+
22
+ // Click shouldn’t fire when loading
20
23
  wrapper.find('button').prop('onClick')();
21
24
  expect(wrapper).toMatchSnapshot();
22
25
  expect(spy).toHaveBeenCalledTimes(0);
23
26
  });
24
27
  it('should render with checkmark icon and should not be clickable the second time', async () => {
25
- const spy = jest.fn(() => new Promise(resolve => resolve()));
26
- const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
28
+ const spy = jest.fn(() => Promise.resolve());
29
+ const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
27
30
  onClick: spy,
28
31
  isLoading: false,
29
32
  isOrderable: true,
30
33
  isDisabled: false
31
34
  }));
32
- wrapper.find('button').prop('onClick')();
35
+
36
+ // First click triggers async work
37
+ await act(async () => {
38
+ wrapper.find('button').prop('onClick')();
39
+ await flushMicrotasks();
40
+ });
33
41
  wrapper.update();
34
- await flushPromises();
35
- wrapper.find('button').prop('onClick')();
42
+
43
+ // Second click should be ignored
44
+ await act(async () => {
45
+ wrapper.find('button').prop('onClick')();
46
+ await flushMicrotasks();
47
+ });
36
48
  wrapper.update();
37
- await flushPromises();
38
49
  expect(wrapper).toMatchSnapshot();
39
50
  expect(spy).toHaveBeenCalledTimes(1);
40
51
  });
41
- it('should render with cart icon and should be clickable', () => {
42
- const spy = jest.fn(() => new Promise(resolve => resolve()));
43
- const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
52
+ it('should render with cart icon and should be clickable', async () => {
53
+ const spy = jest.fn(() => Promise.resolve());
54
+ const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
44
55
  onClick: spy,
45
56
  isLoading: false,
46
57
  isOrderable: true,
47
58
  isDisabled: false
48
59
  }));
49
- wrapper.find('button').prop('onClick')();
60
+ await act(async () => {
61
+ wrapper.find('button').prop('onClick')();
62
+ await flushMicrotasks();
63
+ });
64
+ wrapper.update();
50
65
  expect(wrapper).toMatchSnapshot();
51
66
  expect(spy).toHaveBeenCalledTimes(1);
52
67
  });
@@ -13,6 +13,7 @@ import styles from "./style";
13
13
  * @param {string} [props.className] CSS classes
14
14
  * @return {JSX}
15
15
  */
16
+ import { jsx as _jsx } from "react/jsx-runtime";
16
17
  const Availability = ({
17
18
  text,
18
19
  state,
@@ -29,10 +30,11 @@ const Availability = ({
29
30
  if (state === AVAILABILITY_STATE_ALERT) {
30
31
  style = styles.stateAlert;
31
32
  }
32
- return /*#__PURE__*/React.createElement("div", {
33
+ return /*#__PURE__*/_jsx("div", {
33
34
  className: `ui-shared__availability ${className} ${style}`,
34
- "data-test-id": `availabilityText: ${text}`
35
- }, text);
35
+ "data-test-id": `availabilityText: ${text}`,
36
+ children: text
37
+ });
36
38
  };
37
39
  Availability.defaultProps = {
38
40
  className: '',
@@ -2,22 +2,23 @@ import React from 'react';
2
2
  import { mount } from 'enzyme';
3
3
  import { AVAILABILITY_STATE_OK, AVAILABILITY_STATE_WARNING, AVAILABILITY_STATE_ALERT } from '@shopgate/pwa-common-commerce/product/constants';
4
4
  import Availability from "./index";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
5
6
  describe('<Availability />', () => {
6
7
  it('should not render when text is empty', () => {
7
- const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
8
+ const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
8
9
  text: ""
9
10
  }));
10
11
  expect(wrapper).toMatchSnapshot();
11
12
  });
12
13
  it('should not render by default if state is "ok"', () => {
13
- const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
14
+ const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
14
15
  state: AVAILABILITY_STATE_OK,
15
16
  text: "Available"
16
17
  }));
17
18
  expect(wrapper).toMatchSnapshot();
18
19
  });
19
20
  it('should render if state is "ok" when "showWhenAvailable" is set', () => {
20
- const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
21
+ const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
21
22
  state: AVAILABILITY_STATE_OK,
22
23
  text: "Available",
23
24
  showWhenAvailable: true
@@ -25,14 +26,14 @@ describe('<Availability />', () => {
25
26
  expect(wrapper).toMatchSnapshot();
26
27
  });
27
28
  it('should render if state is "warning"', () => {
28
- const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
29
+ const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
29
30
  state: AVAILABILITY_STATE_WARNING,
30
31
  text: "Only 5 left"
31
32
  }));
32
33
  expect(wrapper).toMatchSnapshot();
33
34
  });
34
35
  it('should render if state is "warning"', () => {
35
- const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
36
+ const wrapper = mount(/*#__PURE__*/_jsx(Availability, {
36
37
  state: AVAILABILITY_STATE_ALERT,
37
38
  text: "Out of stock"
38
39
  }));