@shopgate/engage 6.22.0-beta.1 → 6.22.0-beta.10
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/app-rating/action-creators/appStart.js +3 -3
- package/app-rating/action-creators/ordersPlaced.js +3 -3
- package/app-rating/action-creators/popup.js +4 -4
- package/app-rating/action-creators/timer.js +3 -3
- package/app-rating/actions/showModal.js +2 -2
- package/app-rating/constants/index.js +2 -2
- package/app-rating/reducers/index.js +2 -2
- package/app-rating/subscriptions/index.js +2 -2
- package/back-in-stock/components/BackInStockButton/index.js +2 -2
- package/back-in-stock/components/BackInStockButton/style.js +1 -1
- package/back-in-stock/components/CharacteristicsButton/index.js +1 -1
- package/back-in-stock/components/ProductInfoBackInStockButton/connector.js +1 -1
- package/back-in-stock/components/Subscriptions/components/List/index.js +2 -2
- package/back-in-stock/components/Subscriptions/components/Subscription/index.js +3 -3
- package/back-in-stock/providers/BackInStockSubscriptionsProvider.connector.js +2 -2
- package/back-in-stock/providers/BackInStockSubscriptionsProvider.js +2 -2
- package/back-in-stock/reducers/index.js +2 -2
- package/back-in-stock/selectors/index.js +32 -14
- package/back-in-stock/subscriptions/index.js +10 -2
- package/core/action-creators/appPermissions.js +9 -0
- package/core/action-creators/index.js +1 -0
- package/core/actions/getGeolocation.js +1 -1
- package/core/actions/grantCameraPermissions.js +1 -1
- package/core/actions/grantGeolocationPermissions.js +1 -1
- package/core/actions/grantPermissions.js +4 -4
- package/core/actions/grantPushPermissions.js +2 -2
- package/core/actions/index.js +1 -0
- package/core/actions/requestAppPermission.js +7 -0
- package/core/actions/requestAppPermissionStatus.js +7 -0
- package/core/collections/AppInitialization.js +49 -0
- package/core/collections/index.js +1 -0
- package/core/constants/actionTypes.js +1 -0
- package/core/constants/appFeatures.js +1 -0
- package/core/constants/index.js +6 -0
- package/core/helpers/appFeatures.js +7 -0
- package/core/helpers/index.js +1 -0
- package/core/index.js +8 -12
- package/core/initialization/index.js +7 -0
- package/core/streams/appPermissions.js +19 -0
- package/core/streams/index.js +1 -0
- package/package.json +7 -7
- package/product/components/Characteristics/Characteristic/components/SheetItem/index.js +3 -3
- package/product/components/Characteristics/Characteristic/components/SheetItem/style.js +1 -1
- package/push-opt-in/action-creators/index.js +1 -0
- package/push-opt-in/action-creators/optInTrigger.js +23 -0
- package/push-opt-in/action-creators/pushOptIn.js +7 -0
- package/push-opt-in/actions/index.js +1 -0
- package/push-opt-in/actions/pushOptInModal.js +8 -0
- package/push-opt-in/components/PushOptInModal/connector.js +9 -0
- package/push-opt-in/components/PushOptInModal/index.js +10 -0
- package/push-opt-in/components/PushOptInModal/push-opt-in.svg +62 -0
- package/push-opt-in/components/PushOptInModal/style.js +1 -0
- package/push-opt-in/components/index.js +1 -0
- package/push-opt-in/constants/index.js +1 -0
- package/push-opt-in/constants/optInModal.js +1 -0
- package/push-opt-in/constants/optInTrigger.js +1 -0
- package/push-opt-in/reducers/index.js +1 -0
- package/push-opt-in/reducers/optInModal.js +6 -0
- package/push-opt-in/reducers/optInTrigger.js +6 -0
- package/push-opt-in/selectors/index.js +1 -0
- package/push-opt-in/selectors/optInModal.js +8 -0
- package/push-opt-in/selectors/optInTrigger.js +5 -0
- package/push-opt-in/subscriptions/index.js +1 -0
- package/push-opt-in/subscriptions/optInTrigger.js +12 -0
- package/a11y/components/LiveMessage/__tests__/index.spec.js +0 -1
- package/a11y/components/LiveMessenger/__tests__/helpers.spec.js +0 -1
- package/a11y/components/LiveMessenger/__tests__/index.spec.js +0 -1
- package/a11y/components/Navigation/__tests__/index.spec.js +0 -1
- package/a11y/components/Section/__tests__/index.spec.js +0 -1
- package/a11y/index.spec.js +0 -1
- package/back-in-stock/components/Subscriptions/components/Subscription/connector.js +0 -3
- package/cart/index.spec.js +0 -1
- package/category/index.spec.js +0 -1
- package/checkout/index.spec.js +0 -1
- package/components/Footer/__tests__/Footer.spec.js +0 -8
- package/components/Form/Builder/Builder.spec.js +0 -19
- package/components/Form/Builder/classes/ActionListener.spec.js +0 -21
- package/components/Form/Builder/helpers/buildCountryList.spec.js +0 -1
- package/components/Form/Builder/helpers/buildFormDefaults.spec.js +0 -1
- package/components/Form/Builder/helpers/buildFormElements.spec.js +0 -3
- package/components/Form/Builder/helpers/buildProvinceList.spec.js +0 -1
- package/components/IntersectionVisibility/__tests__/index.js +0 -1
- package/components/View/__mocks__/context.js +0 -1
- package/components/View/__mocks__/index.js +0 -5
- package/components/View/__tests__/index.spec.js +0 -1
- package/components/View/__tests__/provider.spec.js +0 -1
- package/components/View/components/Above/__tests__/index.spec.js +0 -1
- package/components/View/components/Below/__tests__/index.spec.js +0 -1
- package/components/View/components/Content/__tests__/index.spec.js +0 -2
- package/components/__mocks__/index.js +0 -4
- package/components/index.spec.js +0 -1
- package/core/actions/__tests__/getGeolocation.spec.js +0 -2
- package/core/actions/__tests__/grantCameraPermissions.spec.js +0 -1
- package/core/actions/__tests__/grantGeolocationPermissions.spec.js +0 -1
- package/core/actions/__tests__/grantPermissions.spec.js +0 -9
- package/core/actions/__tests__/updateStatusBarBackground.spec.js +0 -1
- package/core/classes/__tests__/GeolocationRequest.spec.js +0 -5
- package/core/config/__tests__/getPageConfig.spec.js +0 -1
- package/core/config/__tests__/getPageSettings.spec.js +0 -2
- package/core/config/__tests__/getThemeAssets.spec.js +0 -1
- package/core/config/__tests__/getThemeColors.spec.js +0 -1
- package/core/config/__tests__/getThemeConfig.spec.js +0 -2
- package/core/config/__tests__/getThemeSettings.spec.js +0 -1
- package/core/config/__tests__/getThemeStyles.spec.js +0 -1
- package/core/config/__tests__/getWidgetConfig.spec.js +0 -1
- package/core/config/__tests__/getWidgetSettings.spec.js +0 -3
- package/core/helpers/__mocks__/i18n.js +0 -1
- package/core/helpers/__tests__/i18n.spec.js +0 -1
- package/core/helpers/__tests__/updateLegacyNavigationBar.spec.js +0 -1
- package/core/hocs/__mocks__/withWidgetSettings.js +0 -5
- package/core/hocs/__tests__/withApp.spec.js +0 -2
- package/core/hocs/__tests__/withCurrentProduct.spec.js +0 -2
- package/core/hocs/__tests__/withForwardedRef.spec.js +0 -1
- package/core/hocs/__tests__/withNavigation.spec.js +0 -2
- package/core/hocs/__tests__/withRoute.spec.js +0 -2
- package/core/hocs/__tests__/withTheme.spec.js +0 -2
- package/core/hocs/__tests__/withWidgetSettings.spec.js +0 -2
- package/core/hocs/__tests__/withWidgetStyles.spec.js +0 -2
- package/core/hooks/__tests__/useApp.spec.js +0 -1
- package/core/hooks/__tests__/useNavigation.spec.js +0 -1
- package/core/hooks/__tests__/usePageConfig.spec.js +0 -1
- package/core/hooks/__tests__/usePageSettings.spec.js +0 -1
- package/core/hooks/__tests__/useTheme.spec.js +0 -1
- package/core/hooks/__tests__/useWidgetConfig.spec.js +0 -1
- package/core/hooks/__tests__/useWidgetSettings.spec.js +0 -1
- package/core/hooks/__tests__/useWidgetStyles.spec.js +0 -1
- package/core/index.spec.js +0 -1
- package/core/providers/__tests__/AppProvider.spec.js +0 -2
- package/core/router/__tests__/helpers.spec.js +0 -1
- package/favorites/index.spec.js +0 -1
- package/filter/helpers/__tests__/buildUpdatedFilters.spec.js +0 -1
- package/filter/index.spec.js +0 -1
- package/index.spec.js +0 -1
- package/market/index.spec.js +0 -1
- package/orders/index.spec.js +0 -1
- package/page/index.spec.js +0 -1
- package/product/components/Description/__tests__/Description.spec.js +0 -1
- package/product/components/Media/helpers.spec.js +0 -3
- package/product/components/ProductCharacteristics/helpers/index.spec.js +0 -12
- package/product/components/ProductGridPrice/index.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/Content.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/Group.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/GroupedProperties.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/Lists.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/ProductProperties.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/Row.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/Rows.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/helpers/getGroupsFromProperties.spec.js +0 -1
- package/product/components/ProductProperties/__tests__/helpers/getSubgroupsFromProperties.spec.js +0 -1
- package/product/components/QuantityPicker/helpers.spec.js +0 -1
- package/product/components/__mocks__/context.js +0 -1
- package/product/hocs/withMapPricing.spec.js +0 -4
- package/product/hocs/withPriceCalculation.spec.js +0 -1
- package/product/index.spec.js +0 -1
- package/product/selectors/__tests__/media.spec.js +0 -1
- package/product/selectors/__tests__/price.spec.js +0 -1
- package/product/selectors/__tests__/product.spec.js +0 -2
- package/product/selectors/__tests__/relations.spec.js +0 -1
- package/product/selectors/__tests__/variants.spec.js +0 -1
- package/product/selectors/mocks/productProperties.mock.js +0 -1
- package/reviews/index.spec.js +0 -1
- package/scanner/index.spec.js +0 -1
- package/search/index.spec.js +0 -1
- package/user/index.spec.js +0 -1
- package/user/selectors/__tests__/login.spec.js +0 -1
package/cart/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as cart from'.';describe('engage > cart',function(){it('should have exports',function(){expect(_typeof(cart)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(cart).forEach(function(exportKey){expect(typeof cart[exportKey]!=='undefined').toBe(true);});});});
|
package/category/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as category from'.';describe('engage > category',function(){it('should have exports',function(){expect(_typeof(category)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(category).forEach(function(exportKey){expect(typeof category[exportKey]!=='undefined').toBe(true);});});});
|
package/checkout/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as checkout from'.';describe('engage > checkout',function(){it('should have exports',function(){expect(_typeof(checkout)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(checkout).forEach(function(exportKey){expect(typeof checkout[exportKey]!=='undefined').toBe(true);});});});
|
|
@@ -1,8 +0,0 @@
|
|
|
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'@shopgate/pwa-ui-shared/Sheet';import{updateInsetBackgroundColor,updateFooterHeight}from"../Footer.style";import Footer from"../Footer";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("../Footer.style",function(){var actual=require.requireActual("../Footer.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
|
-
* @param {NodeList} children Children for the footer.
|
|
4
|
-
* @returns {JSX}
|
|
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
|
-
* @param {Object} wrapper A wrapper.
|
|
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=/*#__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');});});});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
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);}/* eslint-disable extra-rules/no-single-line-objects */import React from'react';import{mount}from'enzyme';import{Builder}from'.';describe('<Builder />',function(){it('should render empty form',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Builder,{config:{fields:{}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();});it('should render two text fields',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Builder,{config:{fields:{firstName:{label:'foo',type:'text',visible:true},lastName:{label:'bar',type:'text',visible:true}}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);});it('should render invisible field with visibility prop set to false',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Builder,{config:{fields:{firstName:{label:'foo',type:'text',visible:false}}},name:"foo",handleUpdate:function handleUpdate(){}}));// The TextField component is hidden by the ElementText component
|
|
2
|
-
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(0);});it('should modify the element visibility if setVisibilty rule applies',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Builder,{config:{fields:{foo:{label:'foo',type:'text',visible:true},bar:{label:'bar',type:'text',actions:[{type:'setVisibility',rules:[{context:'foo',type:'notIn',data:['abc']}]}]}}},name:"foo",handleUpdate:function handleUpdate(){}}));// Both should be marked visible at the beginning.
|
|
3
|
-
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);// Simulate user input to the text field.
|
|
4
|
-
wrapper.find('input').first().simulate('change',{target:{value:'abc'}});// Second field should be marked as hidden but be still rendered.
|
|
5
|
-
// The TextField component is only rendered when the ElementText is visible.
|
|
6
|
-
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(1);});it('should reset value when rule applies',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Builder,{config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'},bar:{label:'bar',type:'text',"default":'default',actions:[{type:'setValue',params:{value:'cheat',type:'fixed'},rules:[{context:'foo',type:'notIn',data:['default']}]}]}}},name:"foo",handleUpdate:function handleUpdate(){}}));// Default values should be in the inputs.
|
|
7
|
-
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);expect(wrapper.find('input').at(0).props().value).toEqual('default');expect(wrapper.find('input').at(1).props().value).toEqual('default');// Simulate text input to trigger rule.
|
|
8
|
-
wrapper.find('input').first().simulate('change',{target:{value:'abc'}});wrapper.update();// Second field should be hidden now.
|
|
9
|
-
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);expect(wrapper.find('input').at(0).props().value).toEqual('abc');expect(wrapper.find('input').at(1).props().value).toEqual('cheat');});it('should call onChange callback when input is changed',function(){var handleUpdate=jest.fn();var wrapper=mount(/*#__PURE__*/React.createElement(Builder,{config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'}}},name:"foo",id:"foo",handleUpdate:handleUpdate}));// Should call with initial state.
|
|
10
|
-
expect(wrapper).toMatchSnapshot();expect(handleUpdate).toHaveBeenCalledWith({foo:'default'},false,[]);handleUpdate.mockClear();// Update input
|
|
11
|
-
wrapper.find('input').first().simulate('change',{target:{value:'abc'}});// Should call with updated state.
|
|
12
|
-
expect(handleUpdate).toHaveBeenCalledWith({foo:'abc'},false,[]);});describe('Builder::elementChangeHandler',function(){it('should take the updated state from action listener',function(){// Create mocked Form builder.
|
|
13
|
-
var handleUpdate=jest.fn();var builder=new Builder({validationErrors:[],config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'}}},handleUpdate:handleUpdate});builder.actionListener.notify=function(){return{formData:{foo:'bar'},validationErrors:{},elementVisibility:{foo:true}};};// Trigger update
|
|
14
|
-
builder.elementChangeHandler('foo','bar');// Test
|
|
15
|
-
expect(handleUpdate).toHaveBeenCalledWith({foo:'bar'},false,[]);});it('should forward validation errors from form actions',function(){// Create mocked Form builder.
|
|
16
|
-
var handleUpdate=jest.fn();var builder=new Builder({validationErrors:[],config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'}}},handleUpdate:handleUpdate});// This mock handler adds a validation error for the field 'foo'
|
|
17
|
-
builder.actionListener.notify=function(){return{formData:{foo:'bar'},validationErrors:{foo:'bar baz!'},elementVisibility:{foo:true}};};// Trigger update
|
|
18
|
-
builder.elementChangeHandler('foo','bar');// Test
|
|
19
|
-
expect(handleUpdate).toHaveBeenCalledWith({foo:'bar'},true,[{path:'foo',message:'bar baz!'}]);});});describe('Builder::elementSortFunc',function(){var builder=new Builder({validationErrors:[],config:{fields:{}},handleUpdate:jest.fn()});var field1={id:'foo',label:'foo'};var field2={id:'foo2',label:'foo2'};it('should keep sortOrder for undefined',function(){expect([field2,field1].sort(builder.elementSortFunc)).toEqual([field2,field1]);});it('should sort elements',function(){var fields=[_extends({},field1,{sortOrder:2}),_extends({},field2,{sortOrder:1})];expect(fields.sort(builder.elementSortFunc)).toEqual(fields.reverse());});it('should keep sortOrder',function(){var fields=[_extends({},field2,{sortOrder:1}),_extends({},field1,{sortOrder:2})];expect(fields.sort(builder.elementSortFunc)).toEqual([].concat(fields));});});});/* eslint-enable extra-rules/no-single-line-objects */
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
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 ActionListener from"./ActionListener";import{ACTION_TYPE_SET_VISIBILITY,ACTION_TYPE_SET_VALUE,ACTION_TYPE_TRANSFORM,ACTION_SET_VALUE_COPY_FROM,ACTION_RULE_TYPE_ONE_OF}from"./ActionListener.constants";jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){}}};});/**
|
|
2
|
-
* Mock for provinces
|
|
3
|
-
* @returns {{ST: string}}
|
|
4
|
-
*/var mockGetProvincesList=function mockGetProvincesList(){return{ST:'State',DF:'Default-State'};};describe('ActionListener',function(){describe('createSetVisibilityHandler',function(){it('should handle visibility changes correctly',function(){// -------------------------------------------------------------------------------------------
|
|
5
|
-
var element={id:'province'};var action={type:ACTION_TYPE_SET_VISIBILITY,rules:[{context:'country',type:ACTION_RULE_TYPE_ONE_OF,data:['US']}]};var actionListener=new ActionListener(mockGetProvincesList,{});var handler=actionListener.createSetVisibilityHandler(element,action);var nextState;var expected;// Perform "make visible" test
|
|
6
|
-
nextState={formData:{country:'US'}};expected={formData:{country:'US'},elementVisibility:{province:true}};expect(handler({},nextState)).toEqual(expected);// Perform "make invisible" test
|
|
7
|
-
nextState={formData:{country:''}};expected={formData:{country:''},elementVisibility:{province:false}};expect(handler({},nextState)).toEqual(expected);});it('should handle call follow up changes correctly when visibility changed',function(){// -------------------------------------------------------------------------------------------
|
|
8
|
-
var element={id:'province'};var action={type:ACTION_TYPE_SET_VISIBILITY,rules:[{context:'country',type:ACTION_RULE_TYPE_ONE_OF,data:['US']}]};var actionListener=new ActionListener(mockGetProvincesList,{});var handleVisibility=actionListener.createSetVisibilityHandler(element,action);// Province element is supposed to be hidden and therefore the follow up
|
|
9
|
-
var followUpHandler=jest.fn();actionListener.register('province',followUpHandler);var prevState={formData:{province:'to be changed'}};var nextStateBeforeVisibilityChange={formData:{country:'',province:'to be changed'}};var nextStateAfterVisibilityChange={elementVisibility:{province:false},formData:{country:''}};handleVisibility(prevState,nextStateBeforeVisibilityChange);expect(followUpHandler).toHaveBeenCalledWith(prevState,nextStateAfterVisibilityChange);});});describe('updateProvinceElementHandler',function(){it('should select the first province in the list, when country changes and no default is '+'available',function(){// -------------------------------------------------------------------------------------------
|
|
10
|
-
var element={id:'province',required:true};var action={type:'update',rules:[{context:'country'}]};var actionListener=new ActionListener(mockGetProvincesList,{});var handler=actionListener.createUpdateProvinceElementHandler(element,action);var prevState={formData:{province:''}};var nextState={formData:{country:'US'}};// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
11
|
-
var expected={formData:{country:'US',province:'ST'}};expect(handler(prevState,nextState)).toEqual(expected);});it('should select the default province in the list on country changes when a match with '+'default is available',function(){var _formData2;// -------------------------------------------------------------------------------------------
|
|
12
|
-
var provinceElement={id:'province',"default":'DF',required:true};var countryElement={id:'country',"default":'US'};var action={type:'update',rules:[{context:countryElement.id}]};var prevState={};var nextState={formData:_defineProperty({},countryElement.id,countryElement["default"])};var expected={formData:(_formData2={},_defineProperty(_formData2,provinceElement.id,provinceElement["default"]),_defineProperty(_formData2,countryElement.id,countryElement["default"]),_formData2)};// Defaults matches the same object structure as 'formData'
|
|
13
|
-
var actionListener=new ActionListener(mockGetProvincesList,expected.formData);var handler=actionListener.createUpdateProvinceElementHandler(provinceElement,action);// Expects the handler to take over the defaults in this test
|
|
14
|
-
expect(handler(prevState,nextState)).toEqual(expected);});});describe('setValueHandler',function(){it('should create copy the referenced element value into the current element',function(){// -------------------------------------------------------------------------------------------
|
|
15
|
-
var element={id:'street2'};var action={type:ACTION_TYPE_SET_VALUE,params:{type:ACTION_SET_VALUE_COPY_FROM,value:'street'}};var actionListener=new ActionListener(mockGetProvincesList,{});var handler=actionListener.createSetValueHandler(element,action);// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
16
|
-
var prevState={formData:{street:'',street2:''}};// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
17
|
-
var nextState={formData:{street:'Street 1',street2:''}};// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
18
|
-
var expected={formData:{street:'Street 1',street2:'Street 1'}};expect(handler(prevState,nextState)).toEqual(expected);});});describe('transformHandler',function(){it('should apply the transformHandler correctly for "String" operations',function(){// -------------------------------------------------------------------------------------------
|
|
19
|
-
var element={id:'street'};var action={type:ACTION_TYPE_TRANSFORM,params:{type:'toUpperCase'}};var actionListener=new ActionListener(mockGetProvincesList,{});var handler=actionListener.createTransformHandler(element,action);var prevState={formData:{street:''}};var nextState={formData:{street:'Street'}};var expected={formData:{street:'STREET'}};expect(handler(prevState,nextState)).toEqual(expected);});it('should apply the transformHandler correctly for "Boolean" operations',function(){// -------------------------------------------------------------------------------------------
|
|
20
|
-
var element={id:'boolTest'};var action={type:ACTION_TYPE_TRANSFORM,params:{type:'toString'}};var actionListener=new ActionListener(mockGetProvincesList,{});var handler=actionListener.createTransformHandler(element,action);var prevState={formData:{boolTest:true}};var nextState={formData:{boolTest:true}};var expected={formData:{boolTest:'true'}};expect(handler(prevState,nextState)).toEqual(expected);});it('should apply the transformHandler correctly for "Number" operations',function(){// -------------------------------------------------------------------------------------------
|
|
21
|
-
var element={id:'numberTest'};var action={type:ACTION_TYPE_TRANSFORM,params:{type:'isInteger'}};var actionListener=new ActionListener(mockGetProvincesList,{});var handler=actionListener.createTransformHandler(element,action);var prevState={formData:{numberTest:7.88}};var nextState={formData:{numberTest:7.88}};var expected={formData:{numberTest:false}};expect(handler(prevState,nextState)).toEqual(expected);});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import buildCountryList from"./buildCountryList";jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){}}};});var countryElement={countries:['DE','US']};describe('Builder/helpers/buildCountryList',function(){it('should return empty list when config is wrong',function(){expect(buildCountryList({countries:''})).toEqual({});});it('should return list with 2 countries',function(){var expected={DE:'Germany',US:'United States'};expect(buildCountryList(countryElement)).toEqual(expected);});it('should return list with 2 countries and optional on top',function(){var expected={'':'',DE:'Germany',US:'United States'};expect(buildCountryList(countryElement,{'':''})).toEqual(expected);});it('should ignore unknown countries',function(){var expected={DE:'Germany'};expect(buildCountryList({countries:['DE','XX']})).toEqual(expected);});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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);}/* eslint-disable extra-rules/no-single-line-objects */import{ELEMENT_TYPE_SELECT}from"../Builder.constants";import buildFormDefaults from"./buildFormDefaults";var formElement={id:'field',"default":'foo',custom:false};var defaults={field:'baz',customAttributes:{}};describe('Builder/helpers/buildFormDefaults',function(){it('should build defaults from element defaults',function(){var expected={field:'foo'};expect(buildFormDefaults([formElement],{})).toEqual(expected);});it('should build defaults from object defaults ',function(){var expected={field:'baz'};expect(buildFormDefaults([formElement],defaults)).toEqual(expected);});it('should build defaults for custom from element defaults',function(){var expected={field:'foo'};var el=_extends({},formElement,{custom:true});expect(buildFormDefaults([el],defaults)).toEqual(expected);});it('should build defaults for custom from object defaults',function(){var expected={field:'baz'};var el=_extends({},formElement,{custom:true});var def=_extends({},defaults,{customAttributes:{field:'baz'}});expect(buildFormDefaults([el],def)).toEqual(expected);});describe('ELEMENT_TYPE_SELECT',function(){var options={mr:'Mr.',mrs:'Mrs.'};it('should set default value',function(){var el=_extends({},formElement,{type:ELEMENT_TYPE_SELECT,options:options});expect(buildFormDefaults([el])).toEqual({field:'foo'});});it('should set first option',function(){var el=_extends({},formElement,{type:ELEMENT_TYPE_SELECT,options:options,"default":null});expect(buildFormDefaults([el])).toEqual({field:'mr'});});});});/* eslint-enable extra-rules/no-single-line-objects */
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var _excluded=["handleChange"],_excluded2=["handleChange"],_excluded3=["handleChange"];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 _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{ELEMENT_TYPE_COUNTRY}from"../Builder.constants";import buildFormElements from"./buildFormElements";jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){}}};});var formElementConfig={sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true};var formElement={id:'field',sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true,custom:false};describe('Builder/helpers/buildFormElements',function(){it('should not build custom field',function(){var config={fields:{custom:formElementConfig}};expect(buildFormElements(config)).toEqual([]);});it('should not build empty config',function(){var config={fields:{}};expect(buildFormElements(config)).toEqual([]);});it('should build text element',function(){var config={fields:{field:formElementConfig}};var _buildFormElements$=buildFormElements(config)[0],ignore=_buildFormElements$.handleChange,restElement=_objectWithoutProperties(_buildFormElements$,_excluded);expect(restElement).toEqual(formElement);});it('should build 1 country element',function(){var config={fields:{country:_extends({},formElementConfig,{type:ELEMENT_TYPE_COUNTRY}),// eslint-disable-next-line camelcase
|
|
2
|
-
country_2:_extends({},formElementConfig,{type:ELEMENT_TYPE_COUNTRY})}};var expected=_extends({},formElement,{id:'country',type:ELEMENT_TYPE_COUNTRY});var _buildFormElements$2=buildFormElements(config)[0],ignore=_buildFormElements$2.handleChange,restElement=_objectWithoutProperties(_buildFormElements$2,_excluded2);expect(restElement).toEqual(expected);});it('should build custom text element',function(){var config={fields:{custom:{field:formElementConfig}}};var expected=_extends({},formElement,{custom:true});var _buildFormElements$3=buildFormElements(config)[0],ignore=_buildFormElements$3.handleChange,restElement=_objectWithoutProperties(_buildFormElements$3,_excluded3);expect(restElement).toEqual(expected);});it('should build correct change handler for text field',function(){var config={fields:{field:formElementConfig}};var mockHandler=jest.fn();var handleChange=buildFormElements(config,mockHandler)[0].handleChange;// Invoke handler with field value
|
|
3
|
-
handleChange('bar');expect(mockHandler).toBeCalledWith('field','bar');});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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);}import iso3166 from"./iso-3166-2";import buildProvinceList from"./buildProvinceList";describe('Builder/helpers/buildProvinceList',function(){it('should return empty list when country is unknown',function(){expect(buildProvinceList('SOME')).toEqual({});});it('should return a list with US provinces',function(){var expected=iso3166.US.divisions;expect(buildProvinceList('US')).toEqual(expected);});it('should return a list with US provinces and optional',function(){var expected=_extends({'':''},iso3166.US.divisions);expect(buildProvinceList('US',{'':''})).toEqual(expected);});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import IntersectionVisibility from"../index";describe('<IntersectionVisibility />',function(){it('should build a list of 5 thresholds',function(){expect(IntersectionVisibility.buildThresholdList(5)).toEqual([0.20,0.40,0.60,0.80,1.00]);});it('should build a list of 20 thresholds',function(){expect(IntersectionVisibility.buildThresholdList(20)).toEqual([0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1]);});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var context={top:20,bottom:40,ariaHidden:false,set:jest.fn(),setTop:jest.fn(),setBottom:jest.fn(),setContentRef:jest.fn(),getContentRef:jest.fn(),scrollTop:jest.fn(),setAriaHidden:jest.fn()};export var ViewContext={Consumer:function Consumer(props){return props.children(context);}};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import React from'react';import PropTypes from'prop-types';// Export context mock
|
|
2
|
-
export{ViewContext}from"./context";/**
|
|
3
|
-
* @param {Object} props The component props.
|
|
4
|
-
* @return {JSX}
|
|
5
|
-
*/var MockedView=function MockedView(_ref){var children=_ref.children;return/*#__PURE__*/React.createElement("div",null,children);};MockedView.defaultProps={children:null};export default MockedView;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import{mockThemeConfig}from'@shopgate/pwa-common/helpers/config/mock';import{setBackgroundColor}from"../style";import View from"../index";jest.mock('@shopgate/pwa-common/helpers/config',function(){return{themeConfig:mockThemeConfig};});jest.mock('@shopgate/pwa-common/context',function(){return{RouteContext:{Consumer:jest.fn(function(_ref){var children=_ref.children;return children({visible:true});})}};});jest.mock("../provider",function(){return function(_ref2){var children=_ref2.children;return children;};});jest.mock("../context");jest.mock("../style",function(){return{__esModule:true,"default":jest.requireActual('../style')["default"],setBackgroundColor:jest.fn()};});describe('engage > components > view > index',function(){beforeEach(jest.clearAllMocks);var wrapper;beforeAll(function(){wrapper=shallow(/*#__PURE__*/React.createElement(View,null,/*#__PURE__*/React.createElement("div",null,"Page #1")));});it('should initialize with visible route',function(){expect(wrapper.dive()).toMatchSnapshot();});it('should have structured content',function(){expect(wrapper.dive().dive().dive().dive()).toMatchSnapshot();});it('should set background on intialization',function(){wrapper=shallow(/*#__PURE__*/React.createElement(View,{background:"#990000"},/*#__PURE__*/React.createElement("div",null,"Page #1"))).dive().dive();expect(setBackgroundColor).toBeCalledWith('#990000');});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import Provider from"../provider";jest.mock("../context");describe('engage > components > view > provider',function(){it('should initialize and provider context',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(Provider,null,/*#__PURE__*/React.createElement("div",null,"Page #1")));expect(wrapper).toMatchSnapshot();});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import Above from"../index";jest.mock("../../../context");describe('engage > components > view > components > above',function(){it('should render above',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(Above,null)).dive();expect(wrapper).toMatchSnapshot();});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import Below from"../index";jest.mock("../../../context");describe('engage > components > view > components > below',function(){it('should render below',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(Below,null)).dive();expect(wrapper).toMatchSnapshot();});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import Content from"../index";jest.mock('@shopgate/pwa-common/helpers/config',function(){return{shopName:'Test Shop'};});jest.mock('@shopgate/pwa-common/context',function(){return{RouteContext:{Consumer:jest.fn(function(_ref){var children=_ref.children;return children({visible:true,pattern:'page/:pageId,'});})}};});describe('engage > components > view > components > content',function(){beforeEach(jest.clearAllMocks);it('should render content',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(Content,{setContentRef:jest.fn()},/*#__PURE__*/React.createElement("div",null,"Page #1")),{disableLifecycleMethods:true})// Dive through Route context and into render component
|
|
2
|
-
.dive().dive();expect(wrapper).toMatchSnapshot();});});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/* eslint-disable require-jsdoc */import Sheet from'@shopgate/pwa-ui-shared/Sheet';// ICONS IOS
|
|
2
|
-
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
|
|
3
|
-
export{default as ShareIconAndroid}from'@shopgate/pwa-ui-material/icons/ShareIcon';// ICONS SHARED
|
|
4
|
-
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 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 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 LocalShippingIcon}from'@shopgate/pwa-ui-shared/icons/LocalShippingIcon';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 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 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';/** @returns {ReactElement} */export var SurroundPortals=function SurroundPortals(_ref){var children=_ref.children;return children;};/** @returns {ReactElement} */export var HtmlSanitizer=function HtmlSanitizer(_ref2){var children=_ref2.children;return children;};export var SheetDrawer=Sheet;export var SheetList=function SheetList(_ref3){var children=_ref3.children;return children;};export var I18n={Text:function Text(){return'I18n.Text';}};export var PlaceholderParagraph=function PlaceholderParagraph(_ref4){var children=_ref4.children;return children;};export{default as View,ViewContext}from"../View/__mocks__/index";/* eslint-enable require-jsdoc */
|
package/components/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as components from'.';describe('engage > components',function(){it('should have exports',function(){expect(_typeof(components)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(components).forEach(function(exportKey){expect(typeof components[exportKey]!=='undefined').toBe(true);});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}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 grantGeolocationPermissions from"../grantGeolocationPermissions";import getGeolocation from"../getGeolocation";import{GEOLOCATION_ERROR_DENIED}from"../../constants/geolocationRequest";var mockedPosition={coords:{accuracy:25,latitude:50.4330,longitude:8.67447},timestamp:1563873516224};var mockedGeolocationRequest=jest.fn().mockResolvedValue(mockedPosition);jest.mock("../grantGeolocationPermissions",function(){return jest.fn().mockResolvedValue(true);});jest.mock("../../classes/GeolocationRequest",function(){return/*#__PURE__*/function(){function Foo(){_classCallCheck(this,Foo);}_createClass(Foo,[{key:"dispatch",value:// eslint-disable-next-line require-jsdoc, class-methods-use-this
|
|
2
|
-
function dispatch(){return mockedGeolocationRequest();}}]);return Foo;}();});describe('engage > core > actions > grantCameraPermissions',function(){var dispatch=jest.fn(function(action){return action;});beforeEach(function(){jest.clearAllMocks();});it('should resolve the with current position',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var position;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return getGeolocation()(dispatch);case 2:position=_context.sent;expect(position).toBe(mockedPosition);expect(dispatch).toHaveBeenCalledTimes(1);expect(grantGeolocationPermissions).toHaveBeenCalledTimes(1);expect(grantGeolocationPermissions).toHaveBeenCalledWith({});expect(mockedGeolocationRequest).toHaveBeenCalledTimes(1);case 8:case"end":return _context.stop();}}},_callee);})));it('should pass through the options to the grantGeolocationPermissions action call',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){var options;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:options={useSettingsModal:true,modal:{message:'Modal message',confirm:'Confirm label'}};_context2.next=3;return expect(getGeolocation(options)(dispatch)).resolves.toBe(mockedPosition);case 3:expect(grantGeolocationPermissions).toHaveBeenCalledWith(options);case 4:case"end":return _context2.stop();}}},_callee2);})));it('should reject with an error when permissions are not granted',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:grantGeolocationPermissions.mockResolvedValueOnce(false);expect.assertions(4);_context3.prev=2;_context3.next=5;return getGeolocation()(dispatch);case 5:_context3.next=13;break;case 7:_context3.prev=7;_context3.t0=_context3["catch"](2);expect(_context3.t0).toBeInstanceOf(Error);expect(_context3.t0.code).toBe(GEOLOCATION_ERROR_DENIED);expect(grantGeolocationPermissions).toHaveBeenCalledTimes(1);expect(mockedGeolocationRequest).not.toHaveBeenCalled();case 13:case"end":return _context3.stop();}}},_callee3,null,[[2,7]]);})));it('should reject with an error when permissions are not granted',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:mockedGeolocationRequest.mockRejectedValueOnce(new Error());expect.assertions(3);_context4.prev=2;_context4.next=5;return getGeolocation()(dispatch);case 5:_context4.next=12;break;case 7:_context4.prev=7;_context4.t0=_context4["catch"](2);expect(_context4.t0).toBeInstanceOf(Error);expect(grantGeolocationPermissions).toHaveBeenCalledTimes(1);expect(mockedGeolocationRequest).toHaveBeenCalledTimes(1);case 12:case"end":return _context4.stop();}}},_callee4,null,[[2,7]]);})));});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{PERMISSION_ID_CAMERA}from'@shopgate/pwa-core/constants/AppPermissions';import grantPermissions from"../grantPermissions";import grantCameraPermissions from"../grantCameraPermissions";jest.mock("../grantPermissions",function(){return jest.fn().mockReturnValue('grantPermissions');});describe('engage > core > actions > grantCameraPermissions',function(){var dispatch=jest.fn(function(action){return action;});beforeEach(function(){jest.clearAllMocks();});it('should dispatch as expected without options',function(){var result=grantCameraPermissions()(dispatch);expect(result).toEqual(grantPermissions());expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(grantPermissions());expect(grantPermissions).toHaveBeenCalledTimes(3);expect(grantPermissions).toHaveBeenCalledWith({permissionId:PERMISSION_ID_CAMERA,useSettingsModal:false,modal:{title:null,message:'permissions.access_denied.camera_message',confirm:'permissions.access_denied.settings_button'}});});it('should dispatch as expected with some custom modal options',function(){var customModalOptions={title:'Modal title',dismiss:'Dismiss label'};var result=grantCameraPermissions({useSettingsModal:true,modal:customModalOptions})(dispatch);expect(result).toEqual(grantPermissions());expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(grantPermissions());expect(grantPermissions).toHaveBeenCalledTimes(3);expect(grantPermissions).toHaveBeenCalledWith({permissionId:PERMISSION_ID_CAMERA,useSettingsModal:true,modal:{title:'Modal title',message:'permissions.access_denied.camera_message',confirm:'permissions.access_denied.settings_button',dismiss:'Dismiss label'}});});it('should dispatch as expected with complete custom modal options',function(){var customModalOptions={title:'Modal title',message:'Modal message',confirm:'Confirm label',dismiss:'Dismiss label',params:{param:'one'}};var result=grantCameraPermissions({useSettingsModal:true,modal:customModalOptions})(dispatch);expect(result).toEqual(grantPermissions());expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(grantPermissions());expect(grantPermissions).toHaveBeenCalledTimes(3);expect(grantPermissions).toHaveBeenCalledWith({permissionId:PERMISSION_ID_CAMERA,useSettingsModal:true,modal:customModalOptions});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{PERMISSION_ID_LOCATION}from'@shopgate/pwa-core/constants/AppPermissions';import grantPermissions from"../grantPermissions";import grantGeolocationPermissions from"../grantGeolocationPermissions";jest.mock("../grantPermissions",function(){return jest.fn().mockReturnValue('grantPermissions');});describe('engage > core > actions > grantGeolocationPermissions',function(){var dispatch=jest.fn(function(action){return action;});beforeEach(function(){jest.clearAllMocks();});it('should dispatch as expected without options',function(){var result=grantGeolocationPermissions()(dispatch);expect(result).toEqual(grantPermissions());expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(grantPermissions());expect(grantPermissions).toHaveBeenCalledTimes(3);expect(grantPermissions).toHaveBeenCalledWith({permissionId:PERMISSION_ID_LOCATION,useSettingsModal:false,modal:{title:null,message:'permissions.access_denied.geolocation_message',confirm:'permissions.access_denied.settings_button'}});});it('should dispatch as expected with some custom modal options',function(){var customModalOptions={title:'Modal title',dismiss:'Dismiss label'};var result=grantGeolocationPermissions({useSettingsModal:true,modal:customModalOptions})(dispatch);expect(result).toEqual(grantPermissions());expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(grantPermissions());expect(grantPermissions).toHaveBeenCalledTimes(3);expect(grantPermissions).toHaveBeenCalledWith({permissionId:PERMISSION_ID_LOCATION,useSettingsModal:true,modal:{title:'Modal title',message:'permissions.access_denied.geolocation_message',confirm:'permissions.access_denied.settings_button',dismiss:'Dismiss label'}});});it('should dispatch as expected with complete custom modal options',function(){var customModalOptions={title:'Modal title',message:'Modal message',confirm:'Confirm label',dismiss:'Dismiss label',params:{param:'one'}};var result=grantGeolocationPermissions({useSettingsModal:true,modal:customModalOptions})(dispatch);expect(result).toEqual(grantPermissions());expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(grantPermissions());expect(grantPermissions).toHaveBeenCalledTimes(3);expect(grantPermissions).toHaveBeenCalledWith({permissionId:PERMISSION_ID_LOCATION,useSettingsModal:true,modal:customModalOptions});});});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
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);}import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import event from'@shopgate/pwa-core/classes/Event';import{APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND}from'@shopgate/pwa-core/constants/AppEvents';import openAppSettings from'@shopgate/pwa-core/commands/openAppSettings';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{STATUS_DENIED,STATUS_GRANTED,STATUS_NOT_DETERMINED,STATUS_NOT_SUPPORTED,PERMISSION_ID_CAMERA}from'@shopgate/pwa-core/constants/AppPermissions';import{getAppPermissions,requestAppPermissions}from'@shopgate/pwa-core/commands/appPermissions';import{logger}from'@shopgate/pwa-core/helpers';import grantPermissions from"../grantPermissions";jest.mock('@shopgate/pwa-core/classes/Event');jest.mock('@shopgate/pwa-core/commands/openAppSettings');jest.mock('@shopgate/pwa-core/commands/appPermissions',function(){return{getAppPermissions:jest.fn(),requestAppPermissions:jest.fn()};});jest.mock('@shopgate/pwa-common/actions/modal/showModal',function(){return jest.fn();});jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:jest.fn()}};});/**
|
|
2
|
-
* @param {string} status The desired permission status.
|
|
3
|
-
* @returns {Array}
|
|
4
|
-
*/var getPermissionsResponse=function getPermissionsResponse(){var status=arguments.length>0&&arguments[0]!==undefined?arguments[0]:STATUS_GRANTED;return[{status:status}];};/**
|
|
5
|
-
* Flushes the promise queue.
|
|
6
|
-
* @returns {Promise}
|
|
7
|
-
*/var flushPromises=function flushPromises(){return new Promise(function(resolve){return setImmediate(resolve);});};var customModalOptions={message:'Modal message',confirm:'Confirm label',dismiss:'Dismiss label',params:{param:'one'}};describe('engage > core > actions > grantPermissions',function(){var dispatch=jest.fn(function(action){return action;});jest.useFakeTimers();beforeAll(function(){getAppPermissions.mockResolvedValue(getPermissionsResponse(STATUS_GRANTED));requestAppPermissions.mockResolvedValue(getPermissionsResponse(STATUS_GRANTED));showModal.mockResolvedValue(true);});beforeEach(function(){jest.clearAllMocks();event.removeAllListeners();});var permissionId=PERMISSION_ID_CAMERA;it('should resolve with TRUE when the permissions are granted',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var granted;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return grantPermissions({permissionId:permissionId})(dispatch);case 2:granted=_context.sent;expect(granted).toBe(true);expect(getAppPermissions).toHaveBeenCalledWith([permissionId]);expect(requestAppPermissions).not.toHaveBeenCalled();expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();case 9:case"end":return _context.stop();}}},_callee);})));it('should resolve with FALSE when called with an invalid permissionId',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){var granted;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.next=2;return grantPermissions({permissionId:'unknownId'})(dispatch);case 2:granted=_context2.sent;expect(granted).toBe(false);expect(getAppPermissions).not.toHaveBeenCalled();expect(requestAppPermissions).not.toHaveBeenCalled();expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).toHaveBeenCalledTimes(1);case 10:case"end":return _context2.stop();}}},_callee2);})));it('should resolve with FALSE when the permissions are not supported',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){var granted;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_NOT_SUPPORTED));_context3.next=3;return grantPermissions({permissionId:permissionId})(dispatch);case 3:granted=_context3.sent;expect(granted).toBe(false);expect(getAppPermissions).toHaveBeenCalledWith([permissionId]);expect(requestAppPermissions).not.toHaveBeenCalled();expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 11:case"end":return _context3.stop();}}},_callee3);})));it('should resolve with TRUE when the permissions where not determined, but the user granted them',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){var granted;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_NOT_DETERMINED));_context4.next=3;return grantPermissions({permissionId:permissionId})(dispatch);case 3:granted=_context4.sent;expect(granted).toBe(true);expect(getAppPermissions).toHaveBeenCalledWith([permissionId]);expect(requestAppPermissions).toHaveBeenCalledWith([{permissionId:permissionId}]);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 11:case"end":return _context4.stop();}}},_callee4);})));it('should resolve with FALSE when the permissions where not determined, and the user denied them',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(){var granted;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_NOT_DETERMINED));requestAppPermissions.mockResolvedValue(getPermissionsResponse(STATUS_DENIED));_context5.next=4;return grantPermissions({permissionId:permissionId})(dispatch);case 4:granted=_context5.sent;expect(granted).toBe(false);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 10:case"end":return _context5.stop();}}},_callee5);})));it('should resolve with FALSE when the permissions where not determined, and the user denied them temporary',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(){var granted;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_NOT_DETERMINED));requestAppPermissions.mockResolvedValue(getPermissionsResponse(STATUS_NOT_DETERMINED));_context6.next=4;return grantPermissions({permissionId:permissionId})(dispatch);case 4:granted=_context6.sent;expect(granted).toBe(false);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 10:case"end":return _context6.stop();}}},_callee6);})));it('should resolve with FALSE when the permissions are denied, and no settings modal is about to be shown',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(){var granted;return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_DENIED));_context7.next=3;return grantPermissions({permissionId:permissionId})(dispatch);case 3:granted=_context7.sent;expect(granted).toBe(false);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 9:case"end":return _context7.stop();}}},_callee7);})));it('should resolve with FALSE when the user denied to open the app settings',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(){var granted;return _regeneratorRuntime.wrap(function _callee8$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_DENIED));showModal.mockResolvedValueOnce(false);_context8.next=4;return grantPermissions({permissionId:permissionId,useSettingsModal:true,modal:customModalOptions})(dispatch);case 4:granted=_context8.sent;expect(granted).toBe(false);expect(dispatch).toHaveBeenCalledTimes(1);expect(showModal).toHaveBeenCalledWith(_extends({title:null},customModalOptions));expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();case 10:case"end":return _context8.stop();}}},_callee8);})));it('should resolve with FALSE when the user opened the settings, but did not grant permissions',function(done){getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_DENIED));getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_DENIED));grantPermissions({permissionId:permissionId,useSettingsModal:true})(dispatch).then(function(granted){expect(granted).toBe(false);expect(dispatch).toHaveBeenCalledTimes(1);expect(openAppSettings).toHaveBeenCalledTimes(1);expect(event.removeCallbackSpy).toHaveBeenCalledWith(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,expect.any(Function));done();});// Flush the promise queue, so that the code inside of promise from the action is executed.
|
|
8
|
-
flushPromises().then(function(){event.call(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND);jest.runAllTimers();});});it('should resolve with TRUE when the user opened the settings, and granted permissions',function(done){getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_DENIED));getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(STATUS_GRANTED));grantPermissions({permissionId:permissionId,useSettingsModal:true})(dispatch).then(function(granted){expect(granted).toBe(true);expect(dispatch).toHaveBeenCalledTimes(1);expect(openAppSettings).toHaveBeenCalledTimes(1);expect(event.removeCallbackSpy).toHaveBeenCalledWith(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,expect.any(Function));done();});// Flush the promise queue, so that the code inside of promise from the action is executed.
|
|
9
|
-
flushPromises().then(function(){event.call(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND);jest.runAllTimers();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isIos}from'@shopgate/pwa-common/selectors/client';import{updateLegacyNavigationBar}from"../../helpers/updateLegacyNavigationBar";import updateStatusBarBackground from"../updateStatusBarBackground";jest.mock("../../helpers/updateLegacyNavigationBar",function(){return{updateLegacyNavigationBar:jest.fn()};});jest.mock('@shopgate/pwa-common/selectors/client',function(){return{isIos:jest.fn().mockReturnValue(true)};});describe('engage > core > actions > updateStatusBarBackground()',function(){var color='#000';var state={some:'state'};var getState=jest.fn().mockReturnValue(state);beforeEach(function(){jest.clearAllMocks();});it('should do nothing when the device does not run with iOS',function(){isIos.mockReturnValueOnce(false);updateStatusBarBackground(color)(null,getState);expect(isIos).toHaveBeenCalledWith(state);expect(updateLegacyNavigationBar).not.toHaveBeenCalled();});it('should call the updateLegacyNavigationBar helper with the passed color',function(){updateStatusBarBackground(color)(null,getState);expect(isIos).toHaveBeenCalledWith(state);expect(updateLegacyNavigationBar).toHaveBeenCalledTimes(1);expect(updateLegacyNavigationBar).toHaveBeenCalledWith({statusBarBackground:color,isDefault:false});});it('should call the updateLegacyNavigationBar helper with the isDefault flag',function(){updateStatusBarBackground(null,true)(null,getState);expect(isIos).toHaveBeenCalledWith(state);expect(updateLegacyNavigationBar).toHaveBeenCalledTimes(1);expect(updateLegacyNavigationBar).toHaveBeenCalledWith({isDefault:true});});it('should call the updateLegacyNavigationBar helper with just the isDefault property when no color was passed',function(){updateStatusBarBackground()(null,getState);expect(isIos).toHaveBeenCalledWith(state);expect(updateLegacyNavigationBar).toHaveBeenCalledTimes(1);expect(updateLegacyNavigationBar).toHaveBeenCalledWith({isDefault:false});});});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}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);}import GeolocationRequest,{GEOLOCATION_DEFAULT_TIMEOUT}from"../GeolocationRequest";import{GEOLOCATION_ERROR_UNKNOWN,GEOLOCATION_ERROR_DENIED,GEOLOCATION_ERROR_UNAVAILABLE,GEOLOCATION_ERROR_TIMEOUT}from"../../constants/geolocationRequest";var successPayload;var errorPayload;var getCurrentPosition=jest.fn().mockImplementation(function(successCb,errorCb){if(errorPayload){errorCb(errorPayload);return;}successCb(successPayload);});global.navigator.geolocation={getCurrentPosition:getCurrentPosition};var mockSuccessPayload={coords:{accuracy:25,latitude:50.4330,longitude:8.67447},timestamp:1563873516224};describe('GeolocationRequest',function(){var instance;beforeEach(function(){jest.clearAllMocks();successPayload=_extends({},mockSuccessPayload);errorPayload=null;instance=new GeolocationRequest();});it('should initialize the options as expected',function(){expect(instance.options).toEqual({timeout:GEOLOCATION_DEFAULT_TIMEOUT});});describe('.setTimeout()',function(){it('should set a new timeout',function(){var result=instance.setTimeout(5000);expect(instance.options.timeout).toBe(5000);expect(result).toBe(instance);});it('should set the default timeout when called without a value',function(){instance.setTimeout(5000);expect(instance.options.timeout).toBe(5000);var result=instance.setTimeout();expect(instance.options.timeout).toBe(GEOLOCATION_DEFAULT_TIMEOUT);expect(result).toBe(instance);});});describe('.dispatch()',function(){it('should invoke getCurrentPosition() as expected',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return instance.dispatch();case 2:expect(getCurrentPosition).toHaveBeenCalledTimes(1);expect(getCurrentPosition).toHaveBeenCalledWith(expect.any(Function),expect.any(Function),instance.options);case 4:case"end":return _context.stop();}}},_callee);})));it('should resolve as expected',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){var coords;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:coords=mockSuccessPayload.coords;_context2.next=3;return expect(instance.dispatch()).resolves.toEqual({accuracy:coords.accuracy,latitude:coords.latitude,longitude:coords.longitude});case 3:case"end":return _context2.stop();}}},_callee2);})));it('should reject with the expected errors',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){var mockError;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:/**
|
|
2
|
-
* @param {string} code Error code.
|
|
3
|
-
* @param {string} message Error message.
|
|
4
|
-
* @returns {Error}
|
|
5
|
-
*/mockError=function mockError(code,message){var error=new Error(message);error.code=code;return error;};/* eslint-disable extra-rules/no-single-line-objects */errorPayload={code:0,message:'One'};_context3.next=4;return expect(instance.dispatch()).rejects.toEqual(mockError(GEOLOCATION_ERROR_UNKNOWN,'One'));case 4:errorPayload={code:1,message:'Two'};_context3.next=7;return expect(instance.dispatch()).rejects.toEqual(mockError(GEOLOCATION_ERROR_DENIED,'Two'));case 7:errorPayload={code:2,message:'Three'};_context3.next=10;return expect(instance.dispatch()).rejects.toEqual(mockError(GEOLOCATION_ERROR_UNAVAILABLE,'Three'));case 10:errorPayload={code:3,message:'Four'};_context3.next=13;return expect(instance.dispatch()).rejects.toEqual(mockError(GEOLOCATION_ERROR_TIMEOUT,'Four'));case 13:case"end":return _context3.stop();}}},_callee3);})));});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getPageConfig}from"../getPageConfig";import{getThemeConfig}from"../getThemeConfig";jest.mock("../getThemeConfig",function(){return{getThemeConfig:jest.fn()};});var requestedPagePattern='/requested/page';describe('engage > core > config',function(){describe('getPageConfig()',function(){it('should return an empty object if no pages are defined in the theme config.',function(){getThemeConfig.mockReturnValueOnce({});expect(getPageConfig(requestedPagePattern)).toEqual({});});it('should return an empty object if the page is not found.',function(){getThemeConfig.mockReturnValueOnce({pages:[]});expect(getPageConfig(requestedPagePattern)).toEqual({});});it('should only return the page, which matches the given pattern.',function(){getThemeConfig.mockReturnValueOnce({pages:[{pattern:'/some/other/page',name:'Other Page'},{pattern:requestedPagePattern,name:'Correct page'},{pattern:'/yet/another/page',name:'Yet Another Page'}]});expect(getPageConfig(requestedPagePattern)).toEqual({pattern:requestedPagePattern,name:'Correct page'});});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
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{getPageSettings}from"../getPageSettings";import{getThemeSettings}from"../getThemeSettings";import{getPageConfig}from"../getPageConfig";jest.mock("../getThemeSettings",function(){return{getThemeSettings:jest.fn()};});jest.mock("../getPageConfig",function(){return{getPageConfig:jest.fn()};});var requestedPagePattern='/requested/page';describe('engage > core > config',function(){describe('getPageSettings()',function(){beforeEach(function(){jest.resetAllMocks();});it('should return an empty object when no page settings are available and no key set.',function(){getThemeSettings.mockReturnValueOnce(undefined);getPageConfig.mockReturnValueOnce({});expect(getPageSettings(requestedPagePattern)).toEqual({});});it('should return all settings of the given page without inheriting from higher scope.',function(){getThemeSettings.mockReturnValueOnce({higher:{scope:'settings'}});getPageConfig.mockReturnValueOnce({pattern:requestedPagePattern,name:'PageName',settings:{all:{page:'settings'}}});expect(getPageSettings(requestedPagePattern)).toEqual({all:{page:'settings'}});});it('should pass down the key to the lower level functions for filtered inheritance.',function(){var matchingKey='someKey';getThemeSettings.mockReturnValueOnce({});getPageConfig.mockReturnValueOnce({});getPageSettings(requestedPagePattern,matchingKey);expect(getThemeSettings).toBeCalledWith(matchingKey);expect(getThemeSettings).toBeCalledTimes(1);});it('should return undefined when the given key does not exist in any scope of settings.',function(){getThemeSettings.mockReturnValueOnce(undefined);getPageConfig.mockReturnValueOnce({});expect(getPageSettings(requestedPagePattern,'nonExistentKey')).toBeUndefined();getThemeSettings.mockReturnValueOnce(undefined);getPageConfig.mockReturnValueOnce({settings:{someOtherKey:'someOtherValue'}});expect(getPageSettings(requestedPagePattern,'nonExistentKey')).toBeUndefined();});it('should inherit matching keys from theme settings.',function(){// Return unpacked object, not containing the key anymore, because the match is guaranteed
|
|
2
|
-
getThemeSettings.mockReturnValueOnce({things:{to:{inherit:'some inherited value'}}});getPageConfig.mockReturnValueOnce({});expect(getPageSettings(requestedPagePattern,'matchingKey')).toEqual({things:{to:{inherit:'some inherited value'}}});});it('should inherit and mix properties for keys matching theme and page settings.',function(){var _settings;var matchingKey='someKey';getThemeSettings.mockReturnValueOnce({things:{toMix:{inherit:'some inherited value',keep:'low priority'}}});getPageConfig.mockReturnValueOnce({settings:(_settings={},_defineProperty(_settings,matchingKey,{things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting'}},moreToKeep:'keep full key'}),_defineProperty(_settings,"nonMatchingKey",{ignore:'this'}),_settings)});expect(getPageSettings(requestedPagePattern,matchingKey)).toEqual({things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting',inherit:'some inherited value'}},moreToKeep:'keep full key'});});it('should not fail when there is nothing to inherit from.',function(){var _settings2;var matchingKey='someKey';getThemeSettings.mockReturnValueOnce(undefined);getPageConfig.mockReturnValueOnce({settings:(_settings2={},_defineProperty(_settings2,matchingKey,{things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting'}},moreToKeep:'keep full key'}),_defineProperty(_settings2,"nonMatchingKey",{ignore:'this'}),_settings2)});expect(getPageSettings(requestedPagePattern,matchingKey)).toEqual({things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting'}},moreToKeep:'keep full key'});});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getThemeAssets}from"../getThemeAssets";import{getThemeConfig}from"../getThemeConfig";jest.mock("../getThemeConfig",function(){return{getThemeConfig:jest.fn()};});describe('engage > core > config',function(){describe('getThemeAssets()',function(){it('should return an empty object if no assets are available without using a key.',function(){getThemeConfig.mockReturnValueOnce({});var assets=getThemeAssets();expect(assets).toEqual({});});it('should return all theme assets when no key is passed.',function(){getThemeConfig.mockReturnValueOnce({assets:{logo:'some-logo',icons:{}}});var assets=getThemeAssets();expect(assets).toEqual({logo:'some-logo',icons:{}});});it('should return only a single theme asset entry, matching the given key.',function(){getThemeConfig.mockReturnValueOnce({assets:{logo:'some-logo',icons:{}}});var assets=getThemeAssets('logo');expect(assets).toEqual('some-logo');});it('should return undefined if the requested asset key does not exist.',function(){getThemeConfig.mockReturnValueOnce({assets:{logo:'some-logo',icons:{}}});var assets=getThemeAssets('other');expect(assets).toBeUndefined();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getThemeColors}from"../getThemeColors";import{getThemeConfig}from"../getThemeConfig";jest.mock("../getThemeConfig",function(){return{getThemeConfig:jest.fn()};});describe('engage > core > config',function(){describe('getThemeColors()',function(){it('should return an empty object if no colors are available without using a key.',function(){getThemeConfig.mockReturnValueOnce({});var colors=getThemeColors();expect(colors).toEqual({});});it('should return all theme colors when no key is passed.',function(){getThemeConfig.mockReturnValueOnce({colors:{primary:'#ff0000'}});var colors=getThemeColors();expect(colors).toEqual({primary:'#ff0000'});});it('should return only a single theme color entry, matching the given key.',function(){getThemeConfig.mockReturnValueOnce({colors:{primary:'#ff0000',accent:'#47f'}});var colors=getThemeColors('accent');expect(colors).toEqual('#47f');});it('should return undefined if the requested color key does not exist.',function(){getThemeConfig.mockReturnValueOnce({colors:{primary:'#ff0000',accent:'#47f'}});var settings=getThemeColors('other');expect(settings).toBeUndefined();});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{getThemeConfig}from"../getThemeConfig";var mockAppConfig={beta:true};// Mock the config object using class getters
|
|
2
|
-
jest.mock('@shopgate/pwa-common/helpers/config',function(){return{get beta(){return mockAppConfig.beta;},get theme(){return mockAppConfig.theme;}};});describe('engage > core > config',function(){describe('getThemeConfig()',function(){it('should return all theme config props.',function(){mockAppConfig.theme='someThemeConfig';expect(getThemeConfig()).toEqual('someThemeConfig');delete mockAppConfig.theme;});it('should return an empty object if the app config is empty.',function(){expect(getThemeConfig()).toEqual({});});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getThemeSettings}from"../getThemeSettings";import{getThemeConfig}from"../getThemeConfig";jest.mock("../getThemeConfig",function(){return{getThemeConfig:jest.fn()};});describe('engage > core > config',function(){describe('getThemeSettings()',function(){it('should return an empty object if no settings are available without using a key.',function(){getThemeConfig.mockReturnValueOnce({});var settings=getThemeSettings();expect(settings).toEqual({});});it('should return all theme settings when no key is passed.',function(){getThemeConfig.mockReturnValueOnce({settings:{currency:'USD',language:'en-US'}});var settings=getThemeSettings();expect(settings).toEqual({currency:'USD',language:'en-US'});});it('should return only a single theme settings entry, matching the given key.',function(){getThemeConfig.mockReturnValueOnce({settings:{currency:'USD',language:'en-US'}});var settings=getThemeSettings('currency');expect(settings).toEqual('USD');});it('should return undefined if the requested settings key does not exist.',function(){getThemeConfig.mockReturnValueOnce({settings:{currency:'USD',language:'en-US'}});var settings=getThemeSettings('other');expect(settings).toBeUndefined();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getThemeStyles}from"../getThemeStyles";import{getThemeConfig}from"../getThemeConfig";jest.mock("../getThemeConfig",function(){return{getThemeConfig:jest.fn()};});describe('engage > core > config',function(){describe('getThemeStyles()',function(){it('should return an empty object if no styles property exists',function(){getThemeConfig.mockReturnValueOnce({});var styles=getThemeStyles();expect(styles).toEqual({});});it('should return all styles if no key is given',function(){var mockStyles={'@shopgate/engage/product/ProductGrid':{color:'red'},'@shopgate/engage/product/ProductSlider':{color:'blue'}};getThemeConfig.mockReturnValueOnce({styles:mockStyles});var styles=getThemeStyles();expect(styles).toEqual(mockStyles);});it('should return specific styles if key is given',function(){var mockStyles={'@shopgate/engage/product/ProductGrid':{color:'red'},'@shopgate/engage/product/ProductSlider':{color:'blue'}};getThemeConfig.mockReturnValueOnce({styles:mockStyles});var styles=getThemeStyles('@shopgate/engage/product/ProductSlider');expect(styles).toEqual({color:'blue'});});it('should return undefined if key is no available',function(){getThemeConfig.mockReturnValueOnce({});var styles=getThemeStyles('keyNotAvailable');expect(styles).toBeUndefined();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getWidgetConfig}from"../getWidgetConfig";import{getPageConfig}from"../getPageConfig";jest.mock("../getPageConfig",function(){return{getPageConfig:jest.fn()};});var pagePattern='/requested/page';var widgetId='testWidgetId';describe('engage > core > config',function(){describe('getWidgetConfig()',function(){it('should return an empty object if no widgets are defined on the page.',function(){getPageConfig.mockReturnValueOnce({});var result=getWidgetConfig(pagePattern,widgetId);expect(result).toEqual({});});it('should return an empty object if the widget is not found.',function(){getPageConfig.mockReturnValueOnce({widgets:[]});expect(getWidgetConfig(pagePattern)).toEqual({});});it('should only return the first widget, which matches the given widgetId.',function(){getPageConfig.mockReturnValueOnce({widgets:[{id:'/some/other/page',name:'Other Widget'},{id:widgetId,name:'Correct Widget Id And First Found'},{id:widgetId,name:'Correct Widget Id But Not First'},{id:'/yet/another/widgetid',name:'Yet Another Widget'}]});expect(getWidgetConfig(pagePattern,widgetId)).toEqual({id:widgetId,name:'Correct Widget Id And First Found'});});it('should return the same config then an index of zero was given as if it was undefined.',function(){getPageConfig.mockReturnValue({widgets:[{id:widgetId,name:'Correct Widget Id And First Found'}]});var firstResult=getWidgetConfig(pagePattern,widgetId,0);expect(firstResult).toEqual(getWidgetConfig(pagePattern,widgetId,undefined));jest.resetAllMocks();});it('should only return the correct widget, which matches the given widgetId and given index.',function(){getPageConfig.mockReturnValueOnce({widgets:[{id:'/some/other/page',name:'Other Widget'},{id:widgetId,name:'Correct Widget Id Wrong Index'},{id:widgetId,name:'Correct Widget Id And Index'},{id:widgetId,name:'Correct Widget Id Too High Index'},{id:'/yet/another/widgetid',name:'Yet Another Widget'}]});expect(getWidgetConfig(pagePattern,widgetId,2)).toEqual({id:widgetId,name:'Correct Widget Id And Index'});});});});
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{getWidgetSettings}from"../getWidgetSettings";import{getPageSettings}from"../getPageSettings";import{getWidgetConfig}from"../getWidgetConfig";jest.mock("../getPageSettings",function(){return{getPageSettings:jest.fn()};});jest.mock("../getWidgetConfig",function(){return{getWidgetConfig:jest.fn()};});var pagePattern='/requested/page';var widgetId='testWidgetId';describe('engage > core > config',function(){describe('getWidgetSettings()',function(){beforeEach(function(){jest.resetAllMocks();});it('should return an empty object when no widget settings are available in any scope.',function(){getPageSettings.mockReturnValueOnce(undefined);getWidgetConfig.mockReturnValueOnce({});expect(getWidgetSettings(pagePattern,widgetId)).toEqual({});});it('should return all local settings if there is nothing to inherit from.',function(){getPageSettings.mockReturnValueOnce(undefined);getWidgetConfig.mockReturnValueOnce({id:widgetId,name:'WidgetName',settings:{all:{widget:'settings'}}});expect(getWidgetSettings(pagePattern,widgetId)).toEqual({all:{widget:'settings'}});});it('should pass down the params to the lower level functions for filtered inheritance.',function(){getPageSettings.mockReturnValueOnce({});getWidgetConfig.mockReturnValueOnce({});getWidgetSettings(pagePattern,widgetId,7);expect(getPageSettings).toBeCalledWith(pagePattern,widgetId);expect(getPageSettings).toBeCalledTimes(1);expect(getWidgetConfig).toBeCalledWith(pagePattern,widgetId,7);expect(getWidgetConfig).toBeCalledTimes(1);});it('should inherit matching keys from page settings.',function(){// Return unpacked object, not containing the key anymore, because the match is guaranteed
|
|
2
|
-
getPageSettings.mockReturnValueOnce({things:{to:{inherit:'some inherited value'}}});getWidgetConfig.mockReturnValueOnce({});expect(getWidgetSettings(pagePattern,widgetId)).toEqual({things:{to:{inherit:'some inherited value'}}});});it('should inherit and mix properties for keys matching page and widget settings.',function(){// Return unpacked object, not containing the key anymore, because the match is guaranteed
|
|
3
|
-
getPageSettings.mockReturnValueOnce({things:{toMix:{inherit:'some inherited value',keep:'low priority'}}});getWidgetConfig.mockReturnValueOnce({settings:{things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting'}},moreToKeep:'keep full key'}});expect(getWidgetSettings(pagePattern,widgetId)).toEqual({things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting',inherit:'some inherited value'}},moreToKeep:'keep full key'});});it('should not fail when there is nothing to inherit from.',function(){getPageSettings.mockReturnValueOnce(undefined);getWidgetConfig.mockReturnValueOnce({settings:{things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting'}},moreToKeep:'keep full key'}});expect(getWidgetSettings(pagePattern,widgetId)).toEqual({things:{toMix:{keep:'high priority',alsoKeep:'non-conflicting'}},moreToKeep:'keep full key'});});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export var i18n={ready:true,init:function init(){},text:function text(input){return input||'';},price:function price(){return'p';},number:function number(){return'n';},date:function date(){return'd';},time:function time(){return't';}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i18n}from"../i18n";jest.unmock("../i18n");var mockedWarn=jest.fn();var mockedError=jest.fn();jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{warn:function warn(){return mockedWarn.apply(void 0,arguments);},error:function error(){return mockedError.apply(void 0,arguments);}}};});describe('i18n',function(){beforeEach(function(){jest.clearAllMocks();});var methods=['text','price','date','time','number'];methods.forEach(function(m){it("should log error when i18n.".concat(m," is used before init"),function(){i18n[m]();expect(mockedError).toHaveBeenCalled();});});it('should translate',function(){var locales={test:{string:'Test string: {bar}'}};i18n.init({locales:locales,lang:'en-US'});expect(i18n.text('test.string',{bar:'testProperty'})).toBe('Test string: testProperty');expect(i18n.price(1000,'USD',2)).toBe('$1,000.00');expect(i18n.date(new Date(0).getDate())).toBe('Jan 1, 1970');expect(i18n.time(new Date(0).getDate()).match(/PM|AM/).length).toBe(1);expect(i18n.number(1000,2)).toBe('1,000.00');});it('should consider a custom currency locale',function(){i18n.init({locales:{},lang:'en-US',currencyLocale:'en-IL'});expect(i18n.price(1000,'EUR',2)).toBe('€1,000.00');});it('should warn on another init',function(){i18n.init({});expect(mockedWarn).toHaveBeenCalled();});it('should return default text for missing translation',function(){var locales={test:{string:'Test string: {bar}'}};i18n.init({locales:locales,lang:'en-US'});expect(i18n.textWithDefault('test.missing','Default text')).toBe('Default text');});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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);}import broadcastEvent from'@shopgate/pwa-core/commands/broadcastEvent';import{updateLegacyNavigationBar}from"../updateLegacyNavigationBar";jest.mock('@shopgate/pwa-core/commands/broadcastEvent',function(){return jest.fn();});describe('updateLegacyNavigationBar()',function(){it('should broadcast when called without parameters',function(){updateLegacyNavigationBar();expect(broadcastEvent).toHaveBeenCalledWith({event:'updateNavigationBarStyle',parameters:[{targetTab:'main',styles:{}}]});});it('should broadcast when called with colors that contain a bright background',function(){var options={color:'#000',background:'#fff',buttonColor:'red',buttonColorDisabled:'blue'};updateLegacyNavigationBar(options);expect(broadcastEvent).toHaveBeenCalledWith({event:'updateNavigationBarStyle',parameters:[{targetTab:'main',styles:_extends({},options,{statusBarBackground:options.background}),statusBarStyle:'dark'}]});});it('should broadcast when called with colors that contain a light background',function(){var options={background:'#000'};updateLegacyNavigationBar(options);expect(broadcastEvent).toHaveBeenCalledWith({event:'updateNavigationBarStyle',parameters:[{targetTab:'main',styles:_extends({},options,{statusBarBackground:options.background}),statusBarStyle:'light'}]});});it('should broadcast when called with a status bar background',function(){var options={statusBarBackground:'#fff'};updateLegacyNavigationBar(options);expect(broadcastEvent).toHaveBeenCalledWith({event:'updateNavigationBarStyle',parameters:[{targetTab:'main',styles:_extends({},options),statusBarStyle:'dark'}]});});it('should broadcast when called with custom targetTab and statusBarStyle',function(){var options={statusBarStyle:'dark',targetTab:'cart'};updateLegacyNavigationBar(options);expect(broadcastEvent).toHaveBeenCalledWith({event:'updateNavigationBarStyle',parameters:[{targetTab:'cart',styles:{},statusBarStyle:'dark'}]});});it('should broadcast when called with the isDefault option',function(){var options={isDefault:true,statusBarStyle:'dark',targetTab:'cart',statusBarBackground:'red'};updateLegacyNavigationBar(options);expect(broadcastEvent).toHaveBeenCalledWith({event:'updateNavigationBarStyle',parameters:[{isDefault:true,targetTab:'cart',styles:{statusBarBackground:'red'},statusBarStyle:'dark'}]});});});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
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);}import React from'react';/**
|
|
2
|
-
* Mock for the withWidgetSettings HOC.
|
|
3
|
-
* @param {Function} WrappedComponent The react component to wrap.
|
|
4
|
-
* @returns {JSX}
|
|
5
|
-
*/export function withWidgetSettings(WrappedComponent){var settings={mocked:'widgetSetting'};return function(props){return/*#__PURE__*/React.createElement(WrappedComponent,_extends({widgetSettings:settings},props));};}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
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);}import React from'react';import{mount}from'enzyme';import{withApp}from"../withApp";var mockApp={some:'prop'};var mockContext=jest.fn().mockReturnValue(mockApp);jest.mock("../../contexts/AppContext",function(){return{Consumer:function Consumer(_ref){var children=_ref.children;return children(mockContext());}};});// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};describe('engage > core > hocs > withApp',function(){beforeEach(function(){jest.clearAllMocks();});it('should inject a property called "app" into the component',function(){var ComposedComponent=withApp(MockComponent);var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual({someProp:true,app:_extends({},mockApp)});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
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);}import React from'react';import{mount}from'enzyme';import{withCurrentProduct}from"../withCurrentProduct";var mockCurrentProduct={id:'123',name:'acme',price:{currency:'EUR',unitPrice:22.95,unitPriceStriked:25.95}};var mockContext=jest.fn().mockReturnValue(mockCurrentProduct);jest.mock('@shopgate/pwa-common/context',function(){return{ThemeContext:{Consumer:function Consumer(_ref){var themeChildren=_ref.children;return themeChildren({contexts:{ProductContext:{Consumer:function Consumer(_ref2){var productChildren=_ref2.children;return productChildren(mockContext());}}}});}}};});// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};describe('engage > core > hocs > withCurrentProduct',function(){beforeEach(function(){jest.clearAllMocks();});it('should inject the context properties into the component',function(){var ComposedComponent=withCurrentProduct(MockComponent);var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual(_extends({someProp:true},mockCurrentProduct));});it('should inject a single property with the context into the component',function(){var ComposedComponent=withCurrentProduct(MockComponent,{prop:'product'});var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual({someProp:true,product:_extends({},mockCurrentProduct)});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/* eslint-disable require-jsdoc, react/prop-types */import React,{createRef}from'react';import{renderIntoDocument}from'react-dom/test-utils';import{shallow}from'enzyme';import{withForwardedRef}from"../withForwardedRef";var MockComponent=function MockComponent(_ref){var children=_ref.children,className=_ref.className,forwardedRef=_ref.forwardedRef;return/*#__PURE__*/React.createElement("div",{className:className,ref:forwardedRef},children);};describe('engage > core > hocs > withForwardedRef',function(){it('should render',function(){var ComposedComponent=withForwardedRef(MockComponent);var ref=/*#__PURE__*/createRef();var wrapper=shallow(/*#__PURE__*/React.createElement(ComposedComponent,{className:"foo",ref:ref},"Testing 123"));expect(wrapper).toMatchSnapshot();expect(wrapper.props()).toEqual({className:'foo',children:'Testing 123',forwardedRef:{current:null}});});it('should inject the ref with a custom prop name',function(){var ComposedComponent=withForwardedRef(MockComponent,{prop:'custom'});var ref=/*#__PURE__*/createRef();var wrapper=shallow(/*#__PURE__*/React.createElement(ComposedComponent,{className:"foo",ref:ref},"Testing 123"));expect(wrapper).toMatchSnapshot();expect(wrapper.props()).toEqual({className:'foo',children:'Testing 123',custom:{current:null}});});it('should create a ref that points to a HTMLDivElement',function(){var ComposedComponent=withForwardedRef(MockComponent);var ref=/*#__PURE__*/createRef();renderIntoDocument(/*#__PURE__*/React.createElement(ComposedComponent,{className:"foo",ref:ref},"Testing 123"));expect(ref.current).toBeInstanceOf(HTMLDivElement);});});/* eslint-enable require-jsdoc, react/prop-types */
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
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);}import React from'react';import{mount}from'enzyme';import{push,pop,replace,reset,update}from"../../router/helpers";import{withNavigation}from"../withNavigation";var navigationProps={historyPush:push,historyPop:pop,historyReplace:replace,historyReset:reset,historyUpdate:update};// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};describe('engage > core > hocs > withNavigation',function(){beforeEach(function(){jest.clearAllMocks();});it('should inject the navigation properties into the component',function(){var ComposedComponent=withNavigation(MockComponent);var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual(_extends({someProp:true},navigationProps));});it('should inject a single property with the navigation into the component',function(){var ComposedComponent=withNavigation(MockComponent,{prop:'navigation'});var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual({someProp:true,navigation:_extends({},navigationProps)});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
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);}import React from'react';import{mount}from'enzyme';import{withRoute}from"../withRoute";var mockRoute={id:'32d55',pathname:'/',pattern:'/',state:{}};var mockContext=jest.fn().mockReturnValue(mockRoute);jest.mock('@shopgate/pwa-common/context',function(){return{RouteContext:{Consumer:function Consumer(_ref){var children=_ref.children;return children(mockContext());}}};});// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};describe('engage > core > hocs > withRoute',function(){beforeEach(function(){jest.clearAllMocks();});it('should inject the context properties into the component',function(){var ComposedComponent=withRoute(MockComponent);var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual(_extends({someProp:true},mockRoute));});it('should inject a single property with the context into the component',function(){var ComposedComponent=withRoute(MockComponent,{prop:'route'});var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual({someProp:true,route:_extends({},mockRoute)});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
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);}import React from'react';import{mount}from'enzyme';import{withTheme}from"../withTheme";var mockTheme={ComponentOne:function ComponentOne(){return/*#__PURE__*/React.createElement("div",null);},ComponentTwo:function ComponentTwo(){return/*#__PURE__*/React.createElement("div",null);}};var mockContext=jest.fn().mockReturnValue(mockTheme);jest.mock('@shopgate/pwa-common/context',function(){return{ThemeContext:{Consumer:function Consumer(_ref){var children=_ref.children;return children(mockContext());}}};});// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};describe('engage > core > hocs > withTheme',function(){beforeEach(function(){jest.clearAllMocks();});it('should inject the context properties into the component',function(){var ComposedComponent=withTheme(MockComponent);var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual(_extends({someProp:true},mockTheme));});it('should inject a single property with the context into the component',function(){var ComposedComponent=withTheme(MockComponent,{prop:'theme'});var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,{someProp:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).props()).toEqual({someProp:true,theme:_extends({},mockTheme)});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import React from'react';import{mount}from'enzyme';import{withWidgetSettings}from"../withWidgetSettings";import{useWidgetSettings}from"../../hooks/useWidgetSettings";jest.mock("../../hooks/useWidgetSettings",function(){return{useWidgetSettings:jest.fn()};});// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};var widgetSettings={some:'setting'};describe('engage > core > hocs > withWidgetSettings',function(){beforeEach(function(){useWidgetSettings.mockReturnValue(widgetSettings);});it('should merge add the widget settings to a wrapped component',function(){var ComposedComponent=withWidgetSettings(MockComponent);var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,null));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).prop('widgetSettings')).toEqual(widgetSettings);});});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import React from'react';import{mount}from'enzyme';import{withWidgetStyles}from"../withWidgetStyles";import{useWidgetStyles}from"../../hooks/useWidgetStyles";jest.mock("../../hooks/useWidgetStyles",function(){return{useWidgetStyles:jest.fn()};});// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};var widgetStyles={some:'style'};describe('engage > core > hocs > withWidgetStyles',function(){beforeEach(function(){useWidgetStyles.mockReturnValue(widgetStyles);});it('should merge add the widget settings to a wrapped component',function(){var ComposedComponent=withWidgetStyles(MockComponent);var wrapper=mount(/*#__PURE__*/React.createElement(ComposedComponent,null));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).prop('widgetStyles')).toEqual(widgetStyles);});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useContext}from'react';import AppContext from"../../contexts/AppContext";import{useApp}from"../useApp";jest.mock('react',function(){return{useContext:jest.fn(),createContext:jest.fn()};});describe('engage > core > hooks',function(){describe('useApp()',function(){it('should return an empty if no app context is defined.',function(){useContext.mockReturnValueOnce({});var app=useApp();expect(useContext).toHaveBeenCalledWith(AppContext);expect(app).toEqual({});});it('should return object containing app context properties.',function(){useContext.mockReturnValueOnce({some:'prop'});var app=useApp();expect(app).toEqual({some:'prop'});});});});
|
|
@@ -1 +0,0 @@
|
|
|
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);}import{useNavigation}from"../useNavigation";describe('engage > core > hooks',function(){describe('useNavigation()',function(){it('should return the push() function',function(){var result=useNavigation();expect(result.hasOwnProperty('push')).toBe(true);expect(_typeof(result.push)).toBe('function');});it('should return the pop() function',function(){var result=useNavigation();expect(result.hasOwnProperty('pop')).toBe(true);expect(_typeof(result.pop)).toBe('function');});it('should return the replace() function',function(){var result=useNavigation();expect(result.hasOwnProperty('replace')).toBe(true);expect(_typeof(result.replace)).toBe('function');});it('should return the reset() function',function(){var result=useNavigation();expect(result.hasOwnProperty('reset')).toBe(true);expect(_typeof(result.reset)).toBe('function');});it('should return the update() function',function(){var result=useNavigation();expect(result.hasOwnProperty('update')).toBe(true);expect(_typeof(result.update)).toBe('function');});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{usePageConfig}from"../usePageConfig";import{useRoute}from"../useRoute";import{getPageConfig}from"../../config/getPageConfig";jest.mock("../useRoute",function(){return{useRoute:jest.fn()};});jest.mock("../../config/getPageConfig",function(){return{getPageConfig:jest.fn()};});describe('engage > core > hooks',function(){describe('usePageConfig()',function(){beforeEach(function(){jest.resetAllMocks();});it('should pass down the page pattern to the lower level helper functions.',function(){useRoute.mockReturnValue({pattern:'/page/pattern'});usePageConfig();expect(getPageConfig).toBeCalledWith('/page/pattern');expect(getPageConfig).toBeCalledTimes(1);expect(useRoute).toBeCalledTimes(1);});it('should return what it got from the helper function without messing with references.',function(){useRoute.mockReturnValue({pattern:'/page/pattern'});var testPageConfig={pattern:'/page/pattern',settings:{custom:'123'},widgets:[]};getPageConfig.mockReturnValue(testPageConfig);var result=usePageConfig();expect(result===testPageConfig).toBeTruthy();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{usePageSettings}from"../usePageSettings";import{useRoute}from"../useRoute";import{getPageSettings}from"../../config/getPageSettings";jest.mock("../useRoute",function(){return{useRoute:jest.fn()};});jest.mock("../../config/getPageSettings",function(){return{getPageSettings:jest.fn()};});describe('engage > core > hooks',function(){describe('usePageSettings()',function(){beforeEach(function(){jest.resetAllMocks();});it('should pass down its given param and the page pattern to the lower level helper functions.',function(){useRoute.mockReturnValue({pattern:'/page/pattern'});usePageSettings('customKey');expect(getPageSettings).toBeCalledWith('/page/pattern','customKey');expect(getPageSettings).toBeCalledTimes(1);expect(useRoute).toBeCalledTimes(1);});it('should return what it got from the helper function without messing with references.',function(){useRoute.mockReturnValue({pattern:'/page/pattern'});var testPageSettings={custom:'setting-123'};getPageSettings.mockReturnValue(testPageSettings);var result=usePageSettings();expect(result===testPageSettings).toBeTruthy();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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);}import{useContext}from'react';import{useTheme}from"../useTheme";jest.mock('react',function(){return _extends({},jest.requireActual('react'),{useContext:jest.fn()});});describe('engage > core > hooks',function(){describe('useTheme()',function(){it('should return an empty if no theme context is defined.',function(){useContext.mockReturnValueOnce({contexts:{}});var theme=useTheme();expect(theme).toEqual({});});it('should return object containing react components.',function(){useContext.mockReturnValueOnce({contexts:{},Some:function Some(){return null;},Thing:function Thing(){return null;}});var theme=useTheme();expect(theme.Some).toBeTruthy();expect(theme.Thing).toBeTruthy();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useWidgetConfig}from"../useWidgetConfig";import{useRoute}from"../useRoute";import{getWidgetConfig}from"../../config/getWidgetConfig";jest.mock("../useRoute",function(){return{useRoute:jest.fn()};});jest.mock("../../config/getWidgetConfig",function(){return{getWidgetConfig:jest.fn()};});describe('engage > core > hooks',function(){describe('useWidgetConfig()',function(){beforeEach(function(){jest.resetAllMocks();});it('should pass down its given params and the page pattern to the lower level helper functions.',function(){useRoute.mockReturnValue({pattern:'/test'});useWidgetConfig('widgetId',3);expect(getWidgetConfig).toBeCalledWith('/test','widgetId',3);expect(getWidgetConfig).toBeCalledTimes(1);expect(useRoute).toBeCalledTimes(1);});it('should return what it got from the helper function without messing with references.',function(){useRoute.mockReturnValue({pattern:'/test'});var testWidgetConfig={widgetId:'some/widget/id',settings:{custom:'config'}};getWidgetConfig.mockReturnValue(testWidgetConfig);var result=useWidgetConfig('widgetId',3);expect(result===testWidgetConfig).toBeTruthy();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useWidgetSettings}from"../useWidgetSettings";import{useRoute}from"../useRoute";import{getWidgetSettings}from"../../config/getWidgetSettings";jest.mock("../useRoute",function(){return{useRoute:jest.fn()};});jest.mock("../../config/getWidgetSettings",function(){return{getWidgetSettings:jest.fn()};});describe('engage > core > hooks',function(){describe('useWidgetSettings()',function(){beforeEach(function(){jest.resetAllMocks();});it('should pass down its given params and the page pattern to the lower level helper functions.',function(){useRoute.mockReturnValue({pattern:'/test'});useWidgetSettings('widgetId',3);expect(getWidgetSettings).toBeCalledWith('/test','widgetId',3);expect(getWidgetSettings).toBeCalledTimes(1);expect(useRoute).toBeCalledTimes(1);});it('should return what it got from the helper function without messing with references.',function(){useRoute.mockReturnValue({pattern:'/test'});var testWidgetSettings={custom:'setting'};getWidgetSettings.mockReturnValue(testWidgetSettings);var result=useWidgetSettings('widgetId',3);expect(result===testWidgetSettings).toBeTruthy();});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useWidgetStyles}from"../useWidgetStyles";import{useWidgetConfig}from"../useWidgetConfig";import{getThemeStyles}from"../../config/getThemeStyles";jest.mock("../useWidgetConfig",function(){return{useWidgetConfig:jest.fn()};});jest.mock("../../config/getThemeStyles",function(){return{getThemeStyles:jest.fn()};});describe('engage > core > hooks',function(){describe('useWidgetStyles()',function(){beforeEach(function(){jest.resetAllMocks();});it('should return an empty object if no styles property exists',function(){useWidgetConfig.mockReturnValueOnce({});getThemeStyles.mockReturnValueOnce({});var styles=useWidgetStyles();expect(styles).toEqual({});});it('should return an empty object if no styles exist',function(){useWidgetConfig.mockReturnValueOnce({style:{}});getThemeStyles.mockReturnValueOnce({});var styles=useWidgetStyles();expect(styles).toEqual({});});it('should return all widget styles.',function(){useWidgetConfig.mockReturnValueOnce({styles:{color:'#ff0000',width:'100%'}});getThemeStyles.mockReturnValueOnce({});var styles=useWidgetStyles();expect(styles).toEqual({color:'#ff0000',width:'100%'});});it('should return all theme styles.',function(){useWidgetConfig.mockReturnValueOnce({styles:{}});getThemeStyles.mockReturnValueOnce({color:'#ff0000',width:'100%'});var styles=useWidgetStyles();expect(styles).toEqual({color:'#ff0000',width:'100%'});});it('should return merged widget/theme styles.',function(){useWidgetConfig.mockReturnValueOnce({styles:{color:'#666666',height:'100%'}});getThemeStyles.mockReturnValueOnce({color:'#ff0000',width:'100%'});var styles=useWidgetStyles();expect(styles).toEqual({color:'#666666',width:'100%',height:'100%'});});it('should pass down its given params to the lower level helper function.',function(){useWidgetConfig.mockReturnValueOnce({});getThemeStyles.mockReturnValueOnce({});useWidgetStyles('widgetId',3);expect(useWidgetConfig).toBeCalledWith('widgetId',3);expect(useWidgetConfig).toBeCalledTimes(1);expect(getThemeStyles).toBeCalledWith('widgetId');expect(getThemeStyles).toBeCalledTimes(1);});});});
|
package/core/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as core from'.';describe('engage > core',function(){it('should have exports',function(){expect(_typeof(core)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(core).forEach(function(exportKey){expect(typeof core[exportKey]!=='undefined').toBe(true);});});});
|
|
@@ -1,2 +0,0 @@
|
|
|
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 React from'react';import{shallow}from'enzyme';import appConfig from'@shopgate/pwa-common/helpers/config';import event from'@shopgate/pwa-core/classes/Event';import{APP_EVENT_VIEW_WILL_APPEAR,APP_EVENT_VIEW_WILL_DISAPPEAR}from'@shopgate/pwa-core/constants/AppEvents';import AppProvider from"../AppProvider";jest.mock('@shopgate/pwa-common/helpers/config',function(){return{some:'prop'};});jest.mock('@shopgate/pwa-core/classes/Event',function(){return{addCallback:jest.fn(),removeCallback:jest.fn()};});// eslint-disable-next-line require-jsdoc
|
|
2
|
-
var MockComponent=function MockComponent(){return null;};describe('engage > core > providers > AppProvider',function(){beforeEach(function(){jest.clearAllMocks();});it('should initialize as expected',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(AppProvider,null,/*#__PURE__*/React.createElement(MockComponent,null)));var instance=wrapper.instance();expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockComponent).length).toEqual(1);expect(wrapper.prop('value')).toEqual({appConfig:appConfig,isVisible:true,setIsVisible:instance.setIsVisible});expect(event.addCallback).toHaveBeenCalledTimes(2);expect(event.addCallback).toHaveBeenCalledWith(APP_EVENT_VIEW_WILL_APPEAR,instance.setVisible);expect(event.addCallback).toHaveBeenCalledWith(APP_EVENT_VIEW_WILL_DISAPPEAR,instance.setHidden);});it('should handle calls of setIsVisible() as expected',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(AppProvider,null,/*#__PURE__*/React.createElement(MockComponent,null)));var instance=wrapper.instance();var _wrapper$prop=wrapper.prop('value'),isVisible=_wrapper$prop.isVisible;expect(isVisible).toBe(true);instance.setIsVisible(false);var _wrapper$prop2=wrapper.prop('value');isVisible=_wrapper$prop2.isVisible;expect(isVisible).toBe(false);instance.setIsVisible(true);var _wrapper$prop3=wrapper.prop('value');isVisible=_wrapper$prop3.isVisible;expect(isVisible).toBe(true);});it('should handle event calls as expected',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(AppProvider,null,/*#__PURE__*/React.createElement(MockComponent,null)));var _event$addCallback$mo=_slicedToArray(event.addCallback.mock.calls,2),_event$addCallback$mo2=_slicedToArray(_event$addCallback$mo[0],2),setVisible=_event$addCallback$mo2[1],_event$addCallback$mo3=_slicedToArray(_event$addCallback$mo[1],2),setHidden=_event$addCallback$mo3[1];var _wrapper$prop4=wrapper.prop('value'),isVisible=_wrapper$prop4.isVisible;expect(isVisible).toBe(true);setHidden();var _wrapper$prop5=wrapper.prop('value');isVisible=_wrapper$prop5.isVisible;expect(isVisible).toBe(false);setVisible();var _wrapper$prop6=wrapper.prop('value');isVisible=_wrapper$prop6.isVisible;expect(isVisible).toBe(true);});it('should remove the event listeners on unmount',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(AppProvider,null,/*#__PURE__*/React.createElement(MockComponent,null)));var instance=wrapper.instance();wrapper.unmount();expect(event.removeCallback).toHaveBeenCalledTimes(2);expect(event.removeCallback).toHaveBeenCalledWith(APP_EVENT_VIEW_WILL_APPEAR,instance.setVisible);expect(event.removeCallback).toHaveBeenCalledWith(APP_EVENT_VIEW_WILL_DISAPPEAR,instance.setHidden);});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{UIEvents}from'@shopgate/pwa-core';import{router}from'@virtuous/conductor';import{push,pop,replace,reset,update,NAVIGATION_PUSH,NAVIGATION_POP,NAVIGATION_REPLACE,NAVIGATION_RESET}from"../helpers";jest.mock('@shopgate/pwa-core',function(){return{UIEvents:{emit:jest.fn()}};});jest.mock('@virtuous/conductor',function(){return{router:{update:jest.fn(),getCurrentRoute:jest.fn(function(){return{id:'1234'};})}};});describe('Router > helpers',function(){test('push()',function(){push({pathname:'/test1'});expect(UIEvents.emit).toBeCalledWith(NAVIGATION_PUSH,{pathname:'/test1'});});test('pop()',function(){pop();expect(UIEvents.emit).toBeCalledWith(NAVIGATION_POP);});test('replace()',function(){replace({pathname:'/test2'});expect(UIEvents.emit).toBeCalledWith(NAVIGATION_REPLACE,{pathname:'/test2'});});test('reset()',function(){reset();expect(UIEvents.emit).toBeCalledWith(NAVIGATION_RESET);});describe('update()',function(){it('should use the current route\'s ID if no ID is passed',function(){update({foo:'bar'});expect(router.update).toBeCalledWith('1234',{foo:'bar'});});it('should use the custom ID if one is passed',function(){update({foo:'bar'},'345');expect(router.update).toBeCalledWith('345',{foo:'bar'});});});});
|
package/favorites/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as favorites from'.';describe('engage > favorites',function(){it('should have exports',function(){expect(_typeof(favorites)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(favorites).forEach(function(exportKey){expect(typeof favorites[exportKey]!=='undefined').toBe(true);});});});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var _excluded=["manufacturer"];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 set from'lodash/set';import cloneDeep from'lodash/cloneDeep';import buildUpdatedFilters from"../buildUpdatedFilters";var mockedFilter={display_amount:{id:'display_amount',label:'Price',type:'range',value:[100,2000]},manufacturer:{id:'manufacturer',label:'Manufacturer',type:'multiselect',value:[{id:'wayland_corp',label:'Weyland Corp'},{id:'tyrell_corp',label:'Tyrell Corporation'}]}};describe('buildUpdatedFilters()',function(){it('should update filters as expected',function(){var updated=cloneDeep(mockedFilter);expect(buildUpdatedFilters({},updated)).toEqual(updated);});it('should exclude filters when they do not have values selected',function(){var initial=cloneDeep(mockedFilter);var updated=set(cloneDeep(mockedFilter),'manufacturer.value',[]);var manufacturer=mockedFilter.manufacturer,expected=_objectWithoutProperties(mockedFilter,_excluded);expect(buildUpdatedFilters(initial,updated)).toEqual(expected);});it('should round the values of a display amount filter',function(){var initial=cloneDeep(mockedFilter);var updated=set(cloneDeep(mockedFilter),'display_amount.value',[125,1920]);expect(buildUpdatedFilters(initial,updated)).toEqual(mockedFilter);});it('should return null both parameters are empty objects',function(){expect(buildUpdatedFilters({},{})).toBeNull();});});
|
package/filter/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as filter from'.';describe('engage > filter',function(){it('should have exports',function(){expect(_typeof(filter)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(filter).forEach(function(exportKey){expect(typeof filter[exportKey]!=='undefined').toBe(true);});});});
|
package/index.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);}import*as engage from'.';describe('engage',function(){it('should have exports',function(){expect(_typeof(engage)).toEqual('object');});it('should not do undefined exports',function(){Object.keys(engage).forEach(function(exportKey){expect(typeof engage[exportKey]!=='undefined').toBe(true);});});});
|