@shopgate/engage 6.22.0-beta.2 → 6.22.0-beta.3

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.
@@ -10,4 +10,4 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
10
10
  * @param {Function} props.addBackInStockSubscription Add product to back in stock list
11
11
  * @param {Function} props.grantPushPermissions Request / Set push permission
12
12
  * @return {JSX}
13
- */var BackInStockButton=function BackInStockButton(_ref){var productId=_ref.productId,_ref$isLinkToBackInSt=_ref.isLinkToBackInStockEnabled,isLinkToBackInStockEnabled=_ref$isLinkToBackInSt===void 0?false:_ref$isLinkToBackInSt,subscription=_ref.subscription,_ref$stopPropagation=_ref.stopPropagation,stopPropagation=_ref$stopPropagation===void 0?false:_ref$stopPropagation,addBackInStockSubscription=_ref.addBackInStockSubscription,grantPushPermissions=_ref.grantPushPermissions;var handleClick=useCallback(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(event){var allowed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(stopPropagation){event.stopPropagation();}_context.next=3;return grantPushPermissions({rationaleModal:{message:'permissions.back_in_stock_push_notifications.message',confirm:'permissions.back_in_stock_push_notifications.confirm',dismiss:'permissions.back_in_stock_push_notifications.dismiss'}});case 3:allowed=_context.sent;if(allowed){addBackInStockSubscription({productId:productId});}case 5:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}(),[addBackInStockSubscription,grantPushPermissions,productId,stopPropagation]);if((subscription===null||subscription===void 0?void 0:subscription.status)==='active'){return/*#__PURE__*/React.createElement(Link,{href:BACK_IN_STOCK_PATTERN,disabled:!isLinkToBackInStockEnabled,className:styles.backInStockMessageContainer,tag:"span"},/*#__PURE__*/React.createElement(CheckedIcon,{color:colors.success,className:styles.icon}),/*#__PURE__*/React.createElement("span",{className:styles.backInStockMessage},i18n.text('back_in_stock.we_will_remind_you')));}return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("a",{role:"button",onClick:handleClick,className:styles.button},/*#__PURE__*/React.createElement("div",{className:styles.buttonContent},/*#__PURE__*/React.createElement(NotificationIcon,{color:colors.primary}),/*#__PURE__*/React.createElement("span",{className:styles.buttonText},i18n.text('back_in_stock.get_notified')))));};BackInStockButton.defaultProps={stopPropagation:false,isLinkToBackInStockEnabled:false,subscription:null,productId:null};export default connect(BackInStockButton);
13
+ */var BackInStockButton=function BackInStockButton(_ref){var productId=_ref.productId,_ref$isLinkToBackInSt=_ref.isLinkToBackInStockEnabled,isLinkToBackInStockEnabled=_ref$isLinkToBackInSt===void 0?false:_ref$isLinkToBackInSt,subscription=_ref.subscription,_ref$stopPropagation=_ref.stopPropagation,stopPropagation=_ref$stopPropagation===void 0?false:_ref$stopPropagation,addBackInStockSubscription=_ref.addBackInStockSubscription,grantPushPermissions=_ref.grantPushPermissions;var handleClick=useCallback(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(event){var allowed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(stopPropagation){event.stopPropagation();}_context.next=3;return grantPushPermissions({useRationaleModal:true,useSettingsModal:true,rationaleModal:{message:'permissions.back_in_stock_push_notifications.message',confirm:'permissions.back_in_stock_push_notifications.confirm',dismiss:'permissions.back_in_stock_push_notifications.dismiss'}});case 3:allowed=_context.sent;if(allowed){addBackInStockSubscription({productId:productId});}case 5:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}(),[addBackInStockSubscription,grantPushPermissions,productId,stopPropagation]);if((subscription===null||subscription===void 0?void 0:subscription.status)==='active'){return/*#__PURE__*/React.createElement(Link,{href:BACK_IN_STOCK_PATTERN,disabled:!isLinkToBackInStockEnabled,className:styles.backInStockMessageContainer,tag:"span"},/*#__PURE__*/React.createElement(CheckedIcon,{color:colors.success,className:styles.icon}),/*#__PURE__*/React.createElement("span",{className:styles.backInStockMessage},i18n.text('back_in_stock.we_will_remind_you')));}return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("a",{role:"button",onClick:handleClick,className:styles.button},/*#__PURE__*/React.createElement("div",{className:styles.buttonContent},/*#__PURE__*/React.createElement(NotificationIcon,{color:colors.primary}),/*#__PURE__*/React.createElement("span",{className:styles.buttonText},i18n.text('back_in_stock.get_notified')))));};BackInStockButton.defaultProps={stopPropagation:false,isLinkToBackInStockEnabled:false,subscription:null,productId:null};export default connect(BackInStockButton);
@@ -20,7 +20,7 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToAr
20
20
  * @param {string} options.modal.dismiss Label for the dismiss button.
21
21
  * @param {Object} options.modal.params Additional parameters for i18n strings.
22
22
  * @return { Function } A redux thunk.
23
- */var grantPermissions=function grantPermissions(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){return new Promise(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve){var permissionId,_options$useSettingsM,useSettingsModal,_options$useRationale,useRationaleModal,_options$rationaleMod,rationaleModalOptions,_options$modal,modalOptions,status,_yield$getAppPermissi,_yield$getAppPermissi2,requestAllowed,_yield$requestAppPerm,_yield$requestAppPerm2,openSettings,handler;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:permissionId=options.permissionId,_options$useSettingsM=options.useSettingsModal,useSettingsModal=_options$useSettingsM===void 0?false:_options$useSettingsM,_options$useRationale=options.useRationaleModal,useRationaleModal=_options$useRationale===void 0?false:_options$useRationale,_options$rationaleMod=options.rationaleModal,rationaleModalOptions=_options$rationaleMod===void 0?{}:_options$rationaleMod,_options$modal=options.modal,modalOptions=_options$modal===void 0?{}:_options$modal;if(availablePermissionsIds.includes(permissionId)){_context2.next=5;break;}logger.error('grandPermissions: %s is no valid permission id',permissionId);resolve(false);return _context2.abrupt("return");case 5:_context2.next=7;return getAppPermissions([permissionId]);case 7:_yield$getAppPermissi=_context2.sent;_yield$getAppPermissi2=_slicedToArray(_yield$getAppPermissi,1);status=_yield$getAppPermissi2[0].status;if(!(status===PERMISSION_STATUS_NOT_SUPPORTED)){_context2.next=13;break;}resolve(false);return _context2.abrupt("return");case 13:if(!(status===PERMISSION_STATUS_NOT_DETERMINED)){_context2.next=29;break;}if(!useRationaleModal){_context2.next=21;break;}_context2.next=17;return dispatch(showModal({message:rationaleModalOptions.message||'',confirm:rationaleModalOptions.confirm||'',dismiss:rationaleModalOptions.dismiss||'',params:rationaleModalOptions.params||''}));case 17:requestAllowed=_context2.sent;if(!(requestAllowed===false)){_context2.next=21;break;}resolve(false);return _context2.abrupt("return");case 21:_context2.next=23;return requestAppPermissions([{permissionId:permissionId}]);case 23:_yield$requestAppPerm=_context2.sent;_yield$requestAppPerm2=_slicedToArray(_yield$requestAppPerm,1);status=_yield$requestAppPerm2[0].status;if(![PERMISSION_STATUS_DENIED,PERMISSION_STATUS_NOT_DETERMINED].includes(status)){_context2.next=29;break;}resolve(false);return _context2.abrupt("return");case 29:if(!(status===PERMISSION_STATUS_GRANTED)){_context2.next=32;break;}resolve(true);return _context2.abrupt("return");case 32:if(!(status===PERMISSION_STATUS_DENIED)){_context2.next=45;break;}if(useSettingsModal){_context2.next=36;break;}resolve(false);return _context2.abrupt("return");case 36:_context2.next=38;return dispatch(showModal({title:modalOptions.title||null,message:modalOptions.message,confirm:modalOptions.confirm,dismiss:modalOptions.dismiss,params:modalOptions.params}));case 38:openSettings=_context2.sent;if(openSettings){_context2.next=42;break;}resolve(false);return _context2.abrupt("return");case 42:/**
23
+ */var grantPermissions=function grantPermissions(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){return new Promise(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve){var permissionId,_options$useSettingsM,useSettingsModal,_options$useRationale,useRationaleModal,_options$rationaleMod,rationaleModalOptions,_options$modal,modalOptions,status,_yield$getAppPermissi,_yield$getAppPermissi2,requestAllowed,_yield$requestAppPerm,_yield$requestAppPerm2,openSettings,handler;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:permissionId=options.permissionId,_options$useSettingsM=options.useSettingsModal,useSettingsModal=_options$useSettingsM===void 0?false:_options$useSettingsM,_options$useRationale=options.useRationaleModal,useRationaleModal=_options$useRationale===void 0?false:_options$useRationale,_options$rationaleMod=options.rationaleModal,rationaleModalOptions=_options$rationaleMod===void 0?{}:_options$rationaleMod,_options$modal=options.modal,modalOptions=_options$modal===void 0?{}:_options$modal;if(availablePermissionsIds.includes(permissionId)){_context2.next=5;break;}logger.error('grandPermissions: %s is no valid permission id',permissionId);resolve(false);return _context2.abrupt("return");case 5:_context2.next=7;return getAppPermissions([permissionId]);case 7:_yield$getAppPermissi=_context2.sent;_yield$getAppPermissi2=_slicedToArray(_yield$getAppPermissi,1);status=_yield$getAppPermissi2[0].status;if(!(status===PERMISSION_STATUS_NOT_SUPPORTED)){_context2.next=13;break;}resolve(false);return _context2.abrupt("return");case 13:if(!(status===PERMISSION_STATUS_NOT_DETERMINED)){_context2.next=29;break;}if(!useRationaleModal){_context2.next=21;break;}_context2.next=17;return dispatch(showModal({message:rationaleModalOptions.message||'',confirm:rationaleModalOptions.confirm||'',dismiss:rationaleModalOptions.dismiss||'',params:rationaleModalOptions.params}));case 17:requestAllowed=_context2.sent;if(!(requestAllowed===false)){_context2.next=21;break;}resolve(false);return _context2.abrupt("return");case 21:_context2.next=23;return requestAppPermissions([{permissionId:permissionId}]);case 23:_yield$requestAppPerm=_context2.sent;_yield$requestAppPerm2=_slicedToArray(_yield$requestAppPerm,1);status=_yield$requestAppPerm2[0].status;if(![PERMISSION_STATUS_DENIED,PERMISSION_STATUS_NOT_DETERMINED].includes(status)){_context2.next=29;break;}resolve(false);return _context2.abrupt("return");case 29:if(!(status===PERMISSION_STATUS_GRANTED)){_context2.next=32;break;}resolve(true);return _context2.abrupt("return");case 32:if(!(status===PERMISSION_STATUS_DENIED)){_context2.next=45;break;}if(useSettingsModal){_context2.next=36;break;}resolve(false);return _context2.abrupt("return");case 36:_context2.next=38;return dispatch(showModal({title:modalOptions.title||null,message:modalOptions.message,confirm:modalOptions.confirm,dismiss:modalOptions.dismiss,params:modalOptions.params}));case 38:openSettings=_context2.sent;if(openSettings){_context2.next=42;break;}resolve(false);return _context2.abrupt("return");case 42:/**
24
24
  * Handler for the app event.
25
25
  */handler=/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var _yield$getAppPermissi3,_yield$getAppPermissi4;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:event.removeCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,handler);_context.next=3;return getAppPermissions([permissionId]);case 3:_yield$getAppPermissi3=_context.sent;_yield$getAppPermissi4=_slicedToArray(_yield$getAppPermissi3,1);status=_yield$getAppPermissi4[0].status;resolve(status===PERMISSION_STATUS_GRANTED);case 7:case"end":return _context.stop();}}},_callee);}));return function handler(){return _ref2.apply(this,arguments);};}();/**
26
26
  * Register an event handler, so that we can perform the permissions check again,
@@ -1,4 +1,4 @@
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{PERMISSION_ID_PUSH}from'@shopgate/pwa-core/constants/AppPermissions';import grantPermissions from"./grantPermissions";/**
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{PERMISSION_ID_PUSH}from'@shopgate/pwa-core';import grantPermissions from"./grantPermissions";/**
2
2
  * Determines the current state of the push permissions.
3
3
  * If not already happened, the user will be prompted to grant permissions.
4
4
  * The action returns a promise which resolves with a boolean value, that indicates the state.
@@ -19,4 +19,4 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
19
19
  * @param {string} options.modal.dismiss Label for the dismiss button.
20
20
  * @param {Object} options.modal.params Additional parameters for i18n strings.
21
21
  * @return { Function } A redux thunk.
22
- */var grantPushPermissions=function grantPushPermissions(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){var _options$useSettingsM=options.useSettingsModal,useSettingsModal=_options$useSettingsM===void 0?true:_options$useSettingsM,_options$useRationale=options.useRationaleModal,useRationaleModal=_options$useRationale===void 0?true:_options$useRationale,_options$modal=options.modal,modal=_options$modal===void 0?{}:_options$modal,_options$rationaleMod=options.rationaleModal,rationaleModal=_options$rationaleMod===void 0?{}:_options$rationaleMod;return dispatch(grantPermissions({permissionId:PERMISSION_ID_PUSH,useSettingsModal:useSettingsModal,useRationaleModal:useRationaleModal,modal:_extends({title:null,message:'permissions.access_denied.push_message',confirm:'permissions.access_denied.settings_button'},modal),rationaleModal:rationaleModal}));};};export default grantPushPermissions;
22
+ */var grantPushPermissions=function grantPushPermissions(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){var _options$useSettingsM=options.useSettingsModal,useSettingsModal=_options$useSettingsM===void 0?false:_options$useSettingsM,_options$useRationale=options.useRationaleModal,useRationaleModal=_options$useRationale===void 0?false:_options$useRationale,_options$modal=options.modal,modal=_options$modal===void 0?{}:_options$modal,_options$rationaleMod=options.rationaleModal,rationaleModal=_options$rationaleMod===void 0?{}:_options$rationaleMod;return dispatch(grantPermissions({permissionId:PERMISSION_ID_PUSH,useSettingsModal:useSettingsModal,useRationaleModal:useRationaleModal,modal:_extends({title:null,message:'permissions.access_denied.push_message',confirm:'permissions.access_denied.settings_button'},modal),rationaleModal:rationaleModal}));};};export default grantPushPermissions;
package/core/index.js CHANGED
@@ -16,7 +16,7 @@ export { default as routePortals } from '@shopgate/pwa-common/helpers/portals/ro
16
16
  */export*from'@shopgate/pwa-common/helpers/redux';export*from'@shopgate/pwa-common/helpers/style';export*from'@shopgate/pwa-common/helpers/tracking';export*from'@shopgate/pwa-common/helpers/validation';// STREAMS
17
17
  export*from'@shopgate/pwa-common/streams/main';export*from'@shopgate/pwa-common/streams/error';// --------------- APP --------------- //
18
18
  // ACTIONS
19
- export{default as handleDeepLink}from'@shopgate/pwa-common/actions/app/handleDeepLink';export{default as handleUniversalLink}from'@shopgate/pwa-common/actions/app/handleUniversalLink';export{default as handleLink}from'@shopgate/pwa-common/actions/app/handleLink';export{default as handlePushNotification}from'@shopgate/pwa-common/actions/app/handlePushNotification';export{default as registerLinkEvents}from'@shopgate/pwa-common/actions/app/registerLinkEvents';export{default as updateStatusBarBackground}from"./actions/updateStatusBarBackground";export{default as grantPermissions}from"./actions/grantPermissions";export{default as grantCameraPermissions}from"./actions/grantCameraPermissions";export{default as grantPushPermissions}from"./actions/grantPushPermissions";export{default as grantGeolocationPermissions}from"./actions/grantGeolocationPermissions";export{default as getGeolocation}from"./actions/getGeolocation";// STREAMS
19
+ export{default as handleDeepLink}from'@shopgate/pwa-common/actions/app/handleDeepLink';export{default as handleUniversalLink}from'@shopgate/pwa-common/actions/app/handleUniversalLink';export{default as handleLink}from'@shopgate/pwa-common/actions/app/handleLink';export{default as handlePushNotification}from'@shopgate/pwa-common/actions/app/handlePushNotification';export{default as registerLinkEvents}from'@shopgate/pwa-common/actions/app/registerLinkEvents';export{default as updateStatusBarBackground}from"./actions/updateStatusBarBackground";export{default as grantPermissions}from"./actions/grantPermissions";export{default as grantPushPermissions}from"./actions/grantPushPermissions";export{default as grantCameraPermissions}from"./actions/grantCameraPermissions";export{default as grantGeolocationPermissions}from"./actions/grantGeolocationPermissions";export{default as getGeolocation}from"./actions/getGeolocation";// STREAMS
20
20
  export*from'@shopgate/pwa-common/streams/app';// --------------- STORE --------------- //
21
21
  export*from'@shopgate/pwa-common/store';// --------------- CLIENT --------------- //
22
22
  // ACTIONS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/engage",
3
- "version": "6.22.0-beta.2",
3
+ "version": "6.22.0-beta.3",
4
4
  "description": "Shopgate's ENGAGE library.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -15,12 +15,12 @@
15
15
  "connect"
16
16
  ],
17
17
  "dependencies": {
18
- "@shopgate/pwa-common": "6.22.0-beta.2",
19
- "@shopgate/pwa-common-commerce": "6.22.0-beta.2",
20
- "@shopgate/pwa-core": "6.22.0-beta.2",
21
- "@shopgate/pwa-ui-ios": "6.22.0-beta.2",
22
- "@shopgate/pwa-ui-material": "6.22.0-beta.2",
23
- "@shopgate/pwa-ui-shared": "6.22.0-beta.2",
18
+ "@shopgate/pwa-common": "6.22.0-beta.3",
19
+ "@shopgate/pwa-common-commerce": "6.22.0-beta.3",
20
+ "@shopgate/pwa-core": "6.22.0-beta.3",
21
+ "@shopgate/pwa-ui-ios": "6.22.0-beta.3",
22
+ "@shopgate/pwa-ui-material": "6.22.0-beta.3",
23
+ "@shopgate/pwa-ui-shared": "6.22.0-beta.3",
24
24
  "@virtuous/conductor": "~2.4.0",
25
25
  "babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
26
26
  "babel-plugin-transform-es3-property-literals": "^6.8.0",
@@ -1 +1 @@
1
- export*from"./optInTrigger";
1
+ export*from"./optInTrigger";export*from"./pushOptIn";
@@ -0,0 +1,7 @@
1
+ import{HIDE_PUSH_OPT_IN_MODAL,SHOW_PUSH_OPT_IN_MODAL}from"../constants";/**
2
+ * action to be dispatched when the push opt-in should be shown
3
+ * @returns {Function}
4
+ */export var showPushOptInModal=function showPushOptInModal(){return{type:SHOW_PUSH_OPT_IN_MODAL};};/**
5
+ * action to be dispatched when the push opt-in should be hidden
6
+ * @returns {Function}
7
+ */export var hidePushOptInModal=function hidePushOptInModal(){return{type:HIDE_PUSH_OPT_IN_MODAL};};
@@ -1 +1 @@
1
- export*from"./optInTrigger";
1
+ export*from"./pushOptInModal";
@@ -0,0 +1,8 @@
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);});};}import{grantPushPermissions}from"../../core";import{hidePushOptInModal,optInPostponed}from"../action-creators";/**
2
+ * action to be dispatched when the user allowed the push opt-in in the modal
3
+ * and native modal should be triggered for setting the permission
4
+ * @returns {Function}
5
+ */export var allowPushOptIn=function allowPushOptIn(){return/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return dispatch(grantPushPermissions({useSettingsModal:true}));case 2:dispatch(hidePushOptInModal());case 3:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}();};/**
6
+ * action to be dispatched when the user denied the push opt-in in the modal
7
+ * @returns {Function}
8
+ */export var denyPushOptIn=function denyPushOptIn(){return/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(dispatch){return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.next=2;return dispatch(optInPostponed());case 2:dispatch(hidePushOptInModal());case 3:case"end":return _context2.stop();}}},_callee2);}));return function(_x2){return _ref2.apply(this,arguments);};}();};
@@ -0,0 +1,9 @@
1
+ import{connect}from'react-redux';import{getIsPushOptInModalVisible}from"../../selectors";import{allowPushOptIn,denyPushOptIn}from"../../actions";/**
2
+ * Maps the contents of the state to the component props.
3
+ * @param {Object} state The current application state.
4
+ * @return {Object} The extended component props.
5
+ */var mapStateToProps=function mapStateToProps(state){return{isPushOptInModalVisible:getIsPushOptInModalVisible(state)};};/**
6
+ * Connects the dispatch function to a callable function in the props.
7
+ * @param {Function} dispatch The redux dispatch function.
8
+ * @return {Object} The extended component props.
9
+ */var mapDispatchToProps={allowPushOptIn:allowPushOptIn,denyPushOptIn:denyPushOptIn};export default connect(mapStateToProps,mapDispatchToProps);
@@ -0,0 +1,10 @@
1
+ import React,{useMemo}from'react';import PropTypes from'prop-types';import classNames from'classnames';import{Grid,I18n,Button,Modal}from'@shopgate/engage/components';import{appConfig}from'@shopgate/engage';import pushImage from"./push-opt-in.svg";import styles from"./style";import connect from"./connector";/**
2
+ * The Push opt-in modal component.
3
+ * @param {Object} props The component props.
4
+ * @returns {JSX.Element}
5
+ */var PushOptInModal=function PushOptInModal(_ref){var isPushOptInModalVisible=_ref.isPushOptInModalVisible,allowPushOptIn=_ref.allowPushOptIn,denyPushOptIn=_ref.denyPushOptIn;var _appConfig$pushOptIn=appConfig.pushOptIn,modalMessage=_appConfig$pushOptIn.modalMessage,modalTitle=_appConfig$pushOptIn.modalTitle,modalButtonDeny=_appConfig$pushOptIn.modalButtonDeny,modalButtonAllow=_appConfig$pushOptIn.modalButtonAllow,modalImageURL=_appConfig$pushOptIn.modalImageURL,modalImageSVG=_appConfig$pushOptIn.modalImageSVG;var imageSRC=useMemo(function(){// No overwrite configured -> use default image
6
+ if(!modalImageURL&&!modalImageSVG){return pushImage;}// URL overwrite configured -> use it
7
+ if(modalImageURL){return modalImageURL;}// SVG overwrite configured -> create data url
8
+ try{// Remove any characters outside the Latin1 range
9
+ var decoded=decodeURIComponent(encodeURIComponent(modalImageSVG));// Now we can use btoa to convert the svg to base64
10
+ var base64=btoa(decoded);return"data:image/svg+xml;base64,".concat(base64);}catch(e){return pushImage;}},[modalImageSVG,modalImageURL]);if(!isPushOptInModalVisible){return null;}return/*#__PURE__*/React.createElement(Modal,{isOpened:isPushOptInModalVisible,classes:{content:styles.modalContent}},/*#__PURE__*/React.createElement(Grid,{className:classNames(styles.container,'push-opt-in-modal__container')},/*#__PURE__*/React.createElement(Grid.Item,{className:styles.item},/*#__PURE__*/React.createElement("img",{src:imageSRC,className:classNames(styles.image,'push-opt-in-modal__image'),alt:"","aria-hidden":"true"}),/*#__PURE__*/React.createElement(I18n.Text,{className:classNames(styles.title,'push-opt-in-modal__title'),string:modalTitle||'pushOptInModal.title'}),/*#__PURE__*/React.createElement(I18n.Text,{className:classNames('push-opt-in-modal__message'),string:modalMessage||'pushOptInModal.message'}),/*#__PURE__*/React.createElement(Button,{onClick:allowPushOptIn,type:"primary",className:classNames(styles.button,'push-opt-in-modal__button-allow')},/*#__PURE__*/React.createElement(I18n.Text,{string:modalButtonAllow||'pushOptInModal.buttonAllow'})),/*#__PURE__*/React.createElement(Button,{onClick:denyPushOptIn,type:"plain",className:classNames(styles.button,'push-opt-in-modal__button-deny')},/*#__PURE__*/React.createElement(I18n.Text,{string:modalButtonDeny||'pushOptInModal.buttonDeny',className:styles.buttonText})))));};export default connect(PushOptInModal);
@@ -0,0 +1 @@
1
+ import{css}from'glamor';import{themeColors}from'@shopgate/pwa-common/helpers/config';var modalContent=css({width:'100%'}).toString();var container=css({backgroundColor:themeColors.lightOverlay,height:'100vh',textAlign:'center',padding:'30px',justifyContent:'center',display:'flex',flexDirection:'column'}).toString();var title=css({fontWeight:'bold',fontSize:'1.35rem',paddingTop:'30px',paddingBottom:'30px'}).toString();var item=css({display:'flex',flexDirection:'column',alignItems:'center'}).toString();var link=css({paddingTop:'30px',textAlign:'center',color:themeColors.gray}).toString();var image=css({width:'80%',maxWidth:400}).toString();var button=css({marginTop:'30px'}).toString();var buttonText=css({color:themeColors.gray}).toString();export default{modalContent:modalContent,container:container,item:item,title:title,link:link,image:image,button:button,buttonText:buttonText};
@@ -0,0 +1 @@
1
+ export{default as PushOptInModal}from"./PushOptInModal";
@@ -1 +1 @@
1
- export*from"./optInTrigger";
1
+ export*from"./optInTrigger";export*from"./optInModal";
@@ -0,0 +1 @@
1
+ export var SHOW_PUSH_OPT_IN_MODAL='SHOW_PUSH_OPT_IN_MODAL';export var HIDE_PUSH_OPT_IN_MODAL='HIDE_PUSH_OPT_IN_MODAL';
@@ -1 +1 @@
1
- import{combineReducers}from'redux';import optInTrigger from"./optInTrigger";export default combineReducers({optInTrigger:optInTrigger});
1
+ import{combineReducers}from'redux';import optInTrigger from"./optInTrigger";import optInModal from"./optInModal";export default combineReducers({optInTrigger:optInTrigger,optInModal:optInModal});
@@ -0,0 +1,6 @@
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{HIDE_PUSH_OPT_IN_MODAL,SHOW_PUSH_OPT_IN_MODAL}from"../constants";var defaultState={isPushOptInModalVisible:false};/**
2
+ * Stores all the states related to the push Opt-In Modal functionality.
3
+ * @param {Object} [state] The current state.
4
+ * @param {Object} action The action object.
5
+ * @return {Object} The new state.
6
+ */var pushOptInModalReducer=function pushOptInModalReducer(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case SHOW_PUSH_OPT_IN_MODAL:{return _extends({},state,{isPushOptInModalVisible:true});}case HIDE_PUSH_OPT_IN_MODAL:{return _extends({},state,{isPushOptInModalVisible:false});}default:return state;}};export default pushOptInModalReducer;
@@ -1 +1 @@
1
- export*from"./optInTrigger";
1
+ export*from"./optInTrigger";export*from"./optInModal";
@@ -0,0 +1,8 @@
1
+ import{createSelector}from'reselect';/**
2
+ * Selects the push opt-in modal state.
3
+ * @param {Object} state The current state of the push opt-in modal.
4
+ * @returns {Object} whether push opt-in modal is shown.
5
+ */export var getPushOptInModalState=function getPushOptInModalState(state){var _state$pushOptIn;return(state===null||state===void 0?void 0:(_state$pushOptIn=state.pushOptIn)===null||_state$pushOptIn===void 0?void 0:_state$pushOptIn.optInModal)||{};};/**
6
+ * Selects the property of the push opt-in modal.
7
+ * @returns {boolean} whether push opt-in modal is shown.
8
+ */export var getIsPushOptInModalVisible=createSelector(getPushOptInModalState,function(modalState){return modalState.isPushOptInModalVisible||false;});
@@ -1,4 +1,4 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";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 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{appConfig}from'@shopgate/engage';import{main$,event,appDidStart$,getAppPermissions,PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED}from'@shopgate/engage/core';import{increaseAppStartCount,resetAppStartCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,setLastPopupTimestamp,increaseRejectionCount}from"../action-creators";import{PUSH_OPT_IN_OPT_IN_POSTPONED}from"../constants";import{getPushOptInTriggerState}from"../selectors";import{showOptIn}from"../actions";var DAY_IN_MS=1000*60*60*24;var increaseRejectionCount$=main$.filter(function(_ref){var action=_ref.action;return action.type===PUSH_OPT_IN_OPT_IN_POSTPONED;});/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";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 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{appConfig}from'@shopgate/engage';import{main$,event,appDidStart$,getAppPermissions,PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED}from'@shopgate/engage/core';import{increaseAppStartCount,resetAppStartCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,setLastPopupTimestamp,increaseRejectionCount,showPushOptInModal}from"../action-creators";import{PUSH_OPT_IN_OPT_IN_POSTPONED}from"../constants";import{getPushOptInTriggerState}from"../selectors";var DAY_IN_MS=1000*60*60*24;var increaseRejectionCount$=main$.filter(function(_ref){var action=_ref.action;return action.type===PUSH_OPT_IN_OPT_IN_POSTPONED;});/**
2
2
  * Push opt in subscriptions
3
3
  * @param {Function} subscribe The subscribe function
4
4
  */export default function pushOptIn(subscribe){/**
@@ -6,7 +6,7 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToAr
6
6
  * @param {string} configKey The "pushOptIn" key to be used
7
7
  * @param {Function} increaseCountAction Action to increase the count in Redux for the configKey
8
8
  * @returns {void}
9
- */var showOptInAfterChecks=/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2,configKey,increaseCountAction){var dispatch,getState,_appConfig$pushOptIn,appStarts,ordersPlaced,rejectionMaxCount,minDaysBetweenOptIns,_yield$getAppPermissi,_yield$getAppPermissi2,pushStatus,state,configValue,resetAction,resetCountState,configCountState,mustShowModal,hasRepeats,minDaysElapsed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref2.dispatch,getState=_ref2.getState;_appConfig$pushOptIn=appConfig.pushOptIn,appStarts=_appConfig$pushOptIn.appStarts,ordersPlaced=_appConfig$pushOptIn.ordersPlaced,rejectionMaxCount=_appConfig$pushOptIn.rejectionMaxCount,minDaysBetweenOptIns=_appConfig$pushOptIn.minDaysBetweenOptIns;// TODO add check to determine if the app supports push-opt-in
10
- _context.next=4;return getAppPermissions([PERMISSION_ID_PUSH]);case 4:_yield$getAppPermissi=_context.sent;_yield$getAppPermissi2=_slicedToArray(_yield$getAppPermissi,1);pushStatus=_yield$getAppPermissi2[0].status;if(!(pushStatus!==PERMISSION_STATUS_NOT_DETERMINED)){_context.next=9;break;}return _context.abrupt("return");case 9:dispatch(increaseCountAction());state=getPushOptInTriggerState(getState());configValue=appStarts;resetAction=resetAppStartCount;resetCountState=state.appStartResetCount;configCountState=state.appStartCount;if(configKey==='ordersPlaced'){configValue=ordersPlaced;resetAction=resetOrdersPlacedCount;resetCountState=state.ordersPlacedResetCount;configCountState=state.ordersPlacedCount;}if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=18;break;}return _context.abrupt("return");case 18:mustShowModal=Number(configValue.value)>0&&configCountState>=configValue.value;hasRepeats=configValue.repeats===null||resetCountState<=configValue.repeats;minDaysElapsed=Date.now()-state.lastPopupAt>=minDaysBetweenOptIns*DAY_IN_MS;if(mustShowModal&&hasRepeats&&minDaysElapsed){dispatch(setLastPopupTimestamp());dispatch(resetAction());dispatch(showOptIn());}case 22:case"end":return _context.stop();}}},_callee);}));return function showOptInAfterChecks(_x,_x2,_x3){return _ref3.apply(this,arguments);};}();// event subscriber to handle app start based push opt in
9
+ */var showOptInAfterChecks=/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2,configKey,increaseCountAction){var dispatch,getState,_appConfig$pushOptIn,appStarts,ordersPlaced,rejectionMaxCount,minDaysBetweenOptIns,_yield$getAppPermissi,_yield$getAppPermissi2,pushStatus,state,configValue,resetAction,resetCountState,configCountState,mustShowModal,hasRepeats,minDaysElapsed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref2.dispatch,getState=_ref2.getState;_appConfig$pushOptIn=appConfig.pushOptIn,appStarts=_appConfig$pushOptIn.appStarts,ordersPlaced=_appConfig$pushOptIn.ordersPlaced,rejectionMaxCount=_appConfig$pushOptIn.rejectionMaxCount,minDaysBetweenOptIns=_appConfig$pushOptIn.minDaysBetweenOptIns;// TODO add check to determine if the app supports push-opt-in (is done in CURB-3915)
10
+ _context.next=4;return getAppPermissions([PERMISSION_ID_PUSH]);case 4:_yield$getAppPermissi=_context.sent;_yield$getAppPermissi2=_slicedToArray(_yield$getAppPermissi,1);pushStatus=_yield$getAppPermissi2[0].status;if(!(pushStatus!==PERMISSION_STATUS_NOT_DETERMINED)){_context.next=9;break;}return _context.abrupt("return");case 9:dispatch(increaseCountAction());state=getPushOptInTriggerState(getState());configValue=appStarts;resetAction=resetAppStartCount;resetCountState=state.appStartResetCount;configCountState=state.appStartCount;if(configKey==='ordersPlaced'){configValue=ordersPlaced;resetAction=resetOrdersPlacedCount;resetCountState=state.ordersPlacedResetCount;configCountState=state.ordersPlacedCount;}if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=18;break;}return _context.abrupt("return");case 18:mustShowModal=Number(configValue.value)>0&&configCountState>=configValue.value;hasRepeats=configValue.repeats===null||resetCountState<=configValue.repeats;minDaysElapsed=Date.now()-state.lastPopupAt>=minDaysBetweenOptIns*DAY_IN_MS;if(mustShowModal&&hasRepeats&&minDaysElapsed){dispatch(setLastPopupTimestamp());dispatch(resetAction());dispatch(showPushOptInModal());}case 22:case"end":return _context.stop();}}},_callee);}));return function showOptInAfterChecks(_x,_x2,_x3){return _ref3.apply(this,arguments);};}();// event subscriber to handle app start based push opt in
11
11
  subscribe(appDidStart$,/*#__PURE__*/function(){var _ref5=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4){var dispatch,getState;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:dispatch=_ref4.dispatch,getState=_ref4.getState;_context2.next=3;return showOptInAfterChecks({dispatch:dispatch,getState:getState},'appStarts',increaseAppStartCount);case 3:case"end":return _context2.stop();}}},_callee2);}));return function(_x4){return _ref5.apply(this,arguments);};}());// event subscriber to handle order based push opt in
12
12
  subscribe(appDidStart$,function(_ref6){var dispatch=_ref6.dispatch,getState=_ref6.getState;event.addCallback('checkoutSuccess',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_context3.next=2;return showOptInAfterChecks({dispatch:dispatch,getState:getState},'ordersPlaced',increaseOrdersPlacedCount);case 2:case"end":return _context3.stop();}}},_callee3);})));});subscribe(increaseRejectionCount$,function(_ref8){var dispatch=_ref8.dispatch;dispatch(increaseRejectionCount());});}
@@ -1,4 +1,4 @@
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 _regeneratorRuntime from"@babel/runtime/regenerator";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 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{combineReducers}from'redux';import merge from'lodash/merge';import{createMockStore}from'@shopgate/pwa-common/store';import{event,getAppPermissions,PERMISSION_ID_PUSH,PERMISSION_STATUS_DENIED,APP_DID_START}from'@shopgate/engage/core';import{increaseAppStartCount,setLastPopupTimestamp,resetAppStartCount,increaseRejectionCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,optInPostponed}from"../action-creators";import{showOptIn}from"../actions";import pushReducers from"../reducers";import subscriptions from"./optInTrigger";/**
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 _regeneratorRuntime from"@babel/runtime/regenerator";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 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{combineReducers}from'redux';import merge from'lodash/merge';import{createMockStore}from'@shopgate/pwa-common/store';import{event,getAppPermissions,PERMISSION_ID_PUSH,PERMISSION_STATUS_DENIED,APP_DID_START}from'@shopgate/engage/core';import{increaseAppStartCount,setLastPopupTimestamp,resetAppStartCount,increaseRejectionCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,optInPostponed,showPushOptInModal}from"../action-creators";import pushReducers from"../reducers";import subscriptions from"./optInTrigger";/**
2
2
  * @typedef {Object} MockedConfigSetting
3
3
  * @property {number} value
4
4
  * @property {number|null} repeats
@@ -11,31 +11,31 @@ function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj
11
11
  */var mockedPushOptInConfig;/**
12
12
  * Updates the mocked pushOptIn config with custom values.
13
13
  * @param {MockedConfig} update The custom config values
14
- */var setMockedConfig=function setMockedConfig(){var update=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};mockedPushOptInConfig=merge({appStarts:{value:1,repeats:null},ordersPlaced:{value:1,repeats:null},rejectionMaxCount:2,minDaysBetweenOptIns:1},update);};jest.mock("../actions/optInTrigger.js",function(){return{showOptIn:jest.fn()};});jest.mock('@shopgate/engage',function(){return{appConfig:{get pushOptIn(){return mockedPushOptInConfig;}}};});jest.mock('@shopgate/engage/core',function(){/* eslint-disable no-shadow */var _jest$requireActual=jest.requireActual('@shopgate/engage/core'),appDidStart$=_jest$requireActual.appDidStart$,main$=_jest$requireActual.main$,PERMISSION_ID_PUSH=_jest$requireActual.PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED=_jest$requireActual.PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_GRANTED=_jest$requireActual.PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED=_jest$requireActual.PERMISSION_STATUS_DENIED,APP_DID_START=_jest$requireActual.APP_DID_START;/* eslint-enable no-shadow */return{main$:main$,appDidStart$:appDidStart$,PERMISSION_ID_PUSH:PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED:PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_GRANTED:PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED:PERMISSION_STATUS_DENIED,APP_DID_START:APP_DID_START,getAppPermissions:jest.fn().mockResolvedValue([{status:PERMISSION_STATUS_NOT_DETERMINED}]),event:{addCallback:jest.fn()}};});describe('Push OptIn Subscriptions',function(){var subscribe=jest.fn();var dispatch;var getState;var callbackParams;var mockedTS=new Date('2024-01-31T12:00:00.000Z').getTime();var dateMock;beforeEach(function(){setMockedConfig();jest.clearAllMocks();var store=createMockStore(combineReducers({pushOptIn:pushReducers}),subscriptions);jest.spyOn(store,'dispatch');jest.spyOn(store,'getState');dateMock=jest.spyOn(Date,'now').mockImplementation(function(){return mockedTS;});dispatch=store.dispatch;getState=store.getState;callbackParams={dispatch:dispatch,getState:getState};subscriptions(subscribe);// By default dispatching the showOptIn action results into dispatching the optInPostponed
15
- // action
16
- showOptIn.mockImplementation(function(){return function(thunkDispatch){thunkDispatch(optInPostponed());};});});/**
14
+ */var setMockedConfig=function setMockedConfig(){var update=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};mockedPushOptInConfig=merge({appStarts:{value:1,repeats:null},ordersPlaced:{value:1,repeats:null},rejectionMaxCount:2,minDaysBetweenOptIns:1},update);};jest.mock("../action-creators/pushOptIn.js",function(){return{showPushOptInModal:jest.fn()};});jest.mock('@shopgate/engage',function(){return{appConfig:{get pushOptIn(){return mockedPushOptInConfig;}}};});jest.mock('@shopgate/engage/core',function(){/* eslint-disable no-shadow */var _jest$requireActual=jest.requireActual('@shopgate/engage/core'),appDidStart$=_jest$requireActual.appDidStart$,main$=_jest$requireActual.main$,PERMISSION_ID_PUSH=_jest$requireActual.PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED=_jest$requireActual.PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_GRANTED=_jest$requireActual.PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED=_jest$requireActual.PERMISSION_STATUS_DENIED,APP_DID_START=_jest$requireActual.APP_DID_START;/* eslint-enable no-shadow */return{main$:main$,appDidStart$:appDidStart$,PERMISSION_ID_PUSH:PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED:PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_GRANTED:PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED:PERMISSION_STATUS_DENIED,APP_DID_START:APP_DID_START,getAppPermissions:jest.fn().mockResolvedValue([{status:PERMISSION_STATUS_NOT_DETERMINED}]),event:{addCallback:jest.fn()}};});describe('Push OptIn Subscriptions',function(){var subscribe=jest.fn();var dispatch;var getState;var callbackParams;var mockedTS=new Date('2024-01-31T12:00:00.000Z').getTime();var dateMock;beforeEach(function(){setMockedConfig();jest.clearAllMocks();var store=createMockStore(combineReducers({pushOptIn:pushReducers}),subscriptions);jest.spyOn(store,'dispatch');jest.spyOn(store,'getState');dateMock=jest.spyOn(Date,'now').mockImplementation(function(){return mockedTS;});dispatch=store.dispatch;getState=store.getState;callbackParams={dispatch:dispatch,getState:getState};subscriptions(subscribe);// By default dispatching the showPushOptInModal action results
15
+ // into dispatching the optInPostponed action
16
+ showPushOptInModal.mockImplementation(function(){return function(thunkDispatch){thunkDispatch(optInPostponed());};});});/**
17
17
  * Since subscriptions for handling appStarts and ordersPlaced settings share the same logic and
18
18
  * just operate on different properties of the related app config, both test blocks are equal
19
19
  * can can be executed in a loop.
20
20
  */describe.each(['appStarts','ordersPlaced'])('Counter tests',function(configType){describe("Logic for ".concat(configType),function(){var callback;var eventName;var increaseCountAction;var resetCountAction;beforeEach(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var _subscribe$mock$calls,_subscribe$mock$calls2,_subscribe$mock$calls3,_subscribe$mock$calls4,subscribeCallback,_event$addCallback$mo,_event$addCallback$mo2;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(!(configType==='appStarts')){_context.next=8;break;}// Pick the callback of the subscriptions for handling of the appStarts setting
21
21
  _subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);_subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);callback=_subscribe$mock$calls2[1];increaseCountAction=increaseAppStartCount;resetCountAction=resetAppStartCount;_context.next=18;break;case 8:if(!(configType==='ordersPlaced')){_context.next=18;break;}// Pick the callback of the subscriptions for handling of the ordersPlaced setting
22
22
  _subscribe$mock$calls3=_slicedToArray(subscribe.mock.calls,2),_subscribe$mock$calls4=_slicedToArray(_subscribe$mock$calls3[1],2),subscribeCallback=_subscribe$mock$calls4[1];// Invoke the callback, so that an event handler for "checkoutSuccess" is registered
23
- _context.next=12;return subscribeCallback(callbackParams);case 12:_event$addCallback$mo=_slicedToArray(event.addCallback.mock.calls,1);_event$addCallback$mo2=_slicedToArray(_event$addCallback$mo[0],2);eventName=_event$addCallback$mo2[0];callback=_event$addCallback$mo2[1];increaseCountAction=increaseOrdersPlacedCount;resetCountAction=resetOrdersPlacedCount;case 18:case"end":return _context.stop();}}},_callee);})));if(configType==='ordersPlaced'){it('should register for the expected event',function(){expect(eventName).toBe('checkoutSuccess');});}it('should not trigger opt-in when push permission has not status "notDetermined" anymore',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:setMockedConfig(_defineProperty({},configType,{value:1}));getAppPermissions.mockResolvedValueOnce([{status:PERMISSION_STATUS_DENIED}]);_context2.next=4;return callback(callbackParams);case 4:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).not.toHaveBeenCalled();case 7:case"end":return _context2.stop();}}},_callee2);})));it('should not trigger opt-in when config key is set to 0',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:setMockedConfig(_defineProperty({},configType,{value:0}));_context3.next=3;return callback(callbackParams);case 3:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(increaseCountAction());expect(showOptIn).not.toHaveBeenCalled();case 8:case"end":return _context3.stop();}}},_callee3);})));it('should trigger opt-in at the first counter increase',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:setMockedConfig(_defineProperty({},configType,{value:1}));_context4.next=3;return callback(callbackParams);case 3:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).toHaveBeenCalledTimes(4);expect(dispatch).toHaveBeenCalledWith(increaseCountAction());expect(dispatch).toHaveBeenCalledWith(setLastPopupTimestamp());expect(dispatch).toHaveBeenCalledWith(resetCountAction());expect(showOptIn).toHaveBeenCalledTimes(1);case 10:case"end":return _context4.stop();}}},_callee4);})));it('should trigger opt-in at the 3rd counter increase',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(){return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:setMockedConfig(_defineProperty({},configType,{value:3}));// 1st counter increase -> do not show opt-in
24
- _context5.next=3;return callback(callbackParams);case 3:expect(dispatch).toHaveBeenCalledTimes(1);expect(showOptIn).not.toHaveBeenCalled();// 2nd counter increase -> do not show opt-in
25
- _context5.next=7;return callback(callbackParams);case 7:expect(dispatch).toHaveBeenCalledTimes(2);expect(showOptIn).not.toHaveBeenCalled();// 3rd counter increase -> show opt-in
26
- _context5.next=11;return callback(callbackParams);case 11:expect(dispatch).toHaveBeenCalledTimes(6);expect(showOptIn).toHaveBeenCalledTimes(1);case 13:case"end":return _context5.stop();}}},_callee5);})));it('should not trigger opt-in again till "minDaysBetweenOptIns" elapsed',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(){var _setMockedConfig5;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:setMockedConfig((_setMockedConfig5={},_defineProperty(_setMockedConfig5,configType,{value:1}),_defineProperty(_setMockedConfig5,"minDaysBetweenOptIns",1),_setMockedConfig5));// 1st counter increase -> show opt-in
27
- _context6.next=3;return callback(callbackParams);case 3:expect(showOptIn).toHaveBeenCalledTimes(1);// fast forward time by 1/2 day
23
+ _context.next=12;return subscribeCallback(callbackParams);case 12:_event$addCallback$mo=_slicedToArray(event.addCallback.mock.calls,1);_event$addCallback$mo2=_slicedToArray(_event$addCallback$mo[0],2);eventName=_event$addCallback$mo2[0];callback=_event$addCallback$mo2[1];increaseCountAction=increaseOrdersPlacedCount;resetCountAction=resetOrdersPlacedCount;case 18:case"end":return _context.stop();}}},_callee);})));if(configType==='ordersPlaced'){it('should register for the expected event',function(){expect(eventName).toBe('checkoutSuccess');});}it('should not trigger opt-in when push permission has not status "notDetermined" anymore',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:setMockedConfig(_defineProperty({},configType,{value:1}));getAppPermissions.mockResolvedValueOnce([{status:PERMISSION_STATUS_DENIED}]);_context2.next=4;return callback(callbackParams);case 4:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).not.toHaveBeenCalled();case 7:case"end":return _context2.stop();}}},_callee2);})));it('should not trigger opt-in when config key is set to 0',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:setMockedConfig(_defineProperty({},configType,{value:0}));_context3.next=3;return callback(callbackParams);case 3:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(increaseCountAction());expect(showPushOptInModal).not.toHaveBeenCalled();case 8:case"end":return _context3.stop();}}},_callee3);})));it('should trigger opt-in at the first counter increase',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:setMockedConfig(_defineProperty({},configType,{value:1}));_context4.next=3;return callback(callbackParams);case 3:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).toHaveBeenCalledTimes(4);expect(dispatch).toHaveBeenCalledWith(increaseCountAction());expect(dispatch).toHaveBeenCalledWith(setLastPopupTimestamp());expect(dispatch).toHaveBeenCalledWith(resetCountAction());expect(showPushOptInModal).toHaveBeenCalledTimes(1);case 10:case"end":return _context4.stop();}}},_callee4);})));it('should trigger opt-in at the 3rd counter increase',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(){return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:setMockedConfig(_defineProperty({},configType,{value:3}));// 1st counter increase -> do not show opt-in
24
+ _context5.next=3;return callback(callbackParams);case 3:expect(dispatch).toHaveBeenCalledTimes(1);expect(showPushOptInModal).not.toHaveBeenCalled();// 2nd counter increase -> do not show opt-in
25
+ _context5.next=7;return callback(callbackParams);case 7:expect(dispatch).toHaveBeenCalledTimes(2);expect(showPushOptInModal).not.toHaveBeenCalled();// 3rd counter increase -> show opt-in
26
+ _context5.next=11;return callback(callbackParams);case 11:expect(dispatch).toHaveBeenCalledTimes(6);expect(showPushOptInModal).toHaveBeenCalledTimes(1);case 13:case"end":return _context5.stop();}}},_callee5);})));it('should not trigger opt-in again till "minDaysBetweenOptIns" elapsed',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(){var _setMockedConfig5;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:setMockedConfig((_setMockedConfig5={},_defineProperty(_setMockedConfig5,configType,{value:1}),_defineProperty(_setMockedConfig5,"minDaysBetweenOptIns",1),_setMockedConfig5));// 1st counter increase -> show opt-in
27
+ _context6.next=3;return callback(callbackParams);case 3:expect(showPushOptInModal).toHaveBeenCalledTimes(1);// fast forward time by 1/2 day
28
28
  dateMock.mockImplementation(function(){return mockedTS+1000*60*60*12;});// 2nd counter increase -> do not show opt due to min days setting
29
- _context6.next=7;return callback(callbackParams);case 7:expect(showOptIn).toHaveBeenCalledTimes(1);// 3rd counter increase -> do not show opt due to min days setting
30
- _context6.next=10;return callback(callbackParams);case 10:expect(showOptIn).toHaveBeenCalledTimes(1);// fast forward time by 1 day
29
+ _context6.next=7;return callback(callbackParams);case 7:expect(showPushOptInModal).toHaveBeenCalledTimes(1);// 3rd counter increase -> do not show opt due to min days setting
30
+ _context6.next=10;return callback(callbackParams);case 10:expect(showPushOptInModal).toHaveBeenCalledTimes(1);// fast forward time by 1 day
31
31
  dateMock.mockImplementation(function(){return mockedTS+1000*60*60*24;});// 4th counter increase -> show opt-in again
32
- _context6.next=14;return callback(callbackParams);case 14:expect(showOptIn).toHaveBeenCalledTimes(2);case 15:case"end":return _context6.stop();}}},_callee6);})));it('should not trigger opt-in when max rejection count is reached',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(){var _setMockedConfig6;return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:setMockedConfig((_setMockedConfig6={},_defineProperty(_setMockedConfig6,configType,{value:1}),_defineProperty(_setMockedConfig6,"minDaysBetweenOptIns",0),_defineProperty(_setMockedConfig6,"rejectionMaxCount",2),_setMockedConfig6));// 1st counter increase -> show opt-in
33
- _context7.next=3;return callback(callbackParams);case 3:expect(showOptIn).toHaveBeenCalledTimes(1);// 2nd counter increase -> show opt-in
34
- _context7.next=6;return callback(callbackParams);case 6:expect(showOptIn).toHaveBeenCalledTimes(2);// 3rd counter increase -> no opt-in due to rejection count
35
- _context7.next=9;return callback(callbackParams);case 9:expect(showOptIn).toHaveBeenCalledTimes(2);case 10:case"end":return _context7.stop();}}},_callee7);})));it('should not trigger opt-in when max repeats are reached',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(){var _setMockedConfig7;return _regeneratorRuntime.wrap(function _callee8$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:setMockedConfig((_setMockedConfig7={},_defineProperty(_setMockedConfig7,configType,{value:2,repeats:2}),_defineProperty(_setMockedConfig7,"minDaysBetweenOptIns",0),_defineProperty(_setMockedConfig7,"rejectionMaxCount",4),_setMockedConfig7));_context8.next=3;return callback(callbackParams);case 3:_context8.next=5;return callback(callbackParams);case 5:expect(showOptIn).toHaveBeenCalledTimes(1);_context8.next=8;return callback(callbackParams);case 8:_context8.next=10;return callback(callbackParams);case 10:expect(showOptIn).toHaveBeenCalledTimes(2);_context8.next=13;return callback(callbackParams);case 13:_context8.next=15;return callback(callbackParams);case 15:expect(showOptIn).toHaveBeenCalledTimes(3);_context8.next=18;return callback(callbackParams);case 18:_context8.next=20;return callback(callbackParams);case 20:expect(showOptIn).toHaveBeenCalledTimes(3);case 21:case"end":return _context8.stop();}}},_callee8);})));});});describe('Combined counter tests',function(){var appStartsSubscriberCallback;var ordersPlacedSubscriberCallback;beforeEach(function(){var _subscribe$mock$calls5=_slicedToArray(subscribe.mock.calls,2);var _subscribe$mock$calls6=_slicedToArray(_subscribe$mock$calls5[0],2);appStartsSubscriberCallback=_subscribe$mock$calls6[1];var _subscribe$mock$calls7=_slicedToArray(_subscribe$mock$calls5[1],2);ordersPlacedSubscriberCallback=_subscribe$mock$calls7[1];});it('should trigger opt-in for ordersPlaced when max views for appStarts already exceeded',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(){var _event$addCallback$mo3,_event$addCallback$mo4,checkoutSuccessCallback;return _regeneratorRuntime.wrap(function _callee9$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:setMockedConfig({appStarts:{value:1,repeats:2},ordersPlaced:{value:1,repeats:1},minDaysBetweenOptIns:0,rejectionMaxCount:4});// 3 opt-ins can be triggered before opt-in by appStart is exceeded (initial + 2 repeats)
36
- _context9.next=3;return appStartsSubscriberCallback(callbackParams);case 3:expect(showOptIn).toHaveBeenCalledTimes(1);_context9.next=6;return appStartsSubscriberCallback(callbackParams);case 6:expect(showOptIn).toHaveBeenCalledTimes(2);_context9.next=9;return appStartsSubscriberCallback(callbackParams);case 9:expect(showOptIn).toHaveBeenCalledTimes(3);// Opt-in does't show anymore for 4th app start since repeats exceeded
37
- _context9.next=12;return appStartsSubscriberCallback(callbackParams);case 12:expect(showOptIn).toHaveBeenCalledTimes(3);ordersPlacedSubscriberCallback(callbackParams);_event$addCallback$mo3=_slicedToArray(event.addCallback.mock.calls,1),_event$addCallback$mo4=_slicedToArray(_event$addCallback$mo3[0],2),checkoutSuccessCallback=_event$addCallback$mo4[1];// Opt-in shows again since max rejection count is not reached yet
38
- _context9.next=17;return checkoutSuccessCallback();case 17:expect(showOptIn).toHaveBeenCalledTimes(4);// Opt-in doesn't show anymore for the 2nd order placement, since max rejection count exceeded
39
- _context9.next=20;return checkoutSuccessCallback();case 20:expect(showOptIn).toHaveBeenCalledTimes(4);case 21:case"end":return _context9.stop();}}},_callee9);})));});describe('appDidStart$',function(){it('should run expected logic when appDidStart$ stream emits',function(){setMockedConfig({appStarts:{value:1,repeats:1},ordersPlaced:{value:1,repeats:1},minDaysBetweenOptIns:0});dispatch({type:APP_DID_START});// getAppPermissions should have been called 1st time for appDidStart
32
+ _context6.next=14;return callback(callbackParams);case 14:expect(showPushOptInModal).toHaveBeenCalledTimes(2);case 15:case"end":return _context6.stop();}}},_callee6);})));it('should not trigger opt-in when max rejection count is reached',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(){var _setMockedConfig6;return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:setMockedConfig((_setMockedConfig6={},_defineProperty(_setMockedConfig6,configType,{value:1}),_defineProperty(_setMockedConfig6,"minDaysBetweenOptIns",0),_defineProperty(_setMockedConfig6,"rejectionMaxCount",2),_setMockedConfig6));// 1st counter increase -> show opt-in
33
+ _context7.next=3;return callback(callbackParams);case 3:expect(showPushOptInModal).toHaveBeenCalledTimes(1);// 2nd counter increase -> show opt-in
34
+ _context7.next=6;return callback(callbackParams);case 6:expect(showPushOptInModal).toHaveBeenCalledTimes(2);// 3rd counter increase -> no opt-in due to rejection count
35
+ _context7.next=9;return callback(callbackParams);case 9:expect(showPushOptInModal).toHaveBeenCalledTimes(2);case 10:case"end":return _context7.stop();}}},_callee7);})));it('should not trigger opt-in when max repeats are reached',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(){var _setMockedConfig7;return _regeneratorRuntime.wrap(function _callee8$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:setMockedConfig((_setMockedConfig7={},_defineProperty(_setMockedConfig7,configType,{value:2,repeats:2}),_defineProperty(_setMockedConfig7,"minDaysBetweenOptIns",0),_defineProperty(_setMockedConfig7,"rejectionMaxCount",4),_setMockedConfig7));_context8.next=3;return callback(callbackParams);case 3:_context8.next=5;return callback(callbackParams);case 5:expect(showPushOptInModal).toHaveBeenCalledTimes(1);_context8.next=8;return callback(callbackParams);case 8:_context8.next=10;return callback(callbackParams);case 10:expect(showPushOptInModal).toHaveBeenCalledTimes(2);_context8.next=13;return callback(callbackParams);case 13:_context8.next=15;return callback(callbackParams);case 15:expect(showPushOptInModal).toHaveBeenCalledTimes(3);_context8.next=18;return callback(callbackParams);case 18:_context8.next=20;return callback(callbackParams);case 20:expect(showPushOptInModal).toHaveBeenCalledTimes(3);case 21:case"end":return _context8.stop();}}},_callee8);})));});});describe('Combined counter tests',function(){var appStartsSubscriberCallback;var ordersPlacedSubscriberCallback;beforeEach(function(){var _subscribe$mock$calls5=_slicedToArray(subscribe.mock.calls,2);var _subscribe$mock$calls6=_slicedToArray(_subscribe$mock$calls5[0],2);appStartsSubscriberCallback=_subscribe$mock$calls6[1];var _subscribe$mock$calls7=_slicedToArray(_subscribe$mock$calls5[1],2);ordersPlacedSubscriberCallback=_subscribe$mock$calls7[1];});it('should trigger opt-in for ordersPlaced when max views for appStarts already exceeded',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(){var _event$addCallback$mo3,_event$addCallback$mo4,checkoutSuccessCallback;return _regeneratorRuntime.wrap(function _callee9$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:setMockedConfig({appStarts:{value:1,repeats:2},ordersPlaced:{value:1,repeats:1},minDaysBetweenOptIns:0,rejectionMaxCount:4});// 3 opt-ins can be triggered before opt-in by appStart is exceeded (initial + 2 repeats)
36
+ _context9.next=3;return appStartsSubscriberCallback(callbackParams);case 3:expect(showPushOptInModal).toHaveBeenCalledTimes(1);_context9.next=6;return appStartsSubscriberCallback(callbackParams);case 6:expect(showPushOptInModal).toHaveBeenCalledTimes(2);_context9.next=9;return appStartsSubscriberCallback(callbackParams);case 9:expect(showPushOptInModal).toHaveBeenCalledTimes(3);// Opt-in does't show anymore for 4th app start since repeats exceeded
37
+ _context9.next=12;return appStartsSubscriberCallback(callbackParams);case 12:expect(showPushOptInModal).toHaveBeenCalledTimes(3);ordersPlacedSubscriberCallback(callbackParams);_event$addCallback$mo3=_slicedToArray(event.addCallback.mock.calls,1),_event$addCallback$mo4=_slicedToArray(_event$addCallback$mo3[0],2),checkoutSuccessCallback=_event$addCallback$mo4[1];// Opt-in shows again since max rejection count is not reached yet
38
+ _context9.next=17;return checkoutSuccessCallback();case 17:expect(showPushOptInModal).toHaveBeenCalledTimes(4);// Opt-in doesn't show anymore for the 2nd order placement, since max rejection count exceeded
39
+ _context9.next=20;return checkoutSuccessCallback();case 20:expect(showPushOptInModal).toHaveBeenCalledTimes(4);case 21:case"end":return _context9.stop();}}},_callee9);})));});describe('appDidStart$',function(){it('should run expected logic when appDidStart$ stream emits',function(){setMockedConfig({appStarts:{value:1,repeats:1},ordersPlaced:{value:1,repeats:1},minDaysBetweenOptIns:0});dispatch({type:APP_DID_START});// getAppPermissions should have been called 1st time for appDidStart
40
40
  expect(getAppPermissions).toHaveBeenCalledTimes(1);var _event$addCallback$mo5=_slicedToArray(event.addCallback.mock.calls,1),_event$addCallback$mo6=_slicedToArray(_event$addCallback$mo5[0],2),eventName=_event$addCallback$mo6[0],eventCallback=_event$addCallback$mo6[1];expect(eventName).toBe('checkoutSuccess');eventCallback();// getAppPermissions should have been called 2nd time for checkoutSuccess event
41
41
  expect(getAppPermissions).toHaveBeenCalledTimes(2);});});describe('increaseRejectionCount$',function(){var callback;beforeEach(function(){var _subscribe$mock$calls8=_slicedToArray(subscribe.mock.calls,3);var _subscribe$mock$calls9=_slicedToArray(_subscribe$mock$calls8[2],2);callback=_subscribe$mock$calls9[1];});it('should dispatch the increaseRejectionCount action when subscription emits',function(){callback(callbackParams);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(increaseRejectionCount());});});});
@@ -1,6 +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);});};}/**
2
- * Redux thunk to the dispatched when the push opt in is supposed to be shown
3
- * (Modal or native Dialog)
4
- * @returns {Function}
5
- */export var showOptIn=function showOptIn(){return/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:// TODO implement logic
6
- console.warn('SHOW_PUSH_OPT_IN');case 1:case"end":return _context.stop();}}},_callee);}));};