@shopgate/pwa-ui-shared 6.20.0-beta.1 → 6.20.0-beta.7
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 +7 -4
- package/AccordionContainer/spec.js +2 -2
- package/ActionButton/index.js +7 -7
- package/ActionButton/spec.js +1 -1
- package/AddToCartButton/index.js +7 -6
- package/AddToCartButton/mock.js +3 -3
- package/AddToCartButton/spec.js +1 -1
- package/Availability/index.js +1 -1
- package/Availability/spec.js +1 -1
- package/Button/index.js +7 -7
- package/Button/spec.js +1 -1
- package/ButtonLink/index.js +3 -3
- package/ButtonLink/spec.js +1 -1
- package/Card/index.js +1 -1
- package/CardList/components/Item/index.js +1 -1
- package/CardList/index.js +3 -3
- package/CartTotalLine/components/Amount/index.js +1 -1
- package/CartTotalLine/components/Hint/index.js +1 -1
- package/CartTotalLine/components/Label/index.js +1 -1
- package/CartTotalLine/index.js +1 -1
- package/Checkbox/index.js +2 -2
- package/Chip/index.js +1 -1
- package/Chip/spec.js +1 -1
- package/ClientInformation/index.js +5 -5
- package/ClientInformation/spec.js +1 -1
- package/ContextMenu/components/Item/index.js +2 -2
- package/ContextMenu/components/Item/style.js +5 -1
- package/ContextMenu/components/Position/index.js +4 -4
- package/ContextMenu/index.js +8 -8
- package/ContextMenu/spec.js +3 -3
- package/ContextMenu/style.js +1 -1
- package/Dialog/components/PipelineErrorDialog/index.js +9 -9
- package/Dialog/components/PipelineErrorDialog/spec.js +2 -2
- package/Dialog/components/TextMessageDialog/index.js +1 -1
- package/Dialog/components/TextMessageDialog/spec.js +1 -1
- package/Dialog/components/VariantSelectModal/index.js +1 -1
- package/Dialog/components/VariantSelectModal/spec.js +2 -2
- package/Dialog/constants.js +1 -1
- package/Dialog/index.js +4 -4
- package/Dialog/spec.js +2 -2
- package/DiscountBadge/index.js +1 -1
- package/DiscountBadge/spec.js +1 -1
- package/FavoritesButton/connector.js +2 -2
- package/FavoritesButton/index.js +8 -8
- package/FavoritesButton/spec.js +1 -1
- package/Footer/index.js +9 -9
- package/Footer/index.spec.js +4 -4
- package/Form/Builder/builders/buildCountryList.js +1 -1
- package/Form/Builder/builders/buildFormDefaults.js +1 -1
- package/Form/Builder/builders/buildFormElements.js +2 -2
- package/Form/Builder/builders/buildFormElements.spec.js +1 -1
- package/Form/Builder/builders/buildProvinceList.js +1 -1
- package/Form/Builder/classes/ActionListener/index.js +3 -3
- package/Form/Builder/components/CheckboxElement.js +3 -3
- package/Form/Builder/components/CountryElement.js +3 -3
- package/Form/Builder/components/ProvinceElement.js +3 -3
- package/Form/Builder/components/RadioElement.js +3 -3
- package/Form/Builder/components/SelectElement.js +3 -3
- package/Form/Builder/components/TextElement.js +3 -3
- package/Form/Builder/index.js +8 -8
- package/Form/Builder/spec.js +3 -3
- package/Form/Checkbox/index.js +3 -3
- package/Form/Password/index.js +5 -5
- package/Form/Password/spec.js +1 -1
- package/Form/RadioGroup/components/Item/index.js +3 -3
- package/Form/RadioGroup/index.js +7 -7
- package/Form/RadioGroup/spec.js +2 -2
- package/Form/Select/index.js +5 -5
- package/Form/Select/spec.js +1 -1
- package/Form/TextField/index.js +5 -5
- package/Form/TextField/spec.js +1 -1
- package/Form/index.js +8 -8
- package/FormElement/components/ErrorText/index.js +1 -1
- package/FormElement/components/Label/index.js +1 -1
- package/FormElement/components/Placeholder/index.js +1 -1
- package/FormElement/components/Underline/index.js +1 -1
- package/FormElement/index.js +6 -6
- package/FormElement/spec.js +1 -1
- package/Glow/index.js +6 -6
- package/Glow/spec.js +1 -1
- package/IndicatorCircle/index.js +1 -1
- package/IndicatorCircle/spec.js +1 -1
- package/LoadingIndicator/index.js +1 -1
- package/Manufacturer/index.js +1 -1
- package/MessageBar/index.js +1 -1
- package/MessageBar/spec.js +1 -1
- package/NoResults/components/Icon/index.js +1 -1
- package/NoResults/index.js +1 -1
- package/Placeholder/index.js +3 -3
- package/PlaceholderLabel/index.js +1 -1
- package/PlaceholderLabel/spec.js +1 -1
- package/PlaceholderParagraph/index.js +1 -1
- package/PlaceholderParagraph/spec.js +1 -1
- package/Price/index.js +1 -1
- package/PriceInfo/index.js +1 -1
- package/PriceStriked/index.js +6 -6
- package/ProductProperties/index.js +1 -1
- package/ProductProperties/index.spec.js +1 -1
- package/ProgressBar/index.js +4 -4
- package/ProgressBar/spec.js +1 -1
- package/RadioButton/index.js +1 -1
- package/RadioButton/spec.js +1 -1
- package/RatingNumber/index.js +1 -1
- package/RatingNumber/index.spec.js +2 -2
- package/RatingStars/index.js +5 -5
- package/RatingStars/spec.js +2 -2
- package/Ripple/components/RippleAnimation/index.js +3 -3
- package/Ripple/index.js +16 -16
- package/RippleButton/index.js +7 -7
- package/RippleButton/spec.js +1 -1
- package/ScannerOverlay/components/CameraOverlay/index.js +1 -1
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +1 -1
- package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +1 -1
- package/ScannerOverlay/components/ScannerBar/index.js +1 -1
- package/ScannerOverlay/index.js +7 -7
- package/ScannerOverlay/index.spec.js +1 -1
- package/Sheet/components/Header/components/SearchBar/index.js +2 -2
- package/Sheet/components/Header/components/SearchBar/spec.js +1 -1
- package/Sheet/components/Header/index.js +4 -4
- package/Sheet/components/Header/spec.js +1 -1
- package/Sheet/index.js +10 -10
- package/Sheet/spec.js +2 -2
- package/TaxDisclaimer/index.js +1 -1
- package/TaxDisclaimer/spec.js +2 -2
- package/TextField/components/ErrorText/index.js +1 -1
- package/TextField/components/FormElement/index.js +1 -1
- package/TextField/components/Hint/index.js +1 -1
- package/TextField/components/Label/index.js +2 -2
- package/TextField/components/Underline/index.js +1 -1
- package/TextField/index.js +8 -8
- package/TextField/spec.js +2 -2
- package/ToggleIcon/index.js +5 -5
- package/ToggleIcon/spec.js +1 -1
- package/icons/AccountBoxIcon.js +1 -1
- package/icons/AddMoreIcon.js +1 -1
- package/icons/ArrowDropIcon.js +1 -1
- package/icons/ArrowIcon.js +2 -2
- package/icons/BarcodeScannerIcon.js +1 -1
- package/icons/BoxIcon.js +1 -1
- package/icons/BrowseIcon.js +1 -1
- package/icons/BurgerIcon.js +1 -1
- package/icons/CartCouponIcon.js +1 -1
- package/icons/CartIcon.js +1 -1
- package/icons/CartPlusIcon.js +1 -1
- package/icons/CheckIcon.js +1 -1
- package/icons/CheckedIcon.js +1 -1
- package/icons/ChevronIcon.js +1 -1
- package/icons/CreditCardIcon.js +1 -1
- package/icons/CrossIcon.js +1 -1
- package/icons/DescriptionIcon.js +1 -1
- package/icons/FilterIcon.js +1 -1
- package/icons/FlashDisabledIcon.js +1 -1
- package/icons/FlashEnabledIcon.js +1 -1
- package/icons/GridIcon.js +1 -1
- package/icons/HeartIcon.js +1 -1
- package/icons/HeartOutlineIcon.js +1 -1
- package/icons/HomeIcon.js +1 -1
- package/icons/InfoIcon.js +1 -1
- package/icons/InfoOutlineIcon.js +1 -1
- package/icons/ListIcon.js +1 -1
- package/icons/LocalShippingIcon.js +1 -1
- package/icons/LockIcon.js +1 -1
- package/icons/LogoutIcon.js +1 -1
- package/icons/MagnifierIcon.js +1 -1
- package/icons/MoreIcon.js +1 -1
- package/icons/MoreVertIcon.js +1 -1
- package/icons/PlaceholderIcon.js +1 -1
- package/icons/RadioCheckedIcon.js +1 -1
- package/icons/RadioUncheckedIcon.js +1 -1
- package/icons/SecurityIcon.js +1 -1
- package/icons/ShoppingCartIcon.js +1 -1
- package/icons/SortIcon.js +1 -1
- package/icons/StarHalfIcon.js +1 -1
- package/icons/StarIcon.js +1 -1
- package/icons/StarOutlineIcon.js +1 -1
- package/icons/TickIcon.js +1 -1
- package/icons/TrashIcon.js +1 -1
- package/icons/UncheckedIcon.js +1 -1
- package/icons/ViewListIcon.js +1 -1
- package/icons/VisibilityIcon.js +1 -1
- package/icons/VisibilityOffIcon.js +1 -1
- package/package.json +5 -5
- package/Dialog/components/HtmlContentDialog/index.js +0 -6
- package/Dialog/components/HtmlContentDialog/spec.js +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import clamp from'lodash/clamp';import styles from"./style";/**
|
|
2
2
|
* The Context Menu Position component.
|
|
3
|
-
*/var Position=/*#__PURE__*/function(_Component){_inherits(Position,_Component);/**
|
|
3
|
+
*/var Position=/*#__PURE__*/function(_Component){_inherits(Position,_Component);var _super=_createSuper(Position);/**
|
|
4
4
|
* The Constructor.
|
|
5
5
|
* @param {Object} props The component props.
|
|
6
|
-
*/function Position(props){var _this;_classCallCheck(this,Position);_this=
|
|
6
|
+
*/function Position(props){var _this;_classCallCheck(this,Position);_this=_super.call(this,props);_this.elementRef=null;return _this;}/**
|
|
7
7
|
* Calculate and apply the correct menu position after mounting.
|
|
8
8
|
*/_createClass(Position,[{key:"componentDidMount",value:function componentDidMount(){var offset=this.props.offset;// Get ref to the actual child DOM element and calculate bounding rect.
|
|
9
9
|
var _this$elementRef$chil=_slicedToArray(this.elementRef.childNodes,1),child=_this$elementRef$chil[0];var bounds=child.getBoundingClientRect();// Get window dimensions
|
|
@@ -13,4 +13,4 @@ var left=clamp(offset.left,0,width-bounds.width-gap*2);var top=clamp(offset.top-
|
|
|
13
13
|
this.elementRef.style.left="".concat(left,"px");this.elementRef.style.top="".concat(top,"px");}/**
|
|
14
14
|
* Renders the component.
|
|
15
15
|
* @returns {JSX}
|
|
16
|
-
*/},{key:"render",value:function render(){var _this2=this;return
|
|
16
|
+
*/},{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement("div",{ref:function ref(_ref){_this2.elementRef=_ref;},className:styles.container},this.props.children);}}]);return Position;}(Component);_defineProperty(Position,"defaultProps",{children:null,offset:{top:0,left:0}});export default Position;
|
package/ContextMenu/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component,Children}from'react';import PropTypes from'prop-types';import Portal from'react-portal';import classNames from'classnames';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import MoreVertIcon from"../icons/MoreVertIcon";import Position from"./components/Position";import Item from"./components/Item";import styles from"./style";/**
|
|
2
2
|
* The ContextMenu component.
|
|
3
|
-
*/var ContextMenu=/*#__PURE__*/function(_Component){_inherits(ContextMenu,_Component);/**
|
|
3
|
+
*/var ContextMenu=/*#__PURE__*/function(_Component){_inherits(ContextMenu,_Component);var _super=_createSuper(ContextMenu);/**
|
|
4
4
|
* The Constructor.
|
|
5
5
|
* @param {Object} props The component props.
|
|
6
|
-
*/function ContextMenu(props){var _this;_classCallCheck(this,ContextMenu);_this=
|
|
6
|
+
*/function ContextMenu(props){var _this;_classCallCheck(this,ContextMenu);_this=_super.call(this,props);_defineProperty(_assertThisInitialized(_this),"handleMenuToggle",function(e){if(e){e.preventDefault();e.stopPropagation();}if(_this.elementRef){_this.setState(function(_ref){var active=_ref.active;var state={active:!active};if(_this.props.onStateChange){_this.props.onStateChange(state);}return state;});}});_this.elementRef=null;_this.state={active:props.isOpened};return _this;}/** @inheritDoc */_createClass(ContextMenu,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(_ref2){var isOpened=_ref2.isOpened;if(typeof isOpened==='boolean'&&this.state.active!==isOpened){this.setState({active:isOpened});}}/**
|
|
7
7
|
* Gets the offset of the DOM element.
|
|
8
8
|
* @returns {Object}
|
|
9
|
-
*/
|
|
10
|
-
* Renders the component.
|
|
11
|
-
* @returns {JSX}
|
|
12
|
-
*/value:function render(){var _this2=this;var _this$props=this.props,children=_this$props.children,classes=_this$props.classes;var active=this.state.active;return React.createElement("div",{"data-test-id":"contextMenu",ref:function ref(_ref2){_this2.elementRef=_ref2;},className:classNames(styles.container,classes.container,'ui-shared__context-menu'),"aria-hidden":true},React.createElement("button",{className:classNames(styles.button,classes.button),onClick:this.handleMenuToggle,type:"button","aria-hidden":true},React.createElement(MoreVertIcon,null)),React.createElement(Portal,{isOpened:active},React.createElement("div",{className:styles.overlay},React.createElement(Backdrop,{isVisible:true,level:0,opacity:0,onClick:this.handleMenuToggle}),React.createElement(Position,{offset:this.offset},React.createElement("div",{className:styles.menu},Children.map(children,function(child){return React.cloneElement(child,{closeMenu:_this2.handleMenuToggle});}))))));}},{key:"offset",get:function get(){if(this.elementRef){return this.elementRef.getBoundingClientRect();}return{top:0,left:0};}/**
|
|
9
|
+
*/},{key:"offset",get:function get(){if(this.elementRef){return this.elementRef.getBoundingClientRect();}return{top:0,left:0};}/**
|
|
13
10
|
* Handles any menu toggling interactions.
|
|
14
11
|
* @param {Object} [e] Event
|
|
15
|
-
*/}
|
|
12
|
+
*/},{key:"render",value:/**
|
|
13
|
+
* Renders the component.
|
|
14
|
+
* @returns {JSX}
|
|
15
|
+
*/function render(){var _this2=this;var _this$props=this.props,children=_this$props.children,classes=_this$props.classes,disabled=_this$props.disabled,showToggle=_this$props.showToggle,scroll=_this$props.scroll;var active=this.state.active;var useScroll=typeof scroll==='boolean'&&!!scroll;return/*#__PURE__*/React.createElement("div",{"data-test-id":"contextMenu",ref:function ref(_ref3){_this2.elementRef=_ref3;},className:classNames(styles.container,classes.container,'ui-shared__context-menu'),"aria-hidden":true},showToggle&&/*#__PURE__*/React.createElement("button",{className:classNames(styles.button,classes.button,_defineProperty({},styles.disabled,disabled)),onClick:this.handleMenuToggle,disabled:disabled,type:"button","aria-hidden":true},/*#__PURE__*/React.createElement(MoreVertIcon,null)),/*#__PURE__*/React.createElement(Portal,{isOpened:active},/*#__PURE__*/React.createElement("div",{className:styles.overlay},/*#__PURE__*/React.createElement(Backdrop,{isVisible:true,level:0,opacity:0,onClick:this.handleMenuToggle}),/*#__PURE__*/React.createElement(Position,{offset:this.offset},/*#__PURE__*/React.createElement("div",{className:classNames(styles.menu,_defineProperty({},styles.scrollable,useScroll))},Children.map(children,function(child){if(!child){return null;}return/*#__PURE__*/React.cloneElement(child,{closeMenu:_this2.handleMenuToggle});}))))));}}]);return ContextMenu;}(Component);_defineProperty(ContextMenu,"Item",Item);_defineProperty(ContextMenu,"defaultProps",{children:null,classes:{container:'',button:''},disabled:false,showToggle:true,isOpened:null,onStateChange:null,scroll:null});export default ContextMenu;
|
package/ContextMenu/spec.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from'react';import{mount}from'enzyme';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import ContextMenu from"./index";jest.mock('react-portal',function(){return function(_ref){var isOpened=_ref.isOpened,children=_ref.children;return isOpened?children:null;};});global.requestAnimationFrame=function(fn){return fn();};jest.useFakeTimers();describe('<ContextMenu />',function(){var
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import React from'react';import{mount,shallow}from'enzyme';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import ContextMenu from"./index";jest.mock('react-portal',function(){return function(_ref){var isOpened=_ref.isOpened,children=_ref.children;return isOpened?children:null;};});global.requestAnimationFrame=function(fn){return fn();};jest.useFakeTimers();describe('<ContextMenu />',function(){var mockItemAClick=jest.fn();var mockItemBClick=jest.fn();var numMenuItems=2;describe('Snapshot test',function(){it('should match snapshot',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(ContextMenu,{isOpened:true},/*#__PURE__*/React.createElement(ContextMenu.Item,{onClick:mockItemAClick,className:"menu-active-item"},'Item A'),/*#__PURE__*/React.createElement(ContextMenu.Item,{onClick:mockItemBClick,className:"menu-active-item"},'Item B')));expect(wrapper).toMatchSnapshot();});it('should match snapshot without toggle',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(ContextMenu,{isOpened:true,showToggle:false},/*#__PURE__*/React.createElement(ContextMenu.Item,{onClick:mockItemAClick,className:"menu-active-item"},'Item A')));expect(wrapper).toMatchSnapshot();});});describe.skip('Given the component was mounted to the DOM',function(){var renderedElement;var renderedInstance;/**
|
|
2
|
+
* The view component
|
|
3
|
+
*/var renderComponent=function renderComponent(){renderedElement=mount(/*#__PURE__*/React.createElement(ContextMenu,null,/*#__PURE__*/React.createElement(ContextMenu.Item,{onClick:mockItemAClick},"Item A"),/*#__PURE__*/React.createElement(ContextMenu.Item,{onClick:mockItemBClick},"Item B")));renderedInstance=renderedElement.instance();};beforeEach(renderComponent);it('should match snapshot',function(){expect(renderedElement).toMatchSnapshot();});it('should have active state set to false',function(){expect(renderedInstance.state.active).toBe(false);});it('should render the toggle button',function(){expect(renderedElement.find('button').length).toBe(1);});it('should not render any context menu items',function(){expect(renderedElement.find(ContextMenu.Item).length).toBe(0);});describe('Given toggle button gets clicked',function(){beforeEach(function(){renderedElement.find('button').simulate('click');renderedElement.update();});it('should have active state set to true',function(){expect(renderedInstance.state.active).toBe(true);});it('should render the actual context menu w/ items',function(){expect(renderedElement.find(ContextMenu.Item).length).toBe(numMenuItems);});describe('Given the first item gets clicked',function(){beforeEach(function(){renderedElement.find(ContextMenu.Item).first().children().find('[onClick]').simulate('click');jest.runAllTimers();});it('should call the related click handler',function(){expect(mockItemAClick).toBeCalled();});it('should close the context menu',function(){renderedElement.update();expect(renderedElement.find(ContextMenu.Item).length).toBe(0);});});describe('Given the backdrop gets clicked',function(){beforeEach(function(){renderedElement.find(Backdrop).children().find('[onClick]').simulate('click');});it('should have active state reset to false',function(){expect(renderedInstance.state.active).toBe(false);});it('should close the context menu',function(){expect(renderedElement.find(ContextMenu.Item).length).toBe(0);});});});});});
|
package/ContextMenu/style.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var container=css({position:'relative'}).toString();var button=css({display:'block',fontSize:'1.5rem',outline:0,padding:0}).toString();var overlay=css({position:'fixed',top:0,right:0,bottom:0,left:0,zIndex:10}).toString();var menu=css({position:'absolute',top:0,left:0,padding:"".concat(themeConfig.variables.gap.small,"px 0"),minWidth:130,background:themeConfig.colors.light,borderRadius:2,boxShadow:themeConfig.shadows.contextMenu}).toString();export default{container:container,button:button,menu:menu,overlay:overlay};
|
|
1
|
+
import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var container=css({position:'relative'}).toString();var button=css({display:'block',fontSize:'1.5rem',outline:0,padding:0}).toString();var disabled=css({cursor:'not-allowed'}).toString();var overlay=css({position:'fixed',top:0,right:0,bottom:0,left:0,zIndex:10}).toString();var menu=css({position:'absolute',top:0,left:0,padding:"".concat(themeConfig.variables.gap.small,"px 0"),minWidth:130,background:themeConfig.colors.light,borderRadius:2,boxShadow:themeConfig.shadows.contextMenu}).toString();var scrollable=css({maxHeight:'30vh',overflowY:'auto'}).toString();export default{container:container,button:button,menu:menu,overlay:overlay,disabled:disabled,scrollable:scrollable};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import I18n from'@shopgate/pwa-common/components/I18n';import BasicDialog from"../BasicDialog";/**
|
|
2
2
|
* The number of taps required until the dialog switches to/from developer mode.
|
|
3
3
|
*/var requiredTapsToSwitchModes=10;/**
|
|
4
4
|
* The timeout between repeated tapping on the message (in ms).
|
|
@@ -6,23 +6,23 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
|
|
|
6
6
|
* This component displays a pipeline error dialog.
|
|
7
7
|
* The special behaviour of this message is that the user may tap the message body
|
|
8
8
|
* ten times until it reveals additional information about the error that occurred.
|
|
9
|
-
*/var PipelineErrorDialog=/*#__PURE__*/function(_Component){_inherits(PipelineErrorDialog,_Component);/**
|
|
9
|
+
*/var PipelineErrorDialog=/*#__PURE__*/function(_Component){_inherits(PipelineErrorDialog,_Component);var _super=_createSuper(PipelineErrorDialog);/**
|
|
10
10
|
* Creates the component.
|
|
11
11
|
* @param {Object} props The component props.
|
|
12
|
-
*/function PipelineErrorDialog(props){var _this;_classCallCheck(this,PipelineErrorDialog);_this=
|
|
12
|
+
*/function PipelineErrorDialog(props){var _this;_classCallCheck(this,PipelineErrorDialog);_this=_super.call(this,props);_defineProperty(_assertThisInitialized(_this),"handleTapTimeout",function(){_this.tapCounter=0;});_defineProperty(_assertThisInitialized(_this),"handleClick",function(){_this.tapCounter+=1;if(_this.tapTimeout){// Clear the timeout.
|
|
13
13
|
clearTimeout(_this.tapTimeout);}if(_this.tapCounter>=requiredTapsToSwitchModes){// Switch modes and reset the tap counter.
|
|
14
14
|
_this.tapCounter=0;_this.setState(function(_ref){var devMode=_ref.devMode;return{devMode:!devMode};});}else{_this.tapTimeout=setTimeout(_this.handleTapTimeout,switchModeTapTimeout);}});_defineProperty(_assertThisInitialized(_this),"renderDevErrorMessage",function(){/**
|
|
15
15
|
* Checks the input to be truthy, "0" or "false" and enables it to be rendered then.
|
|
16
16
|
* @param {Object|string|number|boolean} value The value to be checked if it should be rendered.
|
|
17
17
|
* @returns {boolean}
|
|
18
|
-
*/var checkValue=function checkValue(value){return!!value||value===0||value===false;};var params=_this.props.params;return
|
|
18
|
+
*/var checkValue=function checkValue(value){return!!value||value===0||value===false;};var params=_this.props.params;return/*#__PURE__*/React.createElement("div",{"aria-hidden":true},/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("strong",null,"Pipeline:"),/*#__PURE__*/React.createElement("span",null," ".concat(params.pipeline)),/*#__PURE__*/React.createElement("br",null)),checkValue(params.entityId)&&/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("strong",null,"Entity id:"),/*#__PURE__*/React.createElement("span",null," ".concat(params.entityId)),/*#__PURE__*/React.createElement("br",null)),checkValue(params.code)&&/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("strong",null,"Code:"),/*#__PURE__*/React.createElement("span",null," ".concat(params.code)),/*#__PURE__*/React.createElement("br",null)),/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("strong",null,"Message:"),/*#__PURE__*/React.createElement("span",null," ".concat(params.message)),/*#__PURE__*/React.createElement("br",null)),checkValue(params.translated)&&/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("strong",null,"Message Translated:"),/*#__PURE__*/React.createElement("span",null," ".concat(params.translated.toString())),/*#__PURE__*/React.createElement("br",null)),checkValue(params.messageParams)&&/*#__PURE__*/React.createElement("p",null,/*#__PURE__*/React.createElement("strong",null,"Message Params:"),/*#__PURE__*/React.createElement("br",null),/*#__PURE__*/React.createElement("span",null,JSON.stringify(params.messageParams,null,' ')),/*#__PURE__*/React.createElement("br",null)),checkValue(params.request)&&/*#__PURE__*/React.createElement("p",null,/*#__PURE__*/React.createElement("strong",null,"Request Params:"),/*#__PURE__*/React.createElement("br",null),/*#__PURE__*/React.createElement("span",null,JSON.stringify(params.request,null,' ')),/*#__PURE__*/React.createElement("br",null)));});_defineProperty(_assertThisInitialized(_this),"renderUserErrorMessage",function(){var _this$props=_this.props,_this$props$message=_this$props.message,message=_this$props$message===void 0?'':_this$props$message,_this$props$params=_this$props.params,params=_this$props$params===void 0?{}:_this$props$params;return/*#__PURE__*/React.createElement(React.Fragment,null,!!params.translated&&(message||params.message||/*#__PURE__*/React.createElement(I18n.Text,{string:"modal.body_error"})),!params.translated&&/*#__PURE__*/React.createElement(I18n.Text,{string:message||params.message||'modal.body_error',params:params.messageParams||{}}));});_this.tapTimeout=null;_this.tapCounter=0;_this.state={devMode:false// Indicating whether we are in dev mode.
|
|
19
19
|
};return _this;}/**
|
|
20
20
|
* @return {string} The title based on the current state of the dialog.
|
|
21
|
-
*/_createClass(PipelineErrorDialog,[{key:"
|
|
22
|
-
* Renders the error message depending on the current mode.
|
|
23
|
-
* @return {JSX}
|
|
24
|
-
*/value:function render(){return React.createElement(BasicDialog,{title:this.title,actions:this.props.actions},React.createElement("div",{onClick:this.handleClick},this.content));}},{key:"title",get:function get(){return this.state.devMode?'Pipeline Error':'modal.title_error';}/**
|
|
21
|
+
*/_createClass(PipelineErrorDialog,[{key:"title",get:function get(){return this.state.devMode?'Pipeline Error':'modal.title_error';}/**
|
|
25
22
|
* @return {JSX} The content component based on the the current state of the dialog.
|
|
26
23
|
*/},{key:"content",get:function get(){return this.state.devMode?this.renderDevErrorMessage():this.renderUserErrorMessage();}/**
|
|
27
24
|
* Clears the tap counter once the
|
|
28
|
-
*/}
|
|
25
|
+
*/},{key:"render",value:/**
|
|
26
|
+
* Renders the error message depending on the current mode.
|
|
27
|
+
* @return {JSX}
|
|
28
|
+
*/function render(){return/*#__PURE__*/React.createElement(BasicDialog,{title:this.title,actions:this.props.actions},/*#__PURE__*/React.createElement("div",{onClick:this.handleClick},this.content));}}]);return PipelineErrorDialog;}(Component);_defineProperty(PipelineErrorDialog,"defaultProps",{message:''});export default PipelineErrorDialog;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from'react';import{mount}from'enzyme';import PipelineErrorDialog from"./index";describe('<PipelineErrorDialog />',function(){var defaultParams={code:'123',message:'Error message',pipeline:'fakePipeline',request:{}};it('should render with minimal props',function(){var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));expect(wrapper).toMatchSnapshot();});it('should show a custom message if a message is is provided',function(){var message='Custom message';var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],message:message,params:defaultParams}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should switch modes on tap',function(){var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));var numTaps=10;var clickElement=wrapper.find('div[onClick]');// Dev mode should be disabled.
|
|
1
|
+
import React from'react';import{mount}from'enzyme';import PipelineErrorDialog from"./index";describe('<PipelineErrorDialog />',function(){var defaultParams={code:'123',message:'Error message',pipeline:'fakePipeline',request:{}};it('should render with minimal props',function(){var wrapper=mount(/*#__PURE__*/React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));expect(wrapper).toMatchSnapshot();});it('should show a custom message if a message is is provided',function(){var message='Custom message';var wrapper=mount(/*#__PURE__*/React.createElement(PipelineErrorDialog,{actions:[],message:message,params:defaultParams}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should switch modes on tap',function(){var wrapper=mount(/*#__PURE__*/React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));var numTaps=10;var clickElement=wrapper.find('div[onClick]');// Dev mode should be disabled.
|
|
2
2
|
for(var i=0;i<numTaps;i+=1){expect(wrapper.state().devMode).toBe(false);clickElement.simulate('click');}// Dev mode should be enabled.
|
|
3
3
|
for(var _i=0;_i<numTaps;_i+=1){expect(wrapper.state().devMode).toBe(true);clickElement.simulate('click');}// Dev mode should be disabled again.
|
|
4
|
-
expect(wrapper.state().devMode).toBe(false);});it('should not switch modes if tapped too slow',function(){jest.useFakeTimers();var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));var numTaps=10;var numTapsUntilTimeout=Math.round(numTaps/2);var clickElement=wrapper.find('div[onClick]');// Dev mode should be disabled.
|
|
4
|
+
expect(wrapper.state().devMode).toBe(false);});it('should not switch modes if tapped too slow',function(){jest.useFakeTimers();var wrapper=mount(/*#__PURE__*/React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));var numTaps=10;var numTapsUntilTimeout=Math.round(numTaps/2);var clickElement=wrapper.find('div[onClick]');// Dev mode should be disabled.
|
|
5
5
|
expect(wrapper.state().devMode).toBe(false);/**
|
|
6
6
|
* Simulates multiple tap events.
|
|
7
7
|
* @param {number} amount The number of tap events to simulate in a row.
|
|
@@ -3,4 +3,4 @@ import React from'react';import PropTypes from'prop-types';import I18n from'@sho
|
|
|
3
3
|
* This is the default dialog if no type has been specified.
|
|
4
4
|
* @param {Object} props The component properties.
|
|
5
5
|
* @returns {JSX} The rendered component.
|
|
6
|
-
*/var TextMessageDialog=function TextMessageDialog(_ref){var actions=_ref.actions,message=_ref.message,title=_ref.title,params=_ref.params;return
|
|
6
|
+
*/var TextMessageDialog=function TextMessageDialog(_ref){var actions=_ref.actions,message=_ref.message,title=_ref.title,params=_ref.params;return/*#__PURE__*/React.createElement(BasicDialog,{title:title,actions:actions},/*#__PURE__*/React.createElement(I18n.Text,{string:message,params:params}));};TextMessageDialog.defaultProps={title:BasicDialog.defaultProps.title,params:I18n.Text.defaultProps.params};export default TextMessageDialog;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import TextMessageDialog from"./index";var message='This is the message.';var title='This is the title.';describe('<TextMessageDialog />',function(){it('should render with minimal props',function(){var wrapper=shallow(React.createElement(TextMessageDialog,{message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should render with title and message',function(){var wrapper=shallow(React.createElement(TextMessageDialog,{title:title,message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(title);});it('should render with title, message and messageParams',function(){var wrapper=shallow(React.createElement(TextMessageDialog,{title:title,message:"Message with {name}",params:{name:'Placeholder'},actions:[]}));expect(wrapper).toMatchSnapshot();});it('should render the actions',function(){var actions=[{label:'fooAction',action:function action(){}}];var wrapper=shallow(React.createElement(TextMessageDialog,{title:title,message:message,actions:actions}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(actions[0].label);});it('should pass title through',function(){var customTitle
|
|
1
|
+
import React from'react';import{shallow}from'enzyme';import TextMessageDialog from"./index";var message='This is the message.';var title='This is the title.';describe('<TextMessageDialog />',function(){it('should render with minimal props',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(TextMessageDialog,{message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should render with title and message',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(TextMessageDialog,{title:title,message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(title);});it('should render with title, message and messageParams',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(TextMessageDialog,{title:title,message:"Message with {name}",params:{name:'Placeholder'},actions:[]}));expect(wrapper).toMatchSnapshot();});it('should render the actions',function(){var actions=[{label:'fooAction',action:function action(){}}];var wrapper=shallow(/*#__PURE__*/React.createElement(TextMessageDialog,{title:title,message:message,actions:actions}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(actions[0].label);});it('should pass title through',function(){var customTitle=/*#__PURE__*/React.createElement("div",null,"Title");var wrapper=shallow(/*#__PURE__*/React.createElement(TextMessageDialog,{title:customTitle,message:message,params:{},actions:[]}));expect(wrapper.find('BaseDialog').prop('title')).toEqual(customTitle);});});
|
|
@@ -16,4 +16,4 @@ if(confirmAction){orderedActions.push(confirmAction);}return orderedActions;};/*
|
|
|
16
16
|
* @param {Object} params The modal params.
|
|
17
17
|
* @return {JSX} The rendered component.
|
|
18
18
|
* @constructor
|
|
19
|
-
*/var VariantSelectModal=function VariantSelectModal(_ref2){var actions=_ref2.actions,message=_ref2.message,navigate=_ref2.navigate,title=_ref2.title,params=_ref2.params;var parsedActions=reorderActions(actions,params,navigate);return
|
|
19
|
+
*/var VariantSelectModal=function VariantSelectModal(_ref2){var actions=_ref2.actions,message=_ref2.message,navigate=_ref2.navigate,title=_ref2.title,params=_ref2.params;var parsedActions=reorderActions(actions,params,navigate);return/*#__PURE__*/React.createElement(BasicDialog,{title:title,actions:parsedActions},/*#__PURE__*/React.createElement(I18n.Text,{string:message}));};VariantSelectModal.defaultProps={params:{productId:null},title:BasicDialog.defaultProps.title};export default connect(VariantSelectModal);export{VariantSelectModal as UnwrappedVariantSelectModal};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import{UnwrappedVariantSelectModal as VariantSelectModal}from"./index";var message='This is the message.';var title='This is the title.';describe('<VariantSelectModal />',function(){it('should render with minimal props',function(){var wrapper=shallow(React.createElement(VariantSelectModal,{message:message,actions:[],navigate:function navigate(){}}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should render the actions',function(){var mockConfirm=jest.fn();var mockNavigate=jest.fn();/**
|
|
1
|
+
import React from'react';import{shallow}from'enzyme';import{UnwrappedVariantSelectModal as VariantSelectModal}from"./index";var message='This is the message.';var title='This is the title.';describe('<VariantSelectModal />',function(){it('should render with minimal props',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(VariantSelectModal,{message:message,actions:[],navigate:function navigate(){}}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should render the actions',function(){var mockConfirm=jest.fn();var mockNavigate=jest.fn();/**
|
|
2
2
|
* Mocks named function
|
|
3
|
-
*/var onConfirm=function onConfirm(){mockConfirm();};var actions=[{label:'confirm',action:onConfirm},{label:'dismiss',action:function action(){}}];var params={productId:'product_1'};var mockedProps={message:message,title:title,params:params,actions:[].concat(actions),navigate:mockNavigate};var wrapper=shallow(React.createElement(VariantSelectModal,mockedProps));expect(wrapper).toMatchSnapshot();var reordered=wrapper.find('BaseDialog').props().actions;var last=reordered.slice(-1)[0];expect(last.label).toEqual(actions[0].label);last.action();expect(mockConfirm).toHaveBeenCalledTimes(1);expect(mockNavigate).toHaveBeenCalledTimes(1);});});
|
|
3
|
+
*/var onConfirm=function onConfirm(){mockConfirm();};var actions=[{label:'confirm',action:onConfirm},{label:'dismiss',action:function action(){}}];var params={productId:'product_1'};var mockedProps={message:message,title:title,params:params,actions:[].concat(actions),navigate:mockNavigate};var wrapper=shallow(/*#__PURE__*/React.createElement(VariantSelectModal,mockedProps));expect(wrapper).toMatchSnapshot();var reordered=wrapper.find('BaseDialog').props().actions;var last=reordered.slice(-1)[0];expect(last.label).toEqual(actions[0].label);last.action();expect(mockConfirm).toHaveBeenCalledTimes(1);expect(mockNavigate).toHaveBeenCalledTimes(1);});});
|
package/Dialog/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var DIALOG_TEXT_MESSAGE='DIALOG_TEXT_MESSAGE';export var
|
|
1
|
+
export var DIALOG_TEXT_MESSAGE='DIALOG_TEXT_MESSAGE';export var MODAL_VARIANT_SELECT='MODAL_VARIANT_SELECT';export var MODAL_ACTION_TYPE_NORMAL='normal';export var MODAL_ACTION_TYPE_PRIMARY='primary';export var MODAL_ACTION_TYPE_DANGER='danger';
|
package/Dialog/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var _dialogTypes;function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React from'react';import PropTypes from'prop-types';import Modal from'@shopgate/pwa-common/components/Modal';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import{MODAL_PIPELINE_ERROR}from'@shopgate/pwa-common/constants/ModalTypes';import I18n from'@shopgate/pwa-common/components/I18n';import{DIALOG_TEXT_MESSAGE,MODAL_VARIANT_SELECT,MODAL_ACTION_TYPE_PRIMARY,MODAL_ACTION_TYPE_NORMAL
|
|
1
|
+
var _dialogTypes;function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React from'react';import PropTypes from'prop-types';import Modal from'@shopgate/pwa-common/components/Modal';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import{MODAL_PIPELINE_ERROR}from'@shopgate/pwa-common/constants/ModalTypes';import I18n from'@shopgate/pwa-common/components/I18n';import{DIALOG_TEXT_MESSAGE,MODAL_VARIANT_SELECT,MODAL_ACTION_TYPE_PRIMARY,MODAL_ACTION_TYPE_NORMAL}from"./constants";import PipelineErrorDialog from"./components/PipelineErrorDialog";import TextMessageDialog from"./components/TextMessageDialog";import BasicDialog from"./components/BasicDialog";import VariantSelectModal from"./components/VariantSelectModal";var dialogTypes=(_dialogTypes={},_defineProperty(_dialogTypes,DIALOG_TEXT_MESSAGE,TextMessageDialog),_defineProperty(_dialogTypes,MODAL_PIPELINE_ERROR,PipelineErrorDialog),_defineProperty(_dialogTypes,MODAL_VARIANT_SELECT,VariantSelectModal),_dialogTypes);/**
|
|
2
2
|
* The main component for rendering dialogs.
|
|
3
3
|
* This component takes care of choosing the correct component body for the given type
|
|
4
4
|
* and render it on a modal overlay.
|
|
5
5
|
* @param {Object} props The component props.
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/var Dialog=function Dialog(_ref){var modal=_ref.modal,onConfirm=_ref.onConfirm,onDismiss=_ref.onDismiss;// Assemble the actions.
|
|
8
|
-
var actions=[];var confirm=modal.confirm,dismiss=modal.dismiss,title=modal.title,titleParams=modal.titleParams,message=modal.message,params=modal.params,type=modal.type
|
|
7
|
+
*/var Dialog=function Dialog(_ref){var modal=_ref.modal,onConfirm=_ref.onConfirm,onDismiss=_ref.onDismiss,children=_ref.children;// Assemble the actions.
|
|
8
|
+
var actions=[];var confirm=modal.confirm,dismiss=modal.dismiss,title=modal.title,titleParams=modal.titleParams,message=modal.message,params=modal.params,type=modal.type;// Push dismiss action first so the button is rendered first
|
|
9
9
|
if(dismiss){// We have a dismiss label, add a dismiss action.
|
|
10
10
|
actions.push({label:modal.dismiss,action:onDismiss,type:MODAL_ACTION_TYPE_PRIMARY});}if(confirm){// We have a confirm label, add a confirm action.
|
|
11
|
-
actions.push({label:modal.confirm,action:onConfirm,type:MODAL_ACTION_TYPE_NORMAL});}var dialogType=type;if(!dialogType&&message){dialogType=DIALOG_TEXT_MESSAGE;}var dialogTitle=title;if(titleParams){dialogTitle
|
|
11
|
+
actions.push({label:modal.confirm,action:onConfirm,type:MODAL_ACTION_TYPE_NORMAL});}var dialogType=type;if(!dialogType&&message){dialogType=DIALOG_TEXT_MESSAGE;}var dialogTitle=title;if(titleParams){dialogTitle=/*#__PURE__*/React.createElement(I18n.Text,{string:title,params:titleParams});}var dialogProps={actions:actions,title:dialogTitle,params:params,message:message||undefined,children:children};var DialogComponent=dialogTypes[dialogType]||BasicDialog;return/*#__PURE__*/React.createElement(Modal,null,/*#__PURE__*/React.createElement(Backdrop,{isVisible:true,level:0}),/*#__PURE__*/React.createElement(DialogComponent,dialogProps));};Dialog.defaultProps={children:null,onConfirm:function onConfirm(){},onDismiss:function onDismiss(){}};export default Dialog;
|
package/Dialog/spec.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from'react';import{shallow,ReactWrapper}from'enzyme';import{MODAL_PIPELINE_ERROR}from'@shopgate/pwa-common/constants/ModalTypes';import{MODAL_VARIANT_SELECT}from"./constants";import Dialog from"./index";jest.mock("./components/VariantSelectModal",function(){/**
|
|
2
2
|
* VariantSelectModal mock.
|
|
3
3
|
* @return {JSX}
|
|
4
|
-
*/var VariantSelectModal=function VariantSelectModal(){return
|
|
5
|
-
var wrapper=shallow(React.createElement(Dialog,{modal:{title:title,titleParams:titleParams}}));var i18n=new ReactWrapper(wrapper.find('BaseDialog').prop('title'));expect(i18n.prop('string')).toEqual(title);expect(i18n.prop('params')).toEqual(titleParams);});});
|
|
4
|
+
*/var VariantSelectModal=function VariantSelectModal(){return/*#__PURE__*/React.createElement("div",null);};return VariantSelectModal;});describe('<Dialog />',function(){it('should render without props',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(Dialog,{modal:{message:'msg'}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextMessageDialog').length).toBe(1);});it('should render BasicDialog when no message given',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(Dialog,{modal:{message:null}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('BaseDialog').length).toBe(1);});it('should render a special dialog',function(){var params={errorCode:'',message:'',pipeline:'',request:{}};var wrapper=shallow(/*#__PURE__*/React.createElement(Dialog,{modal:{type:MODAL_PIPELINE_ERROR,params:params}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('DefaultDialog').length).toBe(0);expect(wrapper.find('PipelineErrorDialog').length).toBe(1);});it('should render variant select dialog',function(){var params={productId:'product_1'};var wrapper=shallow(/*#__PURE__*/React.createElement(Dialog,{modal:{message:'Test',type:MODAL_VARIANT_SELECT,params:params}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('DefaultDialog').length).toBe(0);expect(wrapper.find('VariantSelectModal').length).toBe(1);});it('should convert title into translatable element',function(){var title='translate.me';var titleParams={foo:'bar'};// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
5
|
+
var wrapper=shallow(/*#__PURE__*/React.createElement(Dialog,{modal:{title:title,titleParams:titleParams}}));var i18n=new ReactWrapper(wrapper.find('BaseDialog').prop('title'));expect(i18n.prop('string')).toEqual(title);expect(i18n.prop('params')).toEqual(titleParams);});});
|
package/DiscountBadge/index.js
CHANGED
|
@@ -4,4 +4,4 @@ import React from'react';import PropTypes from'prop-types';import I18n from'@sho
|
|
|
4
4
|
* @param {string} [props.className] Additional CSS style definitions
|
|
5
5
|
* @param {string} props.text The text contents of the component.
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/var DiscountBadge=function DiscountBadge(_ref){var text=_ref.text,className=_ref.className,display=_ref.display,discount=_ref.discount;return
|
|
7
|
+
*/var DiscountBadge=function DiscountBadge(_ref){var text=_ref.text,className=_ref.className,display=_ref.display,discount=_ref.discount;return/*#__PURE__*/React.createElement("div",{"data-test-id":text,className:"ui-shared__discount-badge"},/*#__PURE__*/React.createElement(I18n.Text,{className:"".concat(styles[display]," ").concat(className),string:text,params:[discount]}));};DiscountBadge.defaultProps={className:'',discount:null,display:'small'};export default DiscountBadge;
|
package/DiscountBadge/spec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import DiscountBadge from"./index";describe('<DiscountBadge />',function(){it('should render the text',function(){var wrapper=shallow(React.createElement(DiscountBadge,{text:"foo"}));expect(wrapper).toMatchSnapshot();});it('should render the text and discount',function(){var wrapper=shallow(React.createElement(DiscountBadge,{text:"SAVE {0}%",discount:20}));expect(wrapper).toMatchSnapshot();});});
|
|
1
|
+
import React from'react';import{shallow}from'enzyme';import DiscountBadge from"./index";describe('<DiscountBadge />',function(){it('should render the text',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(DiscountBadge,{text:"foo"}));expect(wrapper).toMatchSnapshot();});it('should render the text and discount',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(DiscountBadge,{text:"SAVE {0}%",discount:20}));expect(wrapper).toMatchSnapshot();});});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{connect}from'react-redux';import{
|
|
1
|
+
import{connect}from'react-redux';import{toggleFavoriteWithListChooser}from'@shopgate/pwa-common-commerce/favorites/actions/toggleFavorites';/**
|
|
2
2
|
* Connects the dispatch function to a callable function in the props.
|
|
3
3
|
* @param {Function} dispatch The redux dispatch function.
|
|
4
4
|
* @return {Object} The extended component props.
|
|
5
|
-
*/var mapDispatchToProps=function mapDispatchToProps(dispatch){return{addFavorites:function addFavorites(productId){return dispatch(
|
|
5
|
+
*/var mapDispatchToProps=function mapDispatchToProps(dispatch){return{addFavorites:function addFavorites(productId){return dispatch(toggleFavoriteWithListChooser(productId));},removeFavorites:function removeFavorites(productId,withRelatives){return dispatch(toggleFavoriteWithListChooser(productId,withRelatives));}};};export default connect(null,mapDispatchToProps,null,{pure:function pure(){return null;}});
|
package/FavoritesButton/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import appConfig from'@shopgate/pwa-common/helpers/config';import HeartIcon from"../icons/HeartIcon";import HeartOutlineIcon from"../icons/HeartOutlineIcon";import Ripple from"../Ripple";import styles from"./style";import connect from"./connector";/**
|
|
2
2
|
* The favorites button component.
|
|
3
|
-
*/var FavoritesButton=/*#__PURE__*/function(_Component){_inherits(FavoritesButton,_Component);/**
|
|
3
|
+
*/var FavoritesButton=/*#__PURE__*/function(_Component){_inherits(FavoritesButton,_Component);var _super=_createSuper(FavoritesButton);/**
|
|
4
4
|
* Context types definition.
|
|
5
5
|
* @type {{i18n: shim}}
|
|
6
6
|
*/ /**
|
|
7
7
|
* Construct and init state
|
|
8
8
|
* @param {Object} props Component props
|
|
9
|
-
*/function FavoritesButton(props){var _this;_classCallCheck(this,FavoritesButton);_this=
|
|
9
|
+
*/function FavoritesButton(props){var _this;_classCallCheck(this,FavoritesButton);_this=_super.call(this,props);_defineProperty(_assertThisInitialized(_this),"onRippleComplete",function(){_this.props.onRippleComplete(_this.props.active);});_defineProperty(_assertThisInitialized(_this),"handleClick",function(event){event.preventDefault();event.stopPropagation();if(_this.props.once&&_this.clickedOnce){return;}_this.clickedOnce=true;if(!_this.props.productId){return;}if(!_this.props.active){_this.props.addFavorites(_this.props.productId);}else{setTimeout(function(){_this.props.removeFavorites(_this.props.productId,_this.props.removeWithRelatives);},_this.props.removeThrottle);}});_this.clickedOnce=false;return _this;}/**
|
|
10
10
|
* Callback for the moment when the ripple animation is done.
|
|
11
|
-
*/_createClass(FavoritesButton,[{key:"getLabel"
|
|
11
|
+
*/_createClass(FavoritesButton,[{key:"getLabel",value:/**
|
|
12
12
|
* Returns text for aria-label.
|
|
13
13
|
* @returns {string}
|
|
14
|
-
*/
|
|
14
|
+
*/function getLabel(){var _this$context$i18n=this.context.i18n(),__=_this$context$i18n.__;var lang=this.props.active?'favorites.remove':'favorites.add';return __(lang);}/**
|
|
15
15
|
* Adds or removes a given product ID from the favorite list.
|
|
16
16
|
* @param {Object} event The click event object.
|
|
17
|
-
*/},{key:"renderIcon"
|
|
17
|
+
*/},{key:"renderIcon",value:/**
|
|
18
18
|
* Renders the heart icon as filled or outlined, depending on the favorite button being active.
|
|
19
19
|
* @returns {JSX}
|
|
20
|
-
*/
|
|
20
|
+
*/function renderIcon(){if(this.props.active){return/*#__PURE__*/React.createElement(HeartIcon,null);}return/*#__PURE__*/React.createElement(HeartOutlineIcon,null);}/**
|
|
21
21
|
* Renders the component.
|
|
22
22
|
* @returns {JSX|null}
|
|
23
|
-
*/},{key:"render",value:function render(){if(!appConfig.hasFavorites){return null;}var className=this.props.noShadow?styles.buttonFlat:styles.button;return
|
|
23
|
+
*/},{key:"render",value:function render(){if(!appConfig.hasFavorites){return null;}var className=this.props.noShadow?styles.buttonFlat:styles.button;return/*#__PURE__*/React.createElement("button",{"aria-label":this.getLabel(),"aria-hidden":this.props['aria-hidden'],className:"ui-shared__favorites-button ".concat(className," ").concat(this.props.className),onClick:this.handleClick,"data-test-id":"favoriteButton",type:"button"},/*#__PURE__*/React.createElement(Ripple,{className:"".concat(styles.ripple," ").concat(this.props.rippleClassName),onComplete:this.onRippleComplete},this.renderIcon()));}}]);return FavoritesButton;}(Component);_defineProperty(FavoritesButton,"contextTypes",{i18n:PropTypes.func});_defineProperty(FavoritesButton,"defaultProps",{active:false,addFavorites:function addFavorites(){},'aria-hidden':null,className:'',noShadow:false,once:false,onRippleComplete:function onRippleComplete(){},productId:null,removeFavorites:function removeFavorites(){},removeThrottle:0,removeWithRelatives:false,rippleClassName:''});export default connect(FavoritesButton);
|
package/FavoritesButton/spec.js
CHANGED
|
@@ -3,4 +3,4 @@ import React from'react';import{Provider}from'react-redux';import configureStore
|
|
|
3
3
|
* @param {Object} mockedState Mocked stage.
|
|
4
4
|
* @param {Object} props Additional props.
|
|
5
5
|
* @return {ReactWrapper}
|
|
6
|
-
*/var createComponent=function createComponent(mockedState){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{active:false};var store=mockedStore(mockedState);store.dispatch=dispatcher;return mount(React.createElement(Provider,{store:store}
|
|
6
|
+
*/var createComponent=function createComponent(mockedState){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{active:false};var store=mockedStore(mockedState);store.dispatch=dispatcher;return mount(/*#__PURE__*/React.createElement(Provider,{store:store},/*#__PURE__*/React.createElement(FavoritesButton,props)),mockRenderOptions);};beforeEach(function(){dispatcher.mockReset();});it('should only render when no favorites set',function(){component=createComponent(mockedStateEmpty);expect(component).toMatchSnapshot();expect(component.find('Heart').exists()).toBe(false);expect(component.find('HeartOutline').exists()).toBe(true);component.find('button').simulate('click');});it('should render when favorites set',function(){component=createComponent(mockedStateOnList,{active:true});expect(component).toMatchSnapshot();expect(component.find('Heart').exists()).toBe(true);expect(component.find('HeartOutline').exists()).toBe(false);});it('should add to favorites on click',function(){component=createComponent(mockedStateNotOnList,{productId:'1',active:false});expect(component.find('Heart').exists()).toBe(false);expect(component.find('HeartOutline').exists()).toBe(true);component.find('button').simulate('click');component.update();expect(dispatcher).toHaveBeenCalled();});it('should remove from favorites on click',function(done){component=createComponent(mockedStateOnList,{productId:'1',active:true});expect(component.find('Heart').exists()).toBe(true);expect(component.find('HeartOutline').exists()).toBe(false);component.find('button').simulate('click');component.update();setTimeout(function(){expect(dispatcher).toHaveBeenCalled();done();},0);});it('should process ripple complete callback',function(){var onRippleComplete=jest.fn();component=createComponent(mockedStateOnList,{productId:'1',active:true,onRippleComplete:onRippleComplete});component.find('Ripple').instance().props.onComplete();component.update();expect(onRippleComplete).toHaveBeenCalled();});it('should only react on first click',function(done){component=createComponent(mockedStateOnList,{once:true,productId:'1',active:false});component.find('button').simulate('click');component.update();component.find('button').simulate('click');component.update();setTimeout(function(){expect(dispatcher.mock.calls.length).toBe(1);done();},1);});it('should only react on both clicks',function(done){component=createComponent(mockedStateOnList,{productId:'1',active:false});component.find('button').simulate('click');component.update();component.find('button').simulate('click');component.update();setTimeout(function(){expect(dispatcher.mock.calls.length).toBe(2);done();},1);});it('should render null when feature flag is off',function(){jest.spyOn(appConfig,'hasFavorites','get').mockReturnValue(false);component=createComponent(mockedStateOnList);expect(component.html()).toBe('');});});
|
package/Footer/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import Portal from'@shopgate/pwa-common/components/Portal';import{logger}from'@shopgate/pwa-core/helpers';import UIEvents from'@shopgate/pwa-core/emitters/ui';import{APP_FOOTER_CONTENT_BEFORE,APP_FOOTER_CONTENT_AFTER}from'@shopgate/pwa-common/constants/Portals';import{getAbsoluteHeight,getStyle}from'@shopgate/pwa-common/helpers/dom';import{SHEET_EVENTS}from"../Sheet";import{footer,withInset,updateInsetBackgroundColor,updateFooterHeight}from"./style";var APP_FOOTER_ID='AppFooter';var DATA_IGNORED='data-footer-inset-update-ignore';/**
|
|
2
2
|
* The Footer Component
|
|
3
3
|
* @deprecated
|
|
4
|
-
*/var Footer=/*#__PURE__*/function(_Component){_inherits(Footer,_Component);function Footer(){var
|
|
4
|
+
*/var Footer=/*#__PURE__*/function(_Component){_inherits(Footer,_Component);var _super=_createSuper(Footer);function Footer(){var _this;_classCallCheck(this,Footer);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_super.call.apply(_super,[this].concat(args));_defineProperty(_assertThisInitialized(_this),"ref",/*#__PURE__*/React.createRef());_defineProperty(_assertThisInitialized(_this),"hide",function(){if(_this.ref.current){updateFooterHeight(0);}});_defineProperty(_assertThisInitialized(_this),"show",function(){if(_this.ref.current){updateFooterHeight(getAbsoluteHeight(_this.ref.current));}});return _this;}_createClass(Footer,[{key:"componentDidMount",value:/**
|
|
5
|
+
* Sets up the DOM Mutation Observer to take care that the footer inset always has the correct
|
|
6
|
+
* background color, which matches the background color of the last element within the footer.
|
|
7
|
+
*/function componentDidMount(){var _this2=this;logger.warn('DEPRECATED: @shopgate/pwa-ui-shared/Footer is deprecated. Please use: import { Footer } from \'@shopgate/engage/components.\'');this.performFooterUpdate();var observer=new MutationObserver(function(mutations){var update=mutations.filter(function(mutation){return mutation.target.getAttribute(DATA_IGNORED)!=='true';}).length>0;if(update){_this2.performFooterUpdate();}});observer.observe(this.ref.current,{attributes:true,childList:true,subtree:true});UIEvents.addListener(SHEET_EVENTS.OPEN,this.hide);UIEvents.addListener(SHEET_EVENTS.CLOSE,this.show);}/** @inheritDoc */},{key:"componentWillUnmount",value:function componentWillUnmount(){UIEvents.removeListener(SHEET_EVENTS.OPEN,this.hide);UIEvents.removeListener(SHEET_EVENTS.CLOSE,this.show);}},{key:"getInsetBackgroundColor",value:/**
|
|
5
8
|
* Retrieves the background color for the footer inset.
|
|
6
9
|
* @param {NodeList} elements The DOM elements to inspect.
|
|
7
10
|
* @returns {string|null}
|
|
8
|
-
*/
|
|
11
|
+
*/function getInsetBackgroundColor(elements){var _this3=this;/**
|
|
9
12
|
* The background color of the bottom inset needs to identical to the last entry of the footer.
|
|
10
13
|
* So we loop backwards to the elements to find the first visible one.
|
|
11
14
|
*/var color=Array.from(elements).reverse().reduce(function(result,element){var ignore=element.getAttribute(DATA_IGNORED)==='true';if(result||ignore){// Nothing to do, since the color was already determined or the element can be ignored.
|
|
12
15
|
return result;}if(element.id===APP_FOOTER_ID){// Inspect core portal.
|
|
13
16
|
return _this3.getInsetBackgroundColor(element.children);}if(element.clientHeight){// Take the background color of the last visible element from the end of the footer.
|
|
14
17
|
return getStyle(element,'backgroundColor');}// Nothing happened within this loop - proceed with the next one.
|
|
15
|
-
return result;},null);if(color==='rgba(0, 0, 0, 0)'||color==='transparent'){return null;}return color||null;}/** Perform hide action */},{key:"performFooterUpdate"
|
|
18
|
+
return result;},null);if(color==='rgba(0, 0, 0, 0)'||color==='transparent'){return null;}return color||null;}/** Perform hide action */},{key:"performFooterUpdate",value:/**
|
|
16
19
|
* Performs an update of the footer: background color, height.
|
|
17
|
-
*/
|
|
20
|
+
*/function performFooterUpdate(){if(this.ref.current){this.ref.current.classList.toggle(withInset,this.hasVisibleContent());updateFooterHeight(getAbsoluteHeight(this.ref.current));updateInsetBackgroundColor(this.getInsetBackgroundColor(this.ref.current.children));}}/**
|
|
18
21
|
* Checks if the footer has visible content.
|
|
19
22
|
* @returns {boolean}
|
|
20
23
|
*/},{key:"hasVisibleContent",value:function hasVisibleContent(){if(this.ref.current){var elements=this.ref.current.parentElement.querySelectorAll("div.".concat(footer.toString()," > *:not(#").concat(APP_FOOTER_ID,"), #").concat(APP_FOOTER_ID," > *"));return Array.from(elements).filter(function(element){return element.getAttribute(DATA_IGNORED)!=='true'&&element.clientHeight>0;}).length>0;}return false;}/**
|
|
21
24
|
* @returns {JSX}
|
|
22
|
-
*/},{key:"render",value:function render(){return
|
|
23
|
-
* Sets up the DOM Mutation Observer to take care that the footer inset always has the correct
|
|
24
|
-
* background color, which matches the background color of the last element within the footer.
|
|
25
|
-
*/});export default Footer;
|
|
25
|
+
*/},{key:"render",value:function render(){return/*#__PURE__*/React.createElement("div",{className:"".concat(footer," ui-shared__footer"),ref:this.ref},/*#__PURE__*/React.createElement(Portal,{name:APP_FOOTER_CONTENT_BEFORE}),/*#__PURE__*/React.createElement("div",{id:APP_FOOTER_ID},this.props.children),/*#__PURE__*/React.createElement(Portal,{name:APP_FOOTER_CONTENT_AFTER}));}}]);return Footer;}(Component);_defineProperty(Footer,"defaultProps",{children:null});export default Footer;
|
package/Footer/index.spec.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
2
|
-
function Portal(){return mockedPortalContent||null;}return Portal;});var FOOTER_CHILD_ID='footer-child';var PORTAL_CONTENT_ID='portal-content';var insetBackgroundUpdateSpy=jest.spyOn(Footer.prototype,'performFooterUpdate');var defaultBackgroundColor='red';var defaultChildren
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}import React from'react';import{mount}from'enzyme';import{getAbsoluteHeight}from'@shopgate/pwa-common/helpers/dom';import UIEvents from'@shopgate/pwa-core/emitters/ui';import{SHEET_EVENTS}from"../Sheet";import{updateInsetBackgroundColor,updateFooterHeight}from"./style";import Footer from"./index";var mutationConstructorSpy=jest.fn();var mutationObserveSpy=jest.fn();/* eslint-disable require-jsdoc, extra-rules/potential-point-free, class-methods-use-this */global.MutationObserver=/*#__PURE__*/function(){function _class(callback){_classCallCheck(this,_class);mutationConstructorSpy(callback);}_createClass(_class,[{key:"observe",value:function observe(element,initObject){mutationObserveSpy(element,initObject);}}]);return _class;}();/* eslint-enable require-jsdoc, extra-rules/potential-point-free, class-methods-use-this */var mockedPortalContent;jest.mock("./style",function(){var actual=require.requireActual("./style");return _extends({},actual,{updateInsetBackgroundColor:jest.fn(),updateFooterHeight:jest.fn()});});jest.mock('@shopgate/pwa-core/emitters/ui',function(){return{addListener:jest.fn(),removeListener:jest.fn()};});jest.mock('@shopgate/pwa-common/helpers/dom',function(){var actual=require.requireActual('@shopgate/pwa-common/helpers/dom');return _extends({},actual,{getAbsoluteHeight:jest.fn()});});jest.mock('@shopgate/pwa-common/components/Portal',function(){// eslint-disable-next-line require-jsdoc
|
|
2
|
+
function Portal(){return mockedPortalContent||null;}return Portal;});var FOOTER_CHILD_ID='footer-child';var PORTAL_CONTENT_ID='portal-content';var insetBackgroundUpdateSpy=jest.spyOn(Footer.prototype,'performFooterUpdate');var defaultBackgroundColor='red';var defaultChildren=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:defaultBackgroundColor}});/**
|
|
3
3
|
* @param {NodeList} children Children for the footer.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var createComponent=function createComponent(){var children=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultChildren;var wrapper=mount(React.createElement("div",null
|
|
5
|
+
*/var createComponent=function createComponent(){var children=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultChildren;var wrapper=mount(/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(Footer,null,children)));return wrapper.find(Footer);};/**
|
|
6
6
|
* @param {Object} wrapper A wrapper.
|
|
7
7
|
* @param {string} id Id of the element to change.
|
|
8
|
-
*/var addHeightToWrapperElement=function addHeightToWrapperElement(wrapper,id){var elements=wrapper.instance().ref.current.querySelectorAll("#".concat(id));if(elements){Array.from(elements).forEach(function(element){Object.defineProperty(element,'clientHeight',{get:function get(){return 30;}});});}};describe('<Footer />',function(){beforeEach(function(){jest.clearAllMocks();mockedPortalContent=null;});it('should render the component',function(){var wrapper=createComponent();expect(wrapper).toMatchSnapshot();expect(wrapper.find('Portal')).toHaveLength(2);expect(wrapper.find("div#AppFooter > #".concat(FOOTER_CHILD_ID))).toExist();expect(mutationConstructorSpy).toHaveBeenCalledWith(expect.any(Function));expect(insetBackgroundUpdateSpy).toHaveBeenCalledTimes(1);});describe('.hasVisibleContent()',function(){it('should return FALSE when footer has no visible content',function(){var wrapper=createComponent();expect(wrapper.instance().hasVisibleContent()).toBe(false);});it('should return FALSE when there are components, but they are not visible',function(){mockedPortalContent
|
|
8
|
+
*/var addHeightToWrapperElement=function addHeightToWrapperElement(wrapper,id){var elements=wrapper.instance().ref.current.querySelectorAll("#".concat(id));if(elements){Array.from(elements).forEach(function(element){Object.defineProperty(element,'clientHeight',{get:function get(){return 30;}});});}};describe('<Footer />',function(){beforeEach(function(){jest.clearAllMocks();mockedPortalContent=null;});it('should render the component',function(){var wrapper=createComponent();expect(wrapper).toMatchSnapshot();expect(wrapper.find('Portal')).toHaveLength(2);expect(wrapper.find("div#AppFooter > #".concat(FOOTER_CHILD_ID))).toExist();expect(mutationConstructorSpy).toHaveBeenCalledWith(expect.any(Function));expect(insetBackgroundUpdateSpy).toHaveBeenCalledTimes(1);});describe('.hasVisibleContent()',function(){it('should return FALSE when footer has no visible content',function(){var wrapper=createComponent();expect(wrapper.instance().hasVisibleContent()).toBe(false);});it('should return FALSE when there are components, but they are not visible',function(){mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:PORTAL_CONTENT_ID});var wrapper=createComponent();expect(wrapper.instance().hasVisibleContent()).toBe(false);});it('should return FALSE when there are components, but they are supposed to be ignored',function(){mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:PORTAL_CONTENT_ID,"data-footer-inset-update-ignore":true});var wrapper=createComponent(null);addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);expect(wrapper.instance().hasVisibleContent()).toBe(false);});it('should return TRUE when the core portal has visible content',function(){var wrapper=createComponent();addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);expect(wrapper.instance().hasVisibleContent()).toBe(true);});it('should return TRUE when the an extension portal has visible content',function(){mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:PORTAL_CONTENT_ID});var wrapper=createComponent(null);addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);expect(wrapper.instance().hasVisibleContent()).toBe(true);});});describe('.getInsetBackgroundColor()',function(){it('should return null when there is no visible content',function(){var wrapper=createComponent(null);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(null);});it('should return "red" when there is visible content within the core portal',function(){var wrapper=createComponent();addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(defaultBackgroundColor);});it('should return "blue" when there is visible content within the core portal',function(){var backgroundColor='blue';mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:backgroundColor}});var wrapper=createComponent();addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(backgroundColor);});it('should return "red" when there is visible content within the core portal',function(){var backgroundColor='blue';mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:backgroundColor},"data-footer-inset-update-ignore":true});var wrapper=createComponent();addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(defaultBackgroundColor);});it('should return null when the last visible content in invisible by the background color',function(){var backgroundColor='rgba(0, 0, 0, 0)';mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:backgroundColor}});var wrapper=createComponent();addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(null);});});describe('.performFooterUpdate()',function(){it('should do nothing when the ref is empty',function(){var wrapper=createComponent();wrapper.instance().ref.current=null;updateInsetBackgroundColor.mockClear();wrapper.instance().performFooterUpdate();expect(updateInsetBackgroundColor).not.toHaveBeenCalled();});it('should update the inset background color',function(){var wrapper=createComponent();updateInsetBackgroundColor.mockClear();var instance=wrapper.instance();instance.performFooterUpdate();var backgroundColor=instance.getInsetBackgroundColor(instance.ref.current.children);expect(updateInsetBackgroundColor).toHaveBeenCalledTimes(1);expect(updateInsetBackgroundColor).toHaveBeenCalledWith(backgroundColor);});});describe('MutationObserver',function(){var callback;var instance;beforeEach(function(){var wrapper=createComponent();instance=wrapper.instance();insetBackgroundUpdateSpy.mockClear();var _mutationConstructorS=_slicedToArray(mutationConstructorSpy.mock.calls,1);var _mutationConstructorS2=_slicedToArray(_mutationConstructorS[0],1);callback=_mutationConstructorS2[0];});it('should observer with the correct initialization',function(){expect(mutationObserveSpy).toHaveBeenCalledWith(instance.ref.current,{attributes:true,childList:true,subtree:true});});it('should perform an inset update when the updated DOM element is not ignored',function(){var element=document.createElement('div');callback([{target:element}]);expect(insetBackgroundUpdateSpy).toHaveBeenCalledTimes(1);});it('should not perform an inset update when the updated DOM element is ignored',function(){var element=document.createElement('div');element.setAttribute('data-footer-inset-update-ignore','true');callback([{target:element}]);expect(insetBackgroundUpdateSpy).not.toHaveBeenCalled();});});describe('UI events subscriptions',function(){it('should subscribe / unsubscribe UI events',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Footer,null,/*#__PURE__*/React.createElement("div",null,"Footer")));var instance=wrapper.instance();expect(UIEvents.addListener).toBeCalledTimes(2);expect(UIEvents.addListener).nthCalledWith(1,SHEET_EVENTS.OPEN,instance.hide);expect(UIEvents.addListener).nthCalledWith(2,SHEET_EVENTS.CLOSE,instance.show);wrapper.unmount();expect(UIEvents.removeListener).toBeCalledTimes(2);expect(UIEvents.removeListener).nthCalledWith(1,SHEET_EVENTS.OPEN,instance.hide);expect(UIEvents.removeListener).nthCalledWith(2,SHEET_EVENTS.CLOSE,instance.show);});});describe('updateFooterHeight',function(){var instance;beforeEach(function(){var wrapper=createComponent();instance=wrapper.instance();});it('should set footer height to zero',function(){instance.hide();expect(updateFooterHeight).toHaveBeenCalledWith(0);});it('should set footer height',function(){getAbsoluteHeight.mockReturnValueOnce('48px');instance.show();expect(updateFooterHeight).toHaveBeenCalledWith('48px');});});});
|
|
@@ -7,4 +7,4 @@ function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj
|
|
|
7
7
|
if(countryElement.countries!==null&&countryElement.countries!==undefined&&!Array.isArray(countryElement.countries)){logger.error("Error: Invalid property type 'countries' in element "+"'".concat(countryElement.id,"'. Must be 'array', 'null' or 'undefined'"));return{};}// Build country display list for the country element (whitelist)
|
|
8
8
|
// For 'null', 'undefined' and '[]' it shows all countries
|
|
9
9
|
var countryKeys;if(countryElement.countries.length>0){countryKeys=countryElement.countries;}else{countryKeys=Object.keys(iso3166);}var countryList=countryKeys.reduce(function(reducer,countryCode){if(!iso3166[countryCode]){logger.error("Error: unknown country code [".concat(countryCode,"]"));return reducer;}return _extends({},reducer,_defineProperty({},countryCode,iso3166[countryCode].name));},{});// Add a "no selection" element
|
|
10
|
-
if(countryElement.required){return countryList;}return _extends({},optional,
|
|
10
|
+
if(countryElement.required){return countryList;}return _extends({},optional,countryList);});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{ELEMENT_TYPE_CHECKBOX,ELEMENT_TYPE_SELECT}from"../elementTypes";/**
|
|
2
2
|
* Prepare state of formData for form builder
|
|
3
3
|
* @param {Object} formElements form elements
|
|
4
4
|
* @param {Object} defaults form defaults
|