@shopgate/engage 7.21.3-beta.3 → 7.22.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ConnectedReactPortal/index.js +13 -0
- package/components/Menu/index.js +2 -2
- package/components/NavigationHandler/connector.js +1 -1
- package/components/Picker/index.js +2 -2
- package/components/Picker/spec.js +1 -1
- package/components/PickerUtilize/spec.js +2 -1
- package/components/index.js +1 -1
- package/package.json +14 -14
- package/product/components/Header/Shipping/spec.js +1 -1
- package/product/components/Rating/spec.js +1 -1
- package/reviews/components/Reviews/components/Header/spec.js +1 -1
- package/reviews/components/Reviews/mock.js +2 -6
- package/reviews/components/Reviews/spec.js +4 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var _excluded=["children"];function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import React from'react';import PropTypes from'prop-types';import{Provider,ReactReduxContext}from'react-redux';import Portal from'react-portal';/**
|
|
2
|
+
* @typedef {import('@types/react-portal')} ReactPortal
|
|
3
|
+
*/ // eslint-disable-next-line valid-jsdoc
|
|
4
|
+
/**
|
|
5
|
+
* ConnectedReactPortal is a wrapper around "react-portal" v3 that ensures
|
|
6
|
+
* children rendered in the portal have access to the Redux store.
|
|
7
|
+
*
|
|
8
|
+
* This addresses the limitation introduced by the switch to the new Context API in react-redux v6,
|
|
9
|
+
* where the Redux store is only accessible to components within the StoreProvider. Since the Portal
|
|
10
|
+
* component renders its children outside the React component tree, this wrapper bridges the gap.
|
|
11
|
+
*
|
|
12
|
+
* @type {ReactPortal}
|
|
13
|
+
*/var ConnectedReactPortal=function ConnectedReactPortal(_ref){var children=_ref.children,props=_objectWithoutProperties(_ref,_excluded);return React.createElement(ReactReduxContext.Consumer,null,function(ctx){return React.createElement(Portal,props,React.createElement(Provider,{store:ctx.store},children));});};ConnectedReactPortal.defaultProps={children:null};export default ConnectedReactPortal;
|
package/components/Menu/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _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);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}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 _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}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}});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 _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
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _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);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}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 _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}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}});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 _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{ConnectedReactPortal}from'@shopgate/engage/components';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import Position from"./components/Position";import Item from"./components/Item";import styles from"./style";/**
|
|
2
2
|
* The Menu component.
|
|
3
3
|
*/var Menu=/*#__PURE__*/function(_Component){function Menu(){var _this2;_classCallCheck(this,Menu);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this2=_callSuper(this,Menu,[].concat(args));/**
|
|
4
4
|
* Handles any menu toggling interactions.
|
|
@@ -9,4 +9,4 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
|
|
|
9
9
|
*/function get(){var _this$props$contextRe;if((_this$props$contextRe=this.props.contextRef)===null||_this$props$contextRe===void 0?void 0:_this$props$contextRe.current){var bounds=this.props.contextRef.current.getBoundingClientRect();return{height:bounds.height,width:bounds.width,left:bounds.left,right:bounds.right,bottom:bounds.bottom,top:bounds.top+bounds.height};}return{top:0,left:0};}},{key:"render",value:/**
|
|
10
10
|
* Renders the component.
|
|
11
11
|
* @returns {JSX}
|
|
12
|
-
*/function render(){var _this$props=this.props,children=_this$props.children,isOpen=_this$props.isOpen,onClose=_this$props.onClose;return React.createElement(
|
|
12
|
+
*/function render(){var _this$props=this.props,children=_this$props.children,isOpen=_this$props.isOpen,onClose=_this$props.onClose;return React.createElement(ConnectedReactPortal,{isOpened:isOpen},React.createElement("div",{className:styles.overlay},React.createElement(Backdrop,{isVisible:true,level:0,opacity:0,onClick:onClose}),React.createElement(Position,{offset:this.offset},React.createElement("div",{className:styles.menu},Children.map(children,function(child){if(!child){return null;}return React.cloneElement(child,{closeMenu:onClose});})))));}}]);}(Component);_defineProperty(Menu,"Item",Item);_defineProperty(Menu,"defaultProps",{children:null,contextRef:null,isOpen:false,onClose:function onClose(){}});export default Menu;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import{connect}from'react-redux';import{historyPush}from'@shopgate/pwa-common/actions/router/historyPush';import{historyPop}from'@shopgate/pwa-common/actions/router/historyPop';import{historyReplace}from'@shopgate/pwa-common/actions/router/historyReplace';import{historyReset}from'@shopgate/pwa-common/actions/router/historyReset';/**
|
|
2
2
|
* @param {Function} dispatch Dispatches redux actions.
|
|
3
3
|
* @returns {Object}
|
|
4
|
-
*/function mapDispatchToProps(dispatch){return{push:function push(params){return dispatch(historyPush(params));},pop:function pop(){return dispatch(historyPop());},replace:function replace(params){return dispatch(historyReplace(params));},reset:function reset(){return dispatch(historyReset());}};}export default connect(null,mapDispatchToProps
|
|
4
|
+
*/function mapDispatchToProps(dispatch){return{push:function push(params){return dispatch(historyPush(params));},pop:function pop(){return dispatch(historyPop());},replace:function replace(params){return dispatch(historyReplace(params));},reset:function reset(){return dispatch(historyReset());}};}export default connect(null,mapDispatchToProps);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}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 _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}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}});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 _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;}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 _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}import React,{Component}from'react';import PropTypes from'prop-types';import
|
|
1
|
+
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);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}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 _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}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}});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 _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;}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 _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}import React,{Component}from'react';import PropTypes from'prop-types';import{ConnectedReactPortal}from'@shopgate/engage/components';import{withForwardedRef}from"../../core";import PickerModal from"./components/Modal";import PickerButton from"./components/Button";import PickerList from"./components/List";/**
|
|
2
2
|
* Converts an item of any type (e.g. string or number)
|
|
3
3
|
* to an object representation containing value and label properties.
|
|
4
4
|
* @param {*} item - An item of any type.
|
|
@@ -34,4 +34,4 @@ if(!this.selectedItem||nextProps.value!==this.selectedItem.value){this.setState(
|
|
|
34
34
|
*/},{key:"selectedItem",get:function get(){return normalizeItem(this.props.items[this.state.selectedIndex]);}},{key:"render",value:/**
|
|
35
35
|
* Renders the component.
|
|
36
36
|
* @returns {JSX}
|
|
37
|
-
*/function render(){var _this3=this;var hasSelection=!!this.selectedItem;var buttonValue=hasSelection?this.selectedItem.label:'';var buttonLabel=hasSelection?this.props.label:this.props.placeholder;var buttonProps=_extends({},this.props.buttonProps,{label:buttonLabel,value:buttonValue,disabled:this.props.disabled,openList:this.props.disabled?null:function(){_this3.toggleOpenState(true);}});var modalProps={isOpen:this.state.isOpen,duration:this.props.duration,onClose:function onClose(){return _this3.toggleOpenState(false);}};var listProps={items:this.props.items.map(normalizeItem),selectedIndex:this.state.selectedIndex,onSelect:this.handleItemSelect};return React.createElement("div",{role:"button",className:"".concat(this.props.className," engage__picker"),ref:this.props.forwardedRef,tabIndex:0,"aria-haspopup":true},React.createElement(this.props.buttonComponent,buttonProps),React.createElement(
|
|
37
|
+
*/function render(){var _this3=this;var hasSelection=!!this.selectedItem;var buttonValue=hasSelection?this.selectedItem.label:'';var buttonLabel=hasSelection?this.props.label:this.props.placeholder;var buttonProps=_extends({},this.props.buttonProps,{label:buttonLabel,value:buttonValue,disabled:this.props.disabled,openList:this.props.disabled?null:function(){_this3.toggleOpenState(true);}});var modalProps={isOpen:this.state.isOpen,duration:this.props.duration,onClose:function onClose(){return _this3.toggleOpenState(false);}};var listProps={items:this.props.items.map(normalizeItem),selectedIndex:this.state.selectedIndex,onSelect:this.handleItemSelect};return React.createElement("div",{role:"button",className:"".concat(this.props.className," engage__picker"),ref:this.props.forwardedRef,tabIndex:0,"aria-haspopup":true},React.createElement(this.props.buttonComponent,buttonProps),React.createElement(ConnectedReactPortal,{onClose:function onClose(){return _this3.toggleOpenState(false);},isOpened:true},React.createElement(this.props.modalComponent,modalProps,React.createElement(this.props.listComponent,listProps))));}}]);}(Component);_defineProperty(Picker,"defaultProps",{buttonComponent:PickerButton,buttonProps:{},duration:300,disabled:false,forwardedRef:null,label:'',listComponent:PickerList,modalComponent:PickerModal,className:'',isOpen:false,items:[],onChange:function onChange(){},onClose:function onClose(){},onSelect:function onSelect(){},placeholder:'Pick ...',value:null});export default withForwardedRef(Picker);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from'react';import{mount}from'enzyme';import Picker from"./index";import PickerList from"./components/List";jest.mock('
|
|
1
|
+
import React from'react';import{mount}from'enzyme';import Picker from"./index";import PickerList from"./components/List";jest.mock('@shopgate/engage/components');describe('<Picker />',function(){var renderedElement;var renderedInstance;var mockItems=['String only',{value:'Value only'},{value:'value',label:'Value and label'}];var mockOnChange=jest.fn();var mockOnSelect=jest.fn();/**
|
|
2
2
|
* The view component
|
|
3
3
|
* @param {Object} props The component props.
|
|
4
4
|
*/var renderComponent=function renderComponent(props){renderedElement=mount(React.createElement(Picker,props));renderedInstance=renderedElement.find('Picker').instance();};beforeEach(function(){renderComponent({items:mockItems,onChange:mockOnChange,onSelect:mockOnSelect});renderedElement.update();});describe('Given the component was mounted to the DOM',function(){it('should match snapshot',function(){expect(renderedElement).toMatchSnapshot();});it('should have no selected value',function(){expect(renderedInstance.selectedItem).toBe(null);});describe('Given picker component gets opened',function(){beforeEach(function(){renderedInstance.toggleOpenState(true);renderedElement.update();});it('should have isOpen state',function(){expect(renderedInstance.state.isOpen).toBe(true);});it('should render the picker list',function(){expect(renderedElement.find(PickerList).length).toBe(1);});it('should render the picker items',function(){expect(renderedElement.find('li button').length).toBe(mockItems.length);});describe('Given a item gets selected',function(){jest.useFakeTimers();beforeEach(function(){jest.clearAllMocks();renderedElement.find('li button').first().simulate('click');jest.runAllTimers();});afterEach(function(){jest.clearAllTimers();});it('should trigger onChange when the value changed',function(){expect(mockOnChange).toHaveBeenCalledTimes(1);});it('should trigger onSelect when the value changed',function(){expect(mockOnSelect).toHaveBeenCalledTimes(1);});it('should not trigger onChange when the value did not change, but trigger onSelect',function(){renderedInstance.setState({selectedIndex:0});renderedInstance.toggleOpenState(true);renderedElement.find('li button').first().simulate('click');jest.runAllTimers();expect(mockOnChange).toHaveBeenCalledTimes(1);expect(mockOnSelect).toHaveBeenCalledTimes(2);});});});});});
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import React from'react';import{mount}from'enzyme';import Picker from"./index";jest.mock('@shopgate/engage/components/View');
|
|
1
|
+
import React from'react';import{mount}from'enzyme';import Picker from"./index";jest.mock('@shopgate/engage/components/View');jest.mock('@shopgate/engage/components',function(){// eslint-disable-next-line require-jsdoc
|
|
2
|
+
function SheetList(_ref){var children=_ref.children;return children;}SheetList.Item=function Item(){return null;};return{SheetList:SheetList,Sheet:function Sheet(_ref2){var children=_ref2.children;return children;},Picker:jest.requireActual('@shopgate/engage/components/Picker')["default"],ConnectedReactPortal:jest.requireActual('@shopgate/engage/components/ConnectedReactPortal/__mocks__')["default"]};});describe('<Picker />',function(){it('should render the picker',function(){var label='Picker label';var wrapper=mount(React.createElement(Picker,{label:label}));expect(wrapper).toMatchSnapshot();});});
|
package/components/index.js
CHANGED
|
@@ -9,4 +9,4 @@ export{default as AccordionContainer}from'@shopgate/pwa-ui-shared/AccordionConta
|
|
|
9
9
|
export{default as CartIconIOS}from'@shopgate/pwa-ui-ios/icons/CartIcon';export{default as FilterIconIOS}from'@shopgate/pwa-ui-ios/icons/FilterIcon';export{default as HomeIconIOS}from'@shopgate/pwa-ui-ios/icons/HomeIcon';export{default as ShareIconIOS}from'@shopgate/pwa-ui-ios/icons/ShareIcon';// ICONS ANDROID
|
|
10
10
|
export{default as ShareIconAndroid}from'@shopgate/pwa-ui-material/icons/ShareIcon';// ICONS SHARED
|
|
11
11
|
export{default as AccountBoxIcon}from'@shopgate/pwa-ui-shared/icons/AccountBoxIcon';export{default as AddMoreIcon}from'@shopgate/pwa-ui-shared/icons/AddMoreIcon';export{default as ArrowDropIcon}from'@shopgate/pwa-ui-shared/icons/ArrowDropIcon';export{default as ArrowIcon}from'@shopgate/pwa-ui-shared/icons/ArrowIcon';export{default as BarcodeScannerIcon}from'@shopgate/pwa-ui-shared/icons/BarcodeScannerIcon';export{default as BoxIcon}from'@shopgate/pwa-ui-shared/icons/BoxIcon';export{default as BrowseIcon}from'@shopgate/pwa-ui-shared/icons/BrowseIcon';export{default as BurgerIcon}from'@shopgate/pwa-ui-shared/icons/BurgerIcon';export{default as CartIcon}from'@shopgate/pwa-ui-shared/icons/CartIcon';export{default as CartPlusIcon}from'@shopgate/pwa-ui-shared/icons/CartPlusIcon';export{default as CartCouponIcon}from'@shopgate/pwa-ui-shared/icons/CartCouponIcon';export{default as CheckedIcon}from'@shopgate/pwa-ui-shared/icons/CheckedIcon';export{default as CheckIcon}from'@shopgate/pwa-ui-shared/icons/CheckIcon';export{default as ChevronIcon}from'@shopgate/pwa-ui-shared/icons/ChevronIcon';export{default as CreditCardIcon}from'@shopgate/pwa-ui-shared/icons/CreditCardIcon';export{default as CrossIcon}from'@shopgate/pwa-ui-shared/icons/CrossIcon';export{default as DescriptionIcon}from'@shopgate/pwa-ui-shared/icons/DescriptionIcon';export{default as FilterIcon}from'@shopgate/pwa-ui-shared/icons/FilterIcon';export{default as FlashEnabledIcon}from'@shopgate/pwa-ui-shared/icons/FlashEnabledIcon';export{default as FlashDisabledIcon}from'@shopgate/pwa-ui-shared/icons/FlashDisabledIcon';export{default as GridIcon}from'@shopgate/pwa-ui-shared/icons/GridIcon';export{default as HeartIcon}from'@shopgate/pwa-ui-shared/icons/HeartIcon';export{default as HeartOutlineIcon}from'@shopgate/pwa-ui-shared/icons/HeartOutlineIcon';export{default as HeartPlusIcon}from'@shopgate/pwa-ui-shared/icons/HeartPlusIcon';export{default as HeartPlusOutlineIcon}from'@shopgate/pwa-ui-shared/icons/HeartPlusOutlineIcon';export{default as HomeIcon}from'@shopgate/pwa-ui-shared/icons/HomeIcon';export{default as InfoIcon}from'@shopgate/pwa-ui-shared/icons/InfoIcon';export{default as InfoOutlineIcon}from'@shopgate/pwa-ui-shared/icons/InfoOutlineIcon';export{default as ListIcon}from'@shopgate/pwa-ui-shared/icons/ListIcon';export{default as LocatorIcon}from'@shopgate/pwa-ui-shared/icons/LocatorIcon';export{default as LocalShippingIcon}from'@shopgate/pwa-ui-shared/icons/LocalShippingIcon';export{default as LocationIcon}from'@shopgate/pwa-ui-shared/icons/LocationIcon';export{default as LockIcon}from'@shopgate/pwa-ui-shared/icons/LockIcon';export{default as LogoutIcon}from'@shopgate/pwa-ui-shared/icons/LogoutIcon';export{default as MagnifierIcon}from'@shopgate/pwa-ui-shared/icons/MagnifierIcon';export{default as MoreIcon}from'@shopgate/pwa-ui-shared/icons/MoreIcon';export{default as MoreVertIcon}from'@shopgate/pwa-ui-shared/icons/MoreVertIcon';export{default as PhoneIcon}from'@shopgate/pwa-ui-shared/icons/PhoneIcon';export{default as PlaceholderIcon}from'@shopgate/pwa-ui-shared/icons/PlaceholderIcon';export{default as RadioCheckedIcon}from'@shopgate/pwa-ui-shared/icons/RadioCheckedIcon';export{default as RadioUncheckedIcon}from'@shopgate/pwa-ui-shared/icons/RadioUncheckedIcon';export{default as SecurityIcon}from'@shopgate/pwa-ui-shared/icons/SecurityIcon';export{default as ShoppingCartIcon}from'@shopgate/pwa-ui-shared/icons/ShoppingCartIcon';export{default as SortIcon}from'@shopgate/pwa-ui-shared/icons/SortIcon';export{default as StarHalfIcon}from'@shopgate/pwa-ui-shared/icons/StarHalfIcon';export{default as StarIcon}from'@shopgate/pwa-ui-shared/icons/StarIcon';export{default as StarOutlineIcon}from'@shopgate/pwa-ui-shared/icons/StarOutlineIcon';export{default as TickIcon}from'@shopgate/pwa-ui-shared/icons/TickIcon';export{default as TrashIcon}from'@shopgate/pwa-ui-shared/icons/TrashIcon';export{default as TrashOutlineIcon}from'@shopgate/pwa-ui-shared/icons/TrashOutlineIcon';export{default as UncheckedIcon}from'@shopgate/pwa-ui-shared/icons/UncheckedIcon';export{default as ViewListIcon}from'@shopgate/pwa-ui-shared/icons/ViewListIcon';export{default as VisibilityIcon}from'@shopgate/pwa-ui-shared/icons/VisibilityIcon';export{default as VisibilityOffIcon}from'@shopgate/pwa-ui-shared/icons/VisibilityOffIcon';export{default as TimeIcon}from'@shopgate/pwa-ui-shared/icons/TimeIcon';export{default as NotificationIcon}from'@shopgate/pwa-ui-shared/icons/NotificationIcon';// LOCAL
|
|
12
|
-
export{MessageBar}from"./MessageBar";export{default as NavigationHandler}from"./NavigationHandler";export{default as TimeBoundary}from"./TimeBoundary";export{default as IntersectionVisibility}from"./IntersectionVisibility";export{default as VideoPlayer}from"./VideoPlayer";export{default as SheetDrawer}from"./SheetDrawer";export{default as SheetList}from"./SheetList";export{default as NullComponent}from"./NullComponent";export{default as View,ViewContext}from"./View";export{default as QuantityInput}from"./QuantityInput";export{default as QuantityLabel}from"./QuantityLabel";export{default as ResponsiveContainer}from"./ResponsiveContainer";export{default as BrandingColorBanner}from"./BrandingColorBanner";export{default as ScrollHeader}from"./ScrollHeader";export{default as Menu}from"./Menu";export{default as Toggle}from"./Toggle";export{Form}from"./Form";export{FormBuilder}from"./Form";export{Footer}from"./Footer";export{SideNavigation}from"./SideNavigation";export{default as TextLink}from"./TextLink/TextLink";export{ConditionalWrapper}from"./ConditionalWrapper";export{default as RadioGroupV2,useRadioGroup}from"./RadioGroup";export{default as RadioV2}from"./Radio";export{default as RadioCard}from"./RadioCard";export{default as ChipLayout}from"./ChipLayout";export{default as Logo}from"./Logo";export{default as PickerUtilize}from"./PickerUtilize";export{default as Switch}from"./Switch";export{default as SnackBarContainer}from"./SnackBarContainer";
|
|
12
|
+
export{MessageBar}from"./MessageBar";export{default as NavigationHandler}from"./NavigationHandler";export{default as TimeBoundary}from"./TimeBoundary";export{default as IntersectionVisibility}from"./IntersectionVisibility";export{default as VideoPlayer}from"./VideoPlayer";export{default as SheetDrawer}from"./SheetDrawer";export{default as SheetList}from"./SheetList";export{default as NullComponent}from"./NullComponent";export{default as View,ViewContext}from"./View";export{default as QuantityInput}from"./QuantityInput";export{default as QuantityLabel}from"./QuantityLabel";export{default as ResponsiveContainer}from"./ResponsiveContainer";export{default as BrandingColorBanner}from"./BrandingColorBanner";export{default as ScrollHeader}from"./ScrollHeader";export{default as Menu}from"./Menu";export{default as Toggle}from"./Toggle";export{Form}from"./Form";export{FormBuilder}from"./Form";export{Footer}from"./Footer";export{SideNavigation}from"./SideNavigation";export{default as TextLink}from"./TextLink/TextLink";export{ConditionalWrapper}from"./ConditionalWrapper";export{default as RadioGroupV2,useRadioGroup}from"./RadioGroup";export{default as RadioV2}from"./Radio";export{default as RadioCard}from"./RadioCard";export{default as ChipLayout}from"./ChipLayout";export{default as Logo}from"./Logo";export{default as PickerUtilize}from"./PickerUtilize";export{default as Switch}from"./Switch";export{default as SnackBarContainer}from"./SnackBarContainer";export{default as ConnectedReactPortal}from"./ConnectedReactPortal";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.22.0-beta.1",
|
|
4
4
|
"description": "Shopgate's ENGAGE library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@shopgate/native-modules": "1.0.0-beta.18",
|
|
19
|
-
"@shopgate/pwa-common": "7.
|
|
20
|
-
"@shopgate/pwa-common-commerce": "7.
|
|
21
|
-
"@shopgate/pwa-core": "7.
|
|
22
|
-
"@shopgate/pwa-ui-ios": "7.
|
|
23
|
-
"@shopgate/pwa-ui-material": "7.
|
|
24
|
-
"@shopgate/pwa-ui-shared": "7.
|
|
19
|
+
"@shopgate/pwa-common": "7.22.0-beta.1",
|
|
20
|
+
"@shopgate/pwa-common-commerce": "7.22.0-beta.1",
|
|
21
|
+
"@shopgate/pwa-core": "7.22.0-beta.1",
|
|
22
|
+
"@shopgate/pwa-ui-ios": "7.22.0-beta.1",
|
|
23
|
+
"@shopgate/pwa-ui-material": "7.22.0-beta.1",
|
|
24
|
+
"@shopgate/pwa-ui-shared": "7.22.0-beta.1",
|
|
25
25
|
"@stripe/react-stripe-js": "^1.1.2",
|
|
26
26
|
"@stripe/stripe-js": "^1.3.1",
|
|
27
27
|
"@virtuous/conductor": "~2.5.0",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"validate.js": "^0.13.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"classnames": "2.
|
|
46
|
+
"classnames": "2.5.1",
|
|
47
47
|
"jest-mock-console": "^0.4.2",
|
|
48
48
|
"lodash": "^4.17.11",
|
|
49
|
-
"prop-types": "~15.
|
|
50
|
-
"react": "~16.
|
|
51
|
-
"react-redux": "^
|
|
52
|
-
"redux": "^4.
|
|
53
|
-
"redux-mock-store": "^1.5.
|
|
54
|
-
"reselect": "^
|
|
49
|
+
"prop-types": "~15.8.1",
|
|
50
|
+
"react": "~16.14.0",
|
|
51
|
+
"react-redux": "^8.1.3",
|
|
52
|
+
"redux": "^4.2.1",
|
|
53
|
+
"redux-mock-store": "^1.5.4",
|
|
54
|
+
"reselect": "^4.1.8"
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -2,4 +2,4 @@ import React from'react';import{Provider}from'react-redux';import configureStore
|
|
|
2
2
|
* Creates connected the component
|
|
3
3
|
* @param {Object} state The mocked redux state
|
|
4
4
|
* @return {ReactWrapper}
|
|
5
|
-
*/var createComponent=function createComponent(state){return mount(React.createElement(Provider,{store:mockedStore(state)},React.createElement(Shipping,{productId:"fakeId"})),mockRenderOptions);};it('should render shipping price',function(){var component=createComponent(mockedStoreWithShippingPrice);expect(component).toMatchSnapshot();expect(component.html().includes('shipping.cost')).toBe(true);});it('should render free shipping',function(){var component=createComponent(mockedStoreWithFreeShipping);expect(component).toMatchSnapshot();expect(component.html().includes('shipping.free')).toBe(true);});it('should not render when shipping is unknown',function(){var component=createComponent(mockedStoreWithUnknownShipping);expect(component.
|
|
5
|
+
*/var createComponent=function createComponent(state){return mount(React.createElement(Provider,{store:mockedStore(state)},React.createElement(Shipping,{productId:"fakeId"})),mockRenderOptions);};it('should render shipping price',function(){var component=createComponent(mockedStoreWithShippingPrice);expect(component).toMatchSnapshot();expect(component.html().includes('shipping.cost')).toBe(true);});it('should render free shipping',function(){var component=createComponent(mockedStoreWithFreeShipping);expect(component).toMatchSnapshot();expect(component.html().includes('shipping.free')).toBe(true);});it('should not render when shipping is unknown',function(){var component=createComponent(mockedStoreWithUnknownShipping);expect(component.isEmptyRender()).toBe(true);});});
|
|
@@ -2,4 +2,4 @@ import React from'react';import{Provider}from'react-redux';import configureStore
|
|
|
2
2
|
* Makes component.
|
|
3
3
|
* @param {Object} state State
|
|
4
4
|
* @returns {Object}
|
|
5
|
-
*/var getComponent=function getComponent(state){return mount(React.createElement(Provider,{store:mockedStore(state)},React.createElement(Rating,{productId:"foo"})),mockRenderOptions);};describe('Rendering',function(){it('should render rating when data is available',function(){var component=getComponent(mockedStateWithTwoReviews);expect(component).toMatchSnapshot();});it('should render nothing when data is not available',function(){var component=getComponent(mockedStateWithoutReview);expect(component.
|
|
5
|
+
*/var getComponent=function getComponent(state){return mount(React.createElement(Provider,{store:mockedStore(state)},React.createElement(Rating,{productId:"foo"})),mockRenderOptions);};describe('Rendering',function(){it('should render rating when data is available',function(){var component=getComponent(mockedStateWithTwoReviews);expect(component).toMatchSnapshot();});it('should render nothing when data is not available',function(){var component=getComponent(mockedStateWithoutReview);expect(component.isEmptyRender()).toBe(true);});});describe('Scroll on click',function(){var scrollSpy=jest.fn();it('should scroll to reviews when clicked',function(){jest.spyOn(document,'getElementById').mockImplementation(getElementById(scrollSpy));var component=getComponent(mockedStateWithTwoReviews);component.simulate('click');expect(scrollSpy.mock.calls[0][0]).toBe(0);expect(scrollSpy.mock.calls[0][1]).toBe(70);expect(scrollSpy).toHaveBeenCalled();document.getElementById.mockReset();document.getElementById.mockRestore();});it('should do nothing when clicked but no reviews excerpt element',function(){jest.spyOn(document,'getElementById').mockImplementation(function(){return null;});var component=getComponent(mockedStateWithTwoReviews);component.simulate('click');expect(scrollSpy.mock.calls.length).toBe(1);document.getElementById.mockReset();document.getElementById.mockRestore();});});});
|
|
@@ -3,4 +3,4 @@ import React from'react';import{Provider}from'react-redux';import{mount}from'enz
|
|
|
3
3
|
* @param {Object} mockedState Mocked stage.
|
|
4
4
|
* @param {Object|null} props Rating prop.
|
|
5
5
|
* @return {ReactWrapper}
|
|
6
|
-
*/var createComponent=function createComponent(mockedState){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return mount(React.createElement(Provider,{store:mockedStore(mockedState)},React.createElement(Header,props)),mockRenderOptions);};describe('<Header />',function(){var header=null;it('should render empty',function(){var productId=mockProductId;var rating=mockedStateWithoutReview.product.productsById[productId].productData.rating;header=createComponent(mockedStateWithoutReview,{productId:productId,rating:rating});expect(header.find('Header').exists()).toBe(true);expect(header).toMatchSnapshot();expect(header.find('RatingStars').prop('value')).toEqual(0);expect(header.find('RatingCount').
|
|
6
|
+
*/var createComponent=function createComponent(mockedState){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return mount(React.createElement(Provider,{store:mockedStore(mockedState)},React.createElement(Header,props)),mockRenderOptions);};describe('<Header />',function(){var header=null;it('should render empty',function(){var productId=mockProductId;var rating=mockedStateWithoutReview.product.productsById[productId].productData.rating;header=createComponent(mockedStateWithoutReview,{productId:productId,rating:rating});expect(header.find('Header').exists()).toBe(true);expect(header).toMatchSnapshot();expect(header.find('RatingStars').prop('value')).toEqual(0);expect(header.find('RatingCount').isEmptyRender()).toBe(true);});it('should render rating summary',function(){var productId=mockProductId;var rating=mockedStateWithAll.product.productsById[productId].productData.rating;header=createComponent(mockedStateWithAll,{productId:productId,rating:rating});expect(header.find('Header').exists()).toBe(true);expect(header).toMatchSnapshot();expect(header.find('RatingStars').prop('value')).toEqual(rating.average);expect(header.find('RatingCount').prop('count')).toEqual(rating.count);});it('should render null when no review is provided',function(){header=createComponent(mockedStateWithAll,{productId:'some-id'});expect(header.isEmptyRender()).toBe(true);});});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
var mockedProduct={productId:'foo',rating:{average:0,count:0}};var mockedProductWithRating={productId:'foo',rating:{average:50,count:4}};/**
|
|
2
2
|
* Creates mocked review object.
|
|
3
3
|
* @param {string|number} id Anything that can be an id.
|
|
4
4
|
* @return {Object}
|
|
@@ -15,8 +15,4 @@ var mockedState=JSON.parse(JSON.stringify(mockedStateWithAll));mockedState.revie
|
|
|
15
15
|
*/export var mockedStateWithoutReview={product:{productsById:{foo:{productData:mockedProduct}}},reviews:{reviewsById:{},reviewsByProductId:{}}};/**
|
|
16
16
|
* Mocked state without data.
|
|
17
17
|
* @type {{product: {productsById: {}}}}
|
|
18
|
-
*/export var mockedStateProductEmpty={product:{productsById:{}}}
|
|
19
|
-
* Sets up mocks.
|
|
20
|
-
* @param {bool} mockReviewsAvailable A feature flag "hasReviews" value.
|
|
21
|
-
* @type {Function}
|
|
22
|
-
*/export var setMocks=function setMocks(){var mockReviewsAvailable=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;jest.doMock('@shopgate/pwa-common/helpers/config',function(){return{get hasReviews(){return mockReviewsAvailable;},get showWriteReview(){return true;},themeConfig:mockedConfig};});};
|
|
18
|
+
*/export var mockedStateProductEmpty={product:{productsById:{}}};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React from'react';import{Provider}from'react-redux';import configureStore from'redux-mock-store';import{mount}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import{mockedStateWithAll,mockedStateWithoutReview,mockedStateWithTwoReviews
|
|
1
|
+
import React from'react';import{Provider}from'react-redux';import configureStore from'redux-mock-store';import{mount}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import{mockedStateWithAll,mockedStateWithoutReview,mockedStateWithTwoReviews}from'@shopgate/pwa-common-commerce/reviews/mock';import appConfig from'@shopgate/pwa-common/helpers/config';import Reviews from"./index";var mockedStore=configureStore();/**
|
|
2
2
|
* @returns {JSX}
|
|
3
|
-
*/
|
|
3
|
+
*/jest.mock("./components/Header",function(){return function Header(){return React.createElement("div",null);};});jest.mock('@shopgate/engage/product',function(){return{PRODUCT_REVIEWS:'product.reviews',makeIsBaseProductActive:jest.fn(function(){return function(){return true;};})};});jest.mock('@shopgate/engage/components');// Mock the getter of the hasReviews key inside the app config, so that we can turn it off later
|
|
4
|
+
jest.resetModules();var hasReviewsGetter=jest.fn().mockReturnValue(true);Object.defineProperty(appConfig,'hasReviews',{get:hasReviewsGetter});/**
|
|
4
5
|
* Creates component with provided store state.
|
|
5
6
|
* @param {Object} mockedState Mocked stage.
|
|
6
7
|
* @return {ReactWrapper}
|
|
7
|
-
*/var createComponent=function createComponent(mockedState){
|
|
8
|
+
*/var createComponent=function createComponent(mockedState){return mount(React.createElement(Provider,{store:mockedStore(mockedState)},React.createElement(Reviews,{productId:"foo"})),mockRenderOptions);};describe('<Reviews />',function(){var component=null;it('should render when no reviews and rating given',function(){component=createComponent(mockedStateWithoutReview);expect(component).toMatchSnapshot();expect(component.find('Header').exists()).toBe(true);expect(component.find('List').exists()).toBe(true);expect(component.find('AllReviewsLink').exists()).toBe(true);});it('should render reviews, header and all reviews link',function(){component=createComponent(mockedStateWithAll);expect(component).toMatchSnapshot();expect(component.find('Header').exists()).toBe(true);expect(component.find('List').exists()).toBe(true);expect(component.find('AllReviewsLink').find('div').exists()).toBe(true);});it('should render reviews, header, but no all reviews link',function(){component=createComponent(mockedStateWithTwoReviews);expect(component).toMatchSnapshot();expect(component.find('Header').exists()).toBe(true);expect(component.find('List').exists()).toBe(true);expect(component.find('AllReviewsLink').find('div').exists()).toBe(false);});it('should not render when feature flag is off',function(){hasReviewsGetter.mockReturnValueOnce(false);component=createComponent(mockedStateWithAll);expect(component).toMatchSnapshot();expect(component.find('Header').exists()).toBe(false);expect(component.find('List').exists()).toBe(false);expect(component.find('AllReviewsLink').exists()).toBe(false);});});
|