@shopgate/pwa-tracking 6.22.0-beta.3 → 6.22.0-beta.4
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/CHANGELOG.md +129 -0
- package/package.json +5 -5
- package/helpers/index.spec.js +0 -1
- package/selectors/cart.spec.js +0 -2
- package/selectors/user.spec.js +0 -1
- package/streams/category.spec.js +0 -13
- package/streams/checkout.spec.js +0 -1
- package/streams/page.spec.js +0 -1
- package/streams/pages.spec.js +0 -12
- package/streams/product.spec.js +0 -7
- package/streams/scanner.spec.js +0 -1
- package/streams/search.spec.js +0 -7
- package/streams/user.spec.js +0 -5
- package/subscriptions/checkout.spec.js +0 -4
- package/subscriptions/scanner.spec.js +0 -5
- package/subscriptions/user.spec.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
|
|
2
|
+
# Changelog
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
### [1.2.4](https://github.com/shopgate/pwa-tracking/compare/v1.2.3...v1.2.4) - January 25, 2018
|
|
6
|
+
#### Changed
|
|
7
|
+
- Added `/favorite_list` to the blacklist for tracked pages
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
### [1.2.3](https://github.com/shopgate/pwa-tracking/compare/v1.2.2...v1.2.3) - January 24, 2018
|
|
12
|
+
#### Changed
|
|
13
|
+
- Updated `@shopgate/pwa-common` dev dependency to ^2.0.0
|
|
14
|
+
- Updated `@shopgate/pwa-common-commerce` dev dependency to ^2.0.0
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
### [1.2.2](https://github.com/shopgate/pwa-tracking/compare/v1.2.1...v1.2.0) - January 17, 2018
|
|
19
|
+
#### Fixed
|
|
20
|
+
- Tracking event `initiatedCheckout`
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
### [1.2.0](https://github.com/shopgate/pwa-tracking/compare/v1.1.2...v1.2.0) - January 08, 2018
|
|
25
|
+
|
|
26
|
+
#### Changed
|
|
27
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.1.4
|
|
28
|
+
|
|
29
|
+
#### Fixed
|
|
30
|
+
- A bug where the `categoryDataLoaded$` Observable did not work correctly
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### [1.1.2](https://github.com/shopgate/pwa-tracking/compare/v1.1.1...v1.1.2) - December 28, 2017
|
|
35
|
+
|
|
36
|
+
#### Changed
|
|
37
|
+
- Updated `@shopgate/pwa-common` to ^1.1.3
|
|
38
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.1.3
|
|
39
|
+
- Updated `@shopgate/tracking-core` to ^1.0.8
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
### [1.1.1](https://github.com/shopgate/pwa-tracking/compare/v1.1.0...v1.1.1) - December 22, 2017
|
|
44
|
+
|
|
45
|
+
#### Changed
|
|
46
|
+
- Updated `@shopgate/pwa-common` to ^1.1.2
|
|
47
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.1.2
|
|
48
|
+
- Updated `@shopgate/pwa-core` to ^1.1.0
|
|
49
|
+
- Updated `@shopgate/tracking-core` to ^1.0.7
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### [1.1.0](https://github.com/shopgate/pwa-tracking/compare/v1.0.7...v1.1.0) - December 22, 2017
|
|
54
|
+
|
|
55
|
+
#### Added
|
|
56
|
+
- React 16 support
|
|
57
|
+
|
|
58
|
+
#### Changed
|
|
59
|
+
- Updated `@shopgate/eslint-config` to ^1.0.3
|
|
60
|
+
- Updated `@shopgate/pwa-common` to ^1.1.1
|
|
61
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.1.1
|
|
62
|
+
- Updated `@shopgate/pwa-unit-test` to ^1.3.0
|
|
63
|
+
- Updated `@shopgate/tracking-core` to ^1.0.6
|
|
64
|
+
- Updated `react` to ^16.2.0
|
|
65
|
+
- Updated `react-dom` to ^16.2.0
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### [1.0.7](https://github.com/shopgate/pwa-tracking/compare/v1.0.6...v1.0.6) - December 21, 2017
|
|
70
|
+
|
|
71
|
+
#### Added
|
|
72
|
+
- Purchases are now automatically tracked when a checkout has been successful
|
|
73
|
+
|
|
74
|
+
#### Changed
|
|
75
|
+
- Updated `@shopgate/pwa-common` to ^1.0.12
|
|
76
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.0.6
|
|
77
|
+
- Updated `@shopgate/pwa-core` to ^1.0.5
|
|
78
|
+
- Updated `@shopgate/tracking-core` to ^1.0.5
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### [1.0.6](https://github.com/shopgate/pwa-tracking/compare/v1.0.5...v1.0.6) - December 15, 2017
|
|
83
|
+
|
|
84
|
+
#### Changed
|
|
85
|
+
- Updated `@shopgate/pwa-common` to ^1.0.11
|
|
86
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.0.5
|
|
87
|
+
- Updated `@shopgate/tracking-core` to ^1.0.4
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### [1.0.5](https://github.com/shopgate/pwa-tracking/compare/v1.0.3...v1.0.5) - December 11, 2017
|
|
92
|
+
|
|
93
|
+
#### Changed
|
|
94
|
+
- Updated `@shopgate/pwa-common` to ^1.0.5
|
|
95
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.0.4
|
|
96
|
+
- Updated `@shopgate/pwa-core` to ^1.0.4
|
|
97
|
+
- Updated `@shopgate/tracking-core` to ^1.0.3
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### [1.0.3](https://github.com/shopgate/pwa-tracking/compare/v1.0.2...v1.0.3) - December 11, 2017
|
|
102
|
+
|
|
103
|
+
#### Changed
|
|
104
|
+
- Updated `@shopgate/pwa-common` to ^1.0.4
|
|
105
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.0.3
|
|
106
|
+
- Updated `@shopgate/pwa-core` to ^1.0.3
|
|
107
|
+
- Updated `@shopgate/tracking-core` to ^1.0.2
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### [1.0.2](https://github.com/shopgate/pwa-tracking/compare/v1.0.1...v1.0.2) - December 07, 2017
|
|
112
|
+
|
|
113
|
+
#### Changed
|
|
114
|
+
- Updated `@shopgate/pwa-common` to ^1.0.3
|
|
115
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.0.2
|
|
116
|
+
- Updated `@shopgate/tracking-core` to ^1.0.1
|
|
117
|
+
|
|
118
|
+
### Removed
|
|
119
|
+
- Default export containing all subscriptions
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### [1.0.1](https://github.com/shopgate/pwa-tracking/compare/v1.0.0...v1.0.1) - December 07, 2017
|
|
124
|
+
|
|
125
|
+
#### Changed
|
|
126
|
+
- Updated `@shopgate/pwa-common` to ^1.0.2
|
|
127
|
+
- Updated `@shopgate/pwa-common-commerce` to ^1.0.1
|
|
128
|
+
- Updated `@shopgate/pwa-core` to ^1.0.0
|
|
129
|
+
- Updated `@shopgate/tracking-core` to ^1.0.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-tracking",
|
|
3
|
-
"version": "6.22.0-beta.
|
|
3
|
+
"version": "6.22.0-beta.4",
|
|
4
4
|
"description": "Tracking library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"connect"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@shopgate/pwa-common": "6.22.0-beta.
|
|
19
|
-
"@shopgate/pwa-common-commerce": "6.22.0-beta.
|
|
20
|
-
"@shopgate/pwa-core": "6.22.0-beta.
|
|
21
|
-
"@shopgate/tracking-core": "6.22.0-beta.
|
|
18
|
+
"@shopgate/pwa-common": "6.22.0-beta.4",
|
|
19
|
+
"@shopgate/pwa-common-commerce": "6.22.0-beta.4",
|
|
20
|
+
"@shopgate/pwa-core": "6.22.0-beta.4",
|
|
21
|
+
"@shopgate/tracking-core": "6.22.0-beta.4",
|
|
22
22
|
"reselect": "^3.0.1",
|
|
23
23
|
"rxjs": "~5.5.12"
|
|
24
24
|
}
|
package/helpers/index.spec.js
DELETED
|
@@ -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 core from'@shopgate/tracking-core/core/Core';import{i18n}from'@shopgate/engage/core';import{createScannerEventData,buildScannerUtmUrl,createCategoryData,createRootCategoryData,createPageviewData}from"./index";jest.mock('@shopgate/engage/core',function(){return{i18n:{text:jest.fn()}};});var scannerEvents=core.getScannerEvents();describe('Tracking helpers',function(){var formatQrCode='QR_CODE';var defaultEvent=scannerEvents.SCAN_SUCCESS;describe('createScannerEventData()',function(){it('should create data when there was no user interaction',function(){var result=createScannerEventData({event:defaultEvent,type:formatQrCode,userInteraction:false});expect(result).toEqual({eventAction:defaultEvent,userInteraction:false});});it('should create data when there was user interaction',function(){var result=createScannerEventData({event:defaultEvent,type:formatQrCode,userInteraction:true});expect(result).toEqual({eventAction:defaultEvent,userInteraction:true});});describe('QR Codes',function(){var productId='abc123';var couponCode='CODE';var categoryId='123abc';var searchPhrase='Search';var pageId='page';var defaultParams={event:defaultEvent,format:'QR_CODE'};var defaultResult={eventAction:defaultEvent};it('should create data for the type HOMEPAGE',function(){var payload='http://2d.is/5/30186?s=30';var eventLabel="".concat(formatQrCode," - main");var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});it('should create data for the type PRODUCT',function(){var payload="http://2d.is/7/30186/".concat(productId,"?s=25");var eventLabel="".concat(formatQrCode," - product - ").concat(productId);var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});it('should create data for the type PRODUCT_WITH_COUPON',function(){var payload="http://2d.is/9/30186/".concat(productId,"/").concat(couponCode,"?s=26");var eventLabel="".concat(formatQrCode," - productcoupon - ").concat(productId,"_").concat(couponCode);var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});it('should create data for the type COUPON',function(){var payload="http://2d.is/2/".concat(couponCode,"/23729?s=27");var eventLabel="".concat(formatQrCode," - coupon - ").concat(couponCode);var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});it('should create data for the type CATEGORY',function(){var payload="http://2d.is/e/30186/".concat(categoryId,"?s=28");var eventLabel="".concat(formatQrCode," - category - ").concat(categoryId);var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});it('should create data for the type SEARCH',function(){var payload="http://2d.is/b/30186/".concat(searchPhrase,"?s=29");var eventLabel="".concat(formatQrCode," - search - ").concat(searchPhrase);var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});it('should create data for the type PAGE',function(){var payload="http://2d.is/1/30186/".concat(pageId,"?s=31");var eventLabel="".concat(formatQrCode," - page - ").concat(pageId);var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});it('should create data for an invalid payload',function(){var payload='http://www.google.com';var eventLabel="".concat(formatQrCode);var result=createScannerEventData(_extends({},defaultParams,{payload:payload}));expect(result).toEqual(_extends({},defaultResult,{eventLabel:eventLabel}));});});});describe('Barcodes',function(){it('should create data',function(){var format='EAN_13';var payload='123456789';var result=createScannerEventData({event:defaultEvent,format:format,payload:payload});expect(result).toEqual({eventAction:defaultEvent,eventLabel:"".concat(format," - ").concat(payload)});});});describe('createScannerUtmData',function(){var referer='/';describe('default Utms',function(){it('should create default utm data for barcode',function(){var result=buildScannerUtmUrl({scannerRoute:{location:'/scanner'},format:'EAN_13',payload:'123456789',referer:referer});expect(result).toEqual('/scanner?utm_source=shopgate&utm_medium=barcode_scanner&utm_campaign=30177BarcodeScan&utm_term=123456789&utm_content=%2F');});it('should create default utm data for cms page qrcode',function(){var result=buildScannerUtmUrl({scannerRoute:{location:'/scanner'},format:'QR_CODE',payload:'http://2d.is/1/30186/cmsPage?s=31',referer:referer});expect(result).toEqual('/scanner?utm_source=shopgate&utm_medium=qrcode_scanner&utm_campaign=30177QRScan&utm_content=%2F');});it('should create search utm data for search term qrcode',function(){var result=buildScannerUtmUrl({scannerRoute:{location:'/scanner'},format:'QR_CODE',payload:'http://2d.is/b/30186/searchPhrase?s=29',referer:referer});expect(result).toEqual('/scanner?utm_source=shopgate&utm_medium=qrcode_scanner&utm_campaign=30177QRScan&utm_term=searchPhrase&utm_content=%2F');});it('should handle custom urls with utm params',function(){var result=buildScannerUtmUrl({scannerRoute:{location:'/scanner'},format:'QR_CODE',payload:'http://custom.url/foo/bar?utm_content=some_content',referer:referer});expect(result).toEqual('/scanner?utm_source=shopgate&utm_medium=qrcode_scanner&utm_campaign=30177QRScan&utm_content=some_content');});});describe('custom Utms',function(){var location='/scanner?utm_medium=MED1&utm_campaign=CMP1';it('should create custom utm data for barcode',function(){var result=buildScannerUtmUrl({scannerRoute:{location:location},format:'EAN_13',payload:'123456789',referer:referer});expect(result).toEqual("".concat(location,"&utm_source=shopgate&utm_term=123456789&utm_content=%2F"));});it('should create custom utm data for cms page qrcode',function(){var result=buildScannerUtmUrl({scannerRoute:{location:location},format:'QR_CODE',payload:'http://2d.is/1/30186/cmsPage?s=31',referer:referer});expect(result).toEqual("".concat(location,"&utm_source=shopgate&utm_content=%2F"));});it('should create custom utm data for search term qrcode',function(){var result=buildScannerUtmUrl({scannerRoute:{location:location},format:'QR_CODE',payload:'http://2d.is/b/30186/searchPhrase?s=29',referer:referer});expect(result).toEqual("".concat(location,"&utm_source=shopgate&utm_term=searchPhrase&utm_content=%2F"));});});});describe('createCategoryData',function(){it('should return null when no category was passed',function(){expect(createCategoryData()).toBeNull();});it('should return tracking data',function(){var category={id:'1337',name:'Category Name',path:'Segment 1=>Segment 2'};expect(createCategoryData(category)).toEqual({uid:category.id,name:category.name,path:category.path});});});describe('createRootCategoryData',function(){it('should return null when no category was passed',function(){expect(createRootCategoryData()).toBeNull();});it('should return tracking data',function(){var categoryName='Root';i18n.text.mockReturnValueOnce(categoryName);var rootCategories=[{},{}];expect(createRootCategoryData(rootCategories)).toEqual({uid:null,name:categoryName,path:null});});});describe('createPageviewData()',function(){it('should return the expected object when the input is an empty object',function(){expect(createPageviewData({})).toEqual({page:null,cart:null,favouriteList:{products:null},search:null,category:null,product:null});});it('should return the expected object when the input contains data',function(){var mockData={some:'value'};var result=createPageviewData({page:mockData,category:mockData,product:mockData,search:mockData,cart:mockData});expect(result).toEqual({page:_extends({},mockData,{title:''}),favouriteList:{products:null},category:mockData,product:mockData,search:mockData,cart:mockData});});it('should use the title from the pageConfig as page title',function(){var mockData={page:{some:'value'},pageConfig:{title:'Page Title'}};var result=createPageviewData(mockData);expect(result).toEqual({page:_extends({},mockData.page,{title:mockData.pageConfig.title}),favouriteList:{products:null},cart:null,search:null,category:null,product:null});});it('should use a category name as page title',function(){var mockData={page:{some:'value'},category:{name:'Category Name'}};var result=createPageviewData(mockData);expect(result).toEqual({page:_extends({},mockData.page,{title:mockData.category.name}),favouriteList:{products:null},cart:null,search:null,category:mockData.category,product:null});});it('should use a product name as page title',function(){var mockData={page:{some:'value'},product:{name:'Category Name'}};var result=createPageviewData(mockData);expect(result).toEqual({page:_extends({},mockData.page,{title:mockData.product.name}),favouriteList:{products:null},cart:null,search:null,category:null,product:mockData.product});});});});/* eslint-enable extra-rules/no-single-line-objects */
|
package/selectors/cart.spec.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{getSubTotal,getCartProducts,getDiscountsAmount}from'@shopgate/pwa-common-commerce/cart/selectors/index';import getCart from"./cart";jest.mock('@shopgate/pwa-common-commerce/cart/selectors/index',function(){return{getSubTotal:jest.fn(),getCurrency:jest.fn().mockReturnValue('EUR'),getCartProducts:jest.fn(),getDiscountsAmount:jest.fn()};});describe('Tracking selector / cart',function(){it('should return empty cart',function(){getSubTotal.mockReturnValueOnce(0);getCartProducts.mockReturnValueOnce([]);getDiscountsAmount.mockReturnValueOnce(0);expect(getCart({})).toEqual({amount:{gross:'0.00',net:'0.00',currency:'EUR'},products:[],productsCount:0});});it('should return cart',function(){getSubTotal.mockReturnValueOnce('100.00');// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
2
|
-
getCartProducts.mockReturnValueOnce([{quantity:1,product:{id:'_ID_',name:'_NAME_',price:{unit:100}}}]);getDiscountsAmount.mockReturnValueOnce(5);expect(getCart({})).toEqual({amount:{gross:'95.00',net:'95.00',currency:'EUR'},products:[{uid:'_ID_',name:'_NAME_',amount:{gross:'100.00'},quantity:1}],productsCount:1});});});
|
package/selectors/user.spec.js
DELETED
|
@@ -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);}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{DEFAULT_LOGIN_STRATEGY,isUserLoggedIn,getUserData,makeGetLoginStrategy}from'@shopgate/engage/user';import{makeGetUser}from"./user";var mockDefaultStrategy='default';var mockUserData={id:'abc123',firstName:'John',lastName:'Doe',isFetching:false,loginType:'userAccount'};var isFetching=mockUserData.isFetching,loginType=mockUserData.loginType,mockTrackableData=_objectWithoutProperties(mockUserData,["isFetching","loginType"]);var mockLoginStrategy=DEFAULT_LOGIN_STRATEGY;jest.mock('@shopgate/engage/user',function(){return{DEFAULT_LOGIN_STRATEGY:mockDefaultStrategy,isUserLoggedIn:jest.fn(),getUserData:jest.fn(),makeGetLoginStrategy:jest.fn()};});describe('User selectors',function(){var getLoginStrategy=jest.fn();beforeEach(function(){jest.clearAllMocks();isUserLoggedIn.mockReturnValue(true);getUserData.mockReturnValue(mockUserData);makeGetLoginStrategy.mockReturnValue(getLoginStrategy);getLoginStrategy.mockReturnValue(mockLoginStrategy);});describe('makeGetUser()',function(){var getUser;beforeEach(function(){getUser=makeGetUser();});it('should return different selector instances',function(){expect(getUser).not.toBe(makeGetUser());});it('should return NULL when the user is not logged in',function(){isUserLoggedIn.mockReturnValueOnce(false);expect(getUser({})).toBeNull();});it('should return NULL when no user data is available',function(){getUserData.mockReturnValueOnce(null);expect(getUser({})).toBeNull();});it('should return NULL when the user data does not contain trackable properties',function(){getUserData.mockReturnValueOnce({isFetching:false,loginType:'userGuest'});expect(getUser({})).toBeNull();});it('should return the expected data when a special login strategy was used',function(){getLoginStrategy.mockReturnValueOnce('special');expect(getUser({})).toEqual(_extends({},mockTrackableData,{type:'special'}));});it('should return the expected data when the login type is userGuest',function(){getUserData.mockReturnValueOnce(_extends({},mockUserData,{loginType:'userGuest'}));expect(getUser({})).toEqual(_extends({},mockTrackableData,{type:'guest'}));});it('should return the expected data when the login type is userAccount',function(){getUserData.mockReturnValueOnce(_extends({},mockUserData,{loginType:'userAccount'}));expect(getUser({})).toEqual(_extends({},mockTrackableData,{type:'standard'}));});it('should return the expected data when an unknown login type is set',function(){getUserData.mockReturnValueOnce(_extends({},mockUserData,{loginType:'unknown'}));expect(getUser({})).toEqual(_extends({},mockTrackableData,{type:null}));});});});
|
package/streams/category.spec.js
DELETED
|
@@ -1,13 +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{combineReducers}from'redux';import{createMockStore}from'@shopgate/pwa-common/store';import{generateResultHash}from'@shopgate/pwa-common/helpers/redux';import{bin2hex}from'@shopgate/pwa-common/helpers/data';import category from'@shopgate/pwa-common-commerce/category/reducers';import product from'@shopgate/pwa-common-commerce/product/reducers';import{routeDidEnter}from'@shopgate/pwa-common/action-creators/router';import receiveRootCategories from'@shopgate/pwa-common-commerce/category/action-creators/receiveRootCategories';import requestProducts from'@shopgate/pwa-common-commerce/product/action-creators/requestProducts';import receiveProducts from'@shopgate/pwa-common-commerce/product/action-creators/receiveProducts';import{ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{pwaDidAppear}from'@shopgate/pwa-common/action-creators';import{categoryIsReady$}from"./category";var mockedRoutePattern;var mockedCategoryId;jest.mock('@shopgate/pwa-common/selectors/router',function(){return{getCurrentRoute:function getCurrentRoute(){return{pattern:mockedRoutePattern,params:_extends({},mockedCategoryId&&{categoryId:mockedCategoryId}),state:{}};},getCurrentPathname:function getCurrentPathname(){return{};},getCurrentQuery:function getCurrentQuery(){return{};},getRouterStack:function getRouterStack(){return{};},getCurrentState:function getCurrentState(){return{};},getCurrentParams:function getCurrentParams(){return{};}};});/**
|
|
2
|
-
* A wrapper for the route did enter action creator. Beside returning the action object of the
|
|
3
|
-
* original action creator, it also updates the pattern of the mocked current route.
|
|
4
|
-
* @param {string} pattern The route pattern.
|
|
5
|
-
* @param {string} categoryId A category id.
|
|
6
|
-
* @return {Object} The dispatched action object.
|
|
7
|
-
*/var routeDidEnterWrapped=function routeDidEnterWrapped(pattern,categoryId){mockedRoutePattern=pattern;// Category ids are encrypted within the route states.
|
|
8
|
-
mockedCategoryId=bin2hex(categoryId);return routeDidEnter({pattern:pattern,params:_extends({},mockedCategoryId&&{categoryId:mockedCategoryId})});};describe('Category streams',function(){var categoryIsReadySubscriber;var dispatch;beforeEach(function(){jest.clearAllMocks();mockedRoutePattern='';mockedCategoryId=null;var _createMockStore=createMockStore(combineReducers({category:category,product:product}));dispatch=_createMockStore.dispatch;categoryIsReadySubscriber=jest.fn();categoryIsReady$.subscribe(categoryIsReadySubscriber);});describe('root category route',function(){it('should emit when the root category route is active and category data is available',function(){dispatch(receiveRootCategories([{id:'one'}]));dispatch(routeDidEnterWrapped(ROOT_CATEGORY_PATTERN));expect(categoryIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should emit after category data came in when the root category route is active',function(){dispatch(routeDidEnterWrapped(ROOT_CATEGORY_PATTERN));expect(categoryIsReadySubscriber).not.toHaveBeenCalled();dispatch(receiveRootCategories([{id:'one'}]));expect(categoryIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when category data is incoming but no category route is not active',function(){dispatch(routeDidEnterWrapped('/some/pattern'));dispatch(receiveRootCategories([{id:'one'}]));expect(categoryIsReadySubscriber).not.toHaveBeenCalled();});});describe('regular category routes',function(){/**
|
|
9
|
-
* Dispatches the receiveProducts action with passed params. Since the state need to be
|
|
10
|
-
* initialized with a fetching entry, it also dispatches the requestProducts action.
|
|
11
|
-
* @param {Array} products A list of products.
|
|
12
|
-
* @param {string} categoryId A category id.
|
|
13
|
-
*/var dispatchReceiveProducts=function dispatchReceiveProducts(products,categoryId){var hash=generateResultHash({categoryId:categoryId});dispatch(requestProducts({hash:hash}));dispatch(receiveProducts({hash:hash,products:products,totalResultCount:products.length}));};it('should emit when a category route is active and category date is available',function(){var categoryId='abc123';dispatchReceiveProducts([{id:'one'}],categoryId);dispatch(routeDidEnterWrapped(CATEGORY_PATTERN,categoryId));expect(categoryIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should emit after category data came in when the root category route is active',function(){var categoryId='abc123';dispatch(routeDidEnterWrapped(CATEGORY_PATTERN,categoryId));expect(categoryIsReadySubscriber).not.toHaveBeenCalled();dispatchReceiveProducts([{id:'one'}],categoryId);expect(categoryIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should only emit for the first chunk of products',function(){var categoryId='abc123';dispatch(routeDidEnterWrapped(CATEGORY_PATTERN,categoryId));dispatchReceiveProducts([{id:'one'}],categoryId);dispatchReceiveProducts([{id:'two'}],categoryId);expect(categoryIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when category data is incoming but no category route is not active',function(){dispatch(routeDidEnterWrapped('/some/pattern'));dispatchReceiveProducts([{id:'one'}],'someid');expect(categoryIsReadySubscriber).not.toHaveBeenCalled();});});describe('navigating back from legacy pages',function(){it('should emit when a root category reappeared from a legacy webview',function(){mockedRoutePattern=ROOT_CATEGORY_PATTERN;dispatch(pwaDidAppear());expect(categoryIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should emit when a category reappeared from a legacy webview',function(){mockedRoutePattern=CATEGORY_PATTERN;dispatch(pwaDidAppear());expect(categoryIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when pwaDidAppear is dispatched and no category path is active',function(){mockedRoutePattern='/some/pattern';dispatch(pwaDidAppear());expect(categoryIsReadySubscriber).not.toHaveBeenCalled();});});});/* eslint-enable extra-rules/no-single-line-objects */
|
package/streams/checkout.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{combineReducers}from'redux';import{createMockStore}from'@shopgate/pwa-common/store';import user from'@shopgate/pwa-common/reducers/user';import{CHECKOUT_PATH}from'@shopgate/pwa-common/constants/RoutePaths';import{successLogin}from'@shopgate/pwa-common/action-creators/user';import{historyPush,historyReplace,historyPop}from'@shopgate/pwa-common/actions/router';import{checkoutDidEnter$}from"./checkout";describe('Checkout streams',function(){var store;var dispatch;beforeEach(function(){store=createMockStore(combineReducers({user:user}));var _store=store;dispatch=_store.dispatch;});describe('checkoutDidEnter$',function(){var checkoutDidEnterSubscriber;beforeEach(function(){checkoutDidEnterSubscriber=jest.fn();checkoutDidEnter$.subscribe(checkoutDidEnterSubscriber);});it('should not emit when a route is pushed which is not the checkout route',function(){dispatch(historyPush({pathname:'/someroute'}));expect(checkoutDidEnterSubscriber).not.toHaveBeenCalled();});it('should not emit when the checkout route is pushed, but the user is not logged in',function(){dispatch(historyPush({pathname:CHECKOUT_PATH}));expect(checkoutDidEnterSubscriber).not.toHaveBeenCalled();});it('should not emit when the checkout route is popped',function(){dispatch(historyPop({pathname:CHECKOUT_PATH}));expect(checkoutDidEnterSubscriber).not.toHaveBeenCalled();});it('should emit when the checkout route is pushed for a logged in user',function(){dispatch(successLogin());dispatch(historyPush({pathname:CHECKOUT_PATH}));expect(checkoutDidEnterSubscriber).toHaveBeenCalledTimes(1);});it('should emit when the checkout route is replaced for a logged in user',function(){dispatch(successLogin());dispatch(historyReplace({pathname:CHECKOUT_PATH}));expect(checkoutDidEnterSubscriber).toHaveBeenCalledTimes(1);});});});
|
package/streams/page.spec.js
DELETED
|
@@ -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{mainSubject}from'@shopgate/pwa-common/store/middelwares/streams';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{ROUTE_DID_ENTER,PWA_DID_APPEAR,RECEIVE_PAGE_CONFIG}from'@shopgate/pwa-common/constants/ActionTypes';import{PAGE_PATTERN,getPageConfigById}from'@shopgate/engage/page';import{pageIsReady$}from"./page";jest.mock('@shopgate/engage/core',function(){var _require$requireActua=require.requireActual('@shopgate/engage/core'),main$=_require$requireActua.main$,routeDidEnter$=_require$requireActua.routeDidEnter$,pwaDidAppear$=_require$requireActua.pwaDidAppear$;return{main$:main$,routeDidEnter$:routeDidEnter$,pwaDidAppear$:pwaDidAppear$};});jest.mock('@shopgate/engage/page',function(){var _require$requireActua2=require.requireActual('@shopgate/engage/page'),PAGE_PATTERN_ORIGINAL=_require$requireActua2.PAGE_PATTERN;return{PAGE_PATTERN:PAGE_PATTERN_ORIGINAL,getPageConfigById:jest.fn()};});jest.mock('@shopgate/pwa-common/selectors/router',function(){var actual=require.requireActual('@shopgate/pwa-common/selectors/router');return _extends({},actual,{getCurrentRoute:jest.fn()});});var pageConfig={isFetching:false,name:'Some Page Name'};var pageRoute={pattern:PAGE_PATTERN};var pageId='page-id';describe('Page streams',function(){var subscriber;var getState=jest.fn().mockReturnValue({});beforeAll(function(){getPageConfigById.mockReturnValue(pageConfig);getCurrentRoute.mockReturnValue(pageRoute);});beforeEach(function(){jest.clearAllMocks();subscriber=jest.fn();});describe('pageIsReady$',function(){var subscription;afterEach(function(){subscription.unsubscribe();});describe('page route',function(){var routeDidEnterPayload={action:{type:ROUTE_DID_ENTER,route:{pattern:PAGE_PATTERN,params:{pageId:pageId}}},getState:getState};it('should emit when a page is already available within the store',function(){subscription=pageIsReady$.subscribe(subscriber);mainSubject.next(routeDidEnterPayload);expect(subscriber).toHaveBeenCalledTimes(1);expect(subscriber).toHaveBeenCalledWith(routeDidEnterPayload);expect(getPageConfigById).toHaveBeenCalledTimes(1);expect(getPageConfigById).toHaveBeenCalledWith({},{pageId:pageId});});it('should not emit when a page is already available within the store, but it is fetching',function(){getPageConfigById.mockReturnValueOnce(_extends({},pageConfig,{isFetching:true}));subscription=pageIsReady$.subscribe(subscriber);mainSubject.next(routeDidEnterPayload);expect(subscriber).not.toHaveBeenCalled();expect(getPageConfigById).toHaveBeenCalledTimes(1);expect(getPageConfigById).toHaveBeenCalledWith({},{pageId:pageId});});it('should emit after the page config comes available',function(){getPageConfigById.mockReturnValueOnce(null);subscription=pageIsReady$.subscribe(subscriber);mainSubject.next(routeDidEnterPayload);expect(subscriber).not.toHaveBeenCalled();expect(getPageConfigById).toHaveBeenCalledTimes(1);expect(getPageConfigById).toHaveBeenCalledWith({},{pageId:pageId});mainSubject.next({action:{type:RECEIVE_PAGE_CONFIG}});expect(subscriber).toHaveBeenCalledTimes(1);expect(subscriber).toHaveBeenCalledWith(routeDidEnterPayload);expect(getPageConfigById).toHaveBeenCalledTimes(1);});});describe('navigating back from legacy pages',function(){it('should emit when pwaDidAppear is dispatched and a page route is active',function(){subscription=pageIsReady$.subscribe(subscriber);mainSubject.next({action:{type:PWA_DID_APPEAR},getState:getState});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not emit when pwaDidAppear is dispatched and no page route is active',function(){getCurrentRoute.mockReturnValueOnce({pattern:'/some/:pattern'});subscription=pageIsReady$.subscribe(subscriber);mainSubject.next({action:{type:PWA_DID_APPEAR},getState:getState});expect(subscriber).not.toHaveBeenCalled();});});});});
|
package/streams/pages.spec.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{combineReducers}from'redux';import{ACTION_REPLACE}from'@virtuous/conductor';import{createMockStore}from'@shopgate/pwa-common/store';import user from'@shopgate/pwa-common/reducers/user';import{routeDidEnter,navigate}from'@shopgate/pwa-common/action-creators/router';import{appWillStart}from'@shopgate/pwa-common/action-creators/app';import{CHECKOUT_PATH}from'@shopgate/pwa-common/constants/RoutePaths';import{pwaDidAppear,pwaDidDisappear}from'@shopgate/pwa-common/action-creators';import{blacklistedPatterns,pagesAreReady$}from"./pages";var mockedPattern;jest.mock('@shopgate/pwa-common/selectors/router',function(){return{getCurrentRoute:function getCurrentRoute(){return{pattern:mockedPattern};}};});/**
|
|
2
|
-
* A wrapper for the route did enter action creator. Beside returning the action object of the
|
|
3
|
-
* original action creator, it also updates the pattern of the mocked current route.
|
|
4
|
-
* @param {string} pattern The route pattern.
|
|
5
|
-
* @return {Object} The dispatched action object.
|
|
6
|
-
*/var routeDidEnterWrapped=function routeDidEnterWrapped(pattern){mockedPattern=pattern;return routeDidEnter({pattern:pattern});};describe('Page streams',function(){var pagesAreReadySubscriber;var dispatch;beforeEach(function(){jest.clearAllMocks();mockedPattern='';var _createMockStore=createMockStore(combineReducers({user:user}));dispatch=_createMockStore.dispatch;pagesAreReadySubscriber=jest.fn();pagesAreReady$.subscribe(pagesAreReadySubscriber);});describe('pagesAreReady$',function(){beforeEach(function(){// Simulate app is started
|
|
7
|
-
dispatch(appWillStart('/'));});it('should emit when a route not blacklisted',function(){dispatch(routeDidEnterWrapped('/somepath'));expect(pagesAreReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when a blacklisted route is active',function(){dispatch(routeDidEnterWrapped(blacklistedPatterns[0]));expect(pagesAreReadySubscriber).not.toHaveBeenCalled();});it('should not emit when a route is active, but the PWA is not visible',function(){// Simulate pwa is disappear
|
|
8
|
-
dispatch(pwaDidDisappear());dispatch(routeDidEnterWrapped('/somepath'));expect(pagesAreReadySubscriber).not.toHaveBeenCalled();// Simulate pwa is appeared again
|
|
9
|
-
dispatch(pwaDidAppear());expect(pagesAreReadySubscriber).toHaveBeenCalledTimes(1);});});describe('coming back from legacy pages',function(){beforeEach(function(){// Simulate app is started
|
|
10
|
-
dispatch(appWillStart('/'));});it('should emit when PWA is reappear and a not blacklisted route is active',function(){dispatch(routeDidEnterWrapped('/somepath'));dispatch(pwaDidDisappear());dispatch(pwaDidAppear());expect(pagesAreReadySubscriber).toHaveBeenCalledTimes(2);});it('should not emit when pwaDidAppear is dispatched and a blacklisted is active',function(){dispatch(routeDidEnterWrapped(blacklistedPatterns[0]));dispatch(pwaDidDisappear());dispatch(pwaDidAppear());expect(pagesAreReadySubscriber).not.toHaveBeenCalled();});});describe('go to checkout',function(){beforeEach(function(){// Simulate app is started
|
|
11
|
-
dispatch(appWillStart('/'));});it('should not emit events when user goes to checkout',function(){dispatch(routeDidEnterWrapped('/somepath'));dispatch(navigate({action:ACTION_REPLACE,pathname:CHECKOUT_PATH}));// should not track this path
|
|
12
|
-
dispatch(routeDidEnterWrapped('/somepath2'));expect(pagesAreReadySubscriber).toHaveBeenCalledTimes(1);});});});
|
package/streams/product.spec.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{combineReducers}from'redux';import{createMockStore}from'@shopgate/pwa-common/store';import{bin2hex as mockBin2Hex}from'@shopgate/pwa-common/helpers/data';import{routeWillEnter}from'@shopgate/pwa-common/action-creators/router';import{HISTORY_PUSH_ACTION}from'@shopgate/pwa-common/constants/ActionTypes';import product from'@shopgate/pwa-common-commerce/product/reducers';import requestProducts from'@shopgate/pwa-common-commerce/product/action-creators/requestProducts';import receiveProducts from'@shopgate/pwa-common-commerce/product/action-creators/receiveProducts';import receiveProduct from'@shopgate/pwa-common-commerce/product/action-creators/receiveProduct';import{ITEM_PATTERN,ITEM_REVIEWS_PATTERN}from'@shopgate/pwa-common-commerce/product/constants';import{pwaDidAppear}from'@shopgate/pwa-common/action-creators';import{productsReceived$,productRouteReappeared$,productWillEnter$,productIsReady$}from"./product";var mockedRoutePattern;var mockedRouteProductId;jest.mock('@shopgate/pwa-common/selectors/router',function(){return{getCurrentRoute:function getCurrentRoute(){return{pattern:mockedRoutePattern,params:{productId:mockedRouteProductId},state:{productId:mockedRouteProductId}};},getCurrentPathname:function getCurrentPathname(){return{};},getCurrentQuery:function getCurrentQuery(){return{};},getRouterStack:function getRouterStack(){return{};},getCurrentState:function getCurrentState(){return{};}};});/**
|
|
2
|
-
* Wrapper for the routeWillEnter action. It also sets up the mocked current route.
|
|
3
|
-
* @param {string} pattern A route pattern.
|
|
4
|
-
* @param {string} historyAction A history action.
|
|
5
|
-
* @param {string} productId A product id.
|
|
6
|
-
* @return {Object}
|
|
7
|
-
*/var wrappedRouteWillEnter=function wrappedRouteWillEnter(pattern,historyAction){var productId=arguments.length>2&&arguments[2]!==undefined?arguments[2]:'';mockedRoutePattern=pattern;mockedRouteProductId=productId;return routeWillEnter({pattern:pattern},historyAction);};describe('Product streams',function(){var store;var dispatch;beforeEach(function(){store=createMockStore(combineReducers({product:product}));var _store=store;dispatch=_store.dispatch;mockedRoutePattern=ITEM_PATTERN;mockedRouteProductId='';});describe('productsReceived$',function(){var productsReceivedSubscriber;beforeEach(function(){productsReceivedSubscriber=jest.fn();productsReceived$.subscribe(productsReceivedSubscriber);});it('should emit when products where received',function(){var hash='hash';dispatch(requestProducts({hash:hash}));dispatch(receiveProducts({products:[],hash:hash}));expect(productsReceivedSubscriber).toHaveBeenCalledTimes(1);});it('should not emit for other actions',function(){dispatch({type:'someaction'});expect(productsReceivedSubscriber).not.toHaveBeenCalled();});});describe('productRouteReappeared$',function(){var productRouteReappearedSubscriber;beforeEach(function(){productRouteReappearedSubscriber=jest.fn();productRouteReappeared$.subscribe(productRouteReappearedSubscriber);});it('should emit when the pwaDidAppear action was dispatched on the item route',function(){dispatch(pwaDidAppear());expect(productRouteReappearedSubscriber).toHaveBeenCalledTimes(1);});it('should not emit when the pwaDidAppear action was dispatched on the item route',function(){mockedRoutePattern=ITEM_REVIEWS_PATTERN;dispatch(pwaDidAppear());expect(productRouteReappearedSubscriber).not.toHaveBeenCalled();});});describe('productWillEnter$',function(){var productWillEnterSubscriber;beforeEach(function(){productWillEnterSubscriber=jest.fn();productWillEnter$.subscribe(productWillEnterSubscriber);});it('should emit when an item page was pushed',function(){dispatch(wrappedRouteWillEnter(ITEM_PATTERN,HISTORY_PUSH_ACTION));expect(productWillEnterSubscriber).toHaveBeenCalledTimes(1);});it('should not emit when an page was pushed which is not the item page',function(){dispatch(wrappedRouteWillEnter(ITEM_REVIEWS_PATTERN,HISTORY_PUSH_ACTION));expect(productWillEnterSubscriber).not.toHaveBeenCalled();});});describe('productIsReady$',function(){var productIsReadySubscriber;beforeEach(function(){productIsReadySubscriber=jest.fn();productIsReady$.subscribe(productIsReadySubscriber);});it('should emit when a product is ready to be tracked',function(){var productId=mockBin2Hex('abc123');dispatch(wrappedRouteWillEnter(ITEM_PATTERN,HISTORY_PUSH_ACTION,productId));dispatch(receiveProduct(productId,{id:productId}));expect(productIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when a product route was entered but the product data was not received yet',function(){dispatch(wrappedRouteWillEnter(ITEM_PATTERN,HISTORY_PUSH_ACTION));expect(productIsReadySubscriber).not.toHaveBeenCalled();});it('should only emit when the underlying streams emit in the correct order',function(){var productId='abc123';dispatch(wrappedRouteWillEnter(ITEM_PATTERN,HISTORY_PUSH_ACTION,productId));dispatch(receiveProduct(productId,{id:productId}));expect(productIsReadySubscriber).toHaveBeenCalledTimes(1);dispatch(receiveProduct(productId,{id:productId}));dispatch(wrappedRouteWillEnter(ITEM_PATTERN,HISTORY_PUSH_ACTION,productId));expect(productIsReadySubscriber).toHaveBeenCalledTimes(1);dispatch(receiveProduct(productId,{id:productId}));expect(productIsReadySubscriber).toHaveBeenCalledTimes(2);});it('should emit when the PWA webview reappeared with an active product page',function(){dispatch(wrappedRouteWillEnter(ITEM_PATTERN,HISTORY_PUSH_ACTION));dispatch(pwaDidAppear());expect(productIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when the PWA webview reappeared but the product page is not active',function(){dispatch(wrappedRouteWillEnter(ITEM_REVIEWS_PATTERN,HISTORY_PUSH_ACTION));dispatch(pwaDidAppear());expect(productIsReadySubscriber).not.toHaveBeenCalled();});});});
|
package/streams/scanner.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{mainSubject}from'@shopgate/pwa-common/store/middelwares/streams';import{SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE}from'@shopgate/pwa-core/constants/Scanner';import{ROUTE_DID_ENTER}from'@shopgate/pwa-common/constants/ActionTypes';import{SUCCESS_HANDLE_SCANNER,ERROR_HANDLE_SCANNER,SCANNER_PATH}from'@shopgate/pwa-common-commerce/scanner/constants';import{scanActivated$,scanSuccess$,scanFail$}from"./scanner";describe('Scanner streams',function(){var subscriber;beforeEach(function(){subscriber=jest.fn();});describe('scanActivated$',function(){it('should call the subscriber when the scanner page was opened and valid query parameters are set',function(){scanActivated$.subscribe(subscriber);mainSubject.next({action:{type:ROUTE_DID_ENTER,route:{pathname:SCANNER_PATH,query:{type:SCANNER_TYPE_BARCODE,scope:SCANNER_SCOPE_DEFAULT}}}});expect(subscriber).toHaveBeenCalledTimes(1);});it('should call the subscriber when the scanner page was opened and no query parameters are set',function(){scanActivated$.subscribe(subscriber);mainSubject.next({action:{type:ROUTE_DID_ENTER,route:{pathname:SCANNER_PATH,query:{}}}});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call the subscriber when the scanner page was opened but invalid query parameters are set',function(){scanActivated$.subscribe(subscriber);mainSubject.next({action:{type:ROUTE_DID_ENTER,route:{pathname:SCANNER_PATH,query:{type:'someType',scope:'someScope'}}}});expect(subscriber).not.toHaveBeenCalled();});});describe('scanSuccess$',function(){it('should call the subscriber when the success action is dispatched with the default scope',function(){scanSuccess$.subscribe(subscriber);mainSubject.next({action:{type:SUCCESS_HANDLE_SCANNER,scope:SCANNER_SCOPE_DEFAULT}});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call the subscriber when the success action is dispatched with in unknown scope',function(){scanSuccess$.subscribe(subscriber);mainSubject.next({action:{type:SUCCESS_HANDLE_SCANNER,scope:'unknown'}});expect(subscriber).not.toHaveBeenCalled();});});describe('scanFail$',function(){it('should call the subscriber when the success action is dispatched with the default scope',function(){scanFail$.subscribe(subscriber);mainSubject.next({action:{type:ERROR_HANDLE_SCANNER,scope:SCANNER_SCOPE_DEFAULT}});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call the subscriber when the success action is dispatched with in unknown scope',function(){scanFail$.subscribe(subscriber);mainSubject.next({action:{type:ERROR_HANDLE_SCANNER,scope:'unknown'}});expect(subscriber).not.toHaveBeenCalled();});});});
|
package/streams/search.spec.js
DELETED
|
@@ -1,7 +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{combineReducers}from'redux';import{createMockStore}from'@shopgate/pwa-common/store';import product from'@shopgate/pwa-common-commerce/product/reducers';import{routeDidEnter}from'@shopgate/pwa-common/action-creators/router';import{SEARCH_PATTERN}from'@shopgate/pwa-common-commerce/search/constants';import receiveSearchResults from'@shopgate/pwa-common-commerce/search/action-creators/receiveSearchResults';import{pwaDidAppear}from'@shopgate/pwa-common/action-creators';import{searchIsReady$}from"./search";var mockedRoutePattern;var mockedSearchQuery;jest.mock('@shopgate/pwa-common/selectors/router',function(){return{getCurrentRoute:function getCurrentRoute(){return{pattern:mockedRoutePattern,query:_extends({},mockedSearchQuery&&{s:mockedSearchQuery}),state:{}};},getCurrentPathname:function getCurrentPathname(){return{};},getCurrentQuery:function getCurrentQuery(){return{};},getRouterStack:function getRouterStack(){return{};},getCurrentState:function getCurrentState(){return{};},getCurrentParams:function getCurrentParams(){return{};},getCurrentSearchQuery:function getCurrentSearchQuery(){return mockedSearchQuery;}};});/**
|
|
2
|
-
* A wrapper for the route did enter action creator. Beside returning the action object of the
|
|
3
|
-
* original action creator, it also updates the pattern of the mocked current route.
|
|
4
|
-
* @param {string} pattern The route pattern.
|
|
5
|
-
* @param {string} searchQuery A search query.
|
|
6
|
-
* @return {Object} The dispatched action object.
|
|
7
|
-
*/var routeDidEnterWrapped=function routeDidEnterWrapped(pattern,searchQuery){mockedRoutePattern=pattern;mockedSearchQuery=searchQuery;return routeDidEnter({pattern:pattern,query:_extends({},searchQuery&&{s:searchQuery})});};describe('Search streams',function(){var searchIsReadySubscriber;var dispatch;beforeEach(function(){jest.resetAllMocks();jest.clearAllMocks();mockedRoutePattern='';mockedSearchQuery=null;var _createMockStore=createMockStore(combineReducers({product:product}));dispatch=_createMockStore.dispatch;searchIsReadySubscriber=jest.fn();searchIsReady$.subscribe(searchIsReadySubscriber);});describe('searchIsReady$',function(){describe('search route',function(){var searchQuery='Search Query';it('should emit when the search route is active and search results came in',function(){dispatch(routeDidEnterWrapped(SEARCH_PATTERN,searchQuery));dispatch(receiveSearchResults());expect(searchIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when search route is active but no search results came in yet',function(){dispatch(routeDidEnterWrapped(SEARCH_PATTERN,searchQuery));expect(searchIsReadySubscriber).not.toHaveBeenCalled();});it('should not emit when search results came in but the route is not active',function(){dispatch(routeDidEnterWrapped('/some/pattern'));dispatch(receiveSearchResults());expect(searchIsReadySubscriber).not.toHaveBeenCalled();});});describe('navigating back from legacy pages',function(){it('should emit when pwaDidAppear is dispatched and a search route is active',function(){mockedRoutePattern=SEARCH_PATTERN;dispatch(pwaDidAppear());expect(searchIsReadySubscriber).toHaveBeenCalledTimes(1);});it('should not emit when pwaDidAppear is dispatched and no search route is active',function(){mockedRoutePattern='/some/pattern';dispatch(pwaDidAppear());expect(searchIsReadySubscriber).not.toHaveBeenCalled();});});});});
|
package/streams/user.spec.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{SUCCESS_LOGIN,RECEIVE_USER}from'@shopgate/pwa-common/constants/ActionTypes';import{mainSubject}from'@shopgate/pwa-common/store/middelwares/streams';import{loginSuccess$}from"./user";var mockedReceiveUser={action:{type:RECEIVE_USER,user:{id:'abc123',firstName:'John',lastName:'Doe'}}};/**
|
|
2
|
-
* Simulate dispatch of the SUCCESS_LOGIN action
|
|
3
|
-
*/var dispatchReceiveUser=function dispatchReceiveUser(){mainSubject.next(mockedReceiveUser);};/**
|
|
4
|
-
* Simulate dispatch of the SUCCESS_LOGIN action
|
|
5
|
-
*/var dispatchSuccessLogin=function dispatchSuccessLogin(){mainSubject.next({action:{type:SUCCESS_LOGIN}});};describe('User streams',function(){var subscriber;var subscription;beforeEach(function(){jest.clearAllMocks();subscriber=jest.fn();});describe('loginSuccess$',function(){beforeEach(function(){subscription=loginSuccess$.subscribe(subscriber);});afterEach(function(){subscription.unsubscribe();});it('should emit after the user logged in, and user data was received',function(){dispatchSuccessLogin();expect(subscriber).not.toHaveBeenCalled();dispatchReceiveUser();expect(subscriber).toHaveBeenCalledTimes(1);expect(subscriber).toHaveBeenCalledWith(mockedReceiveUser);});it('should only emit if both actions are dispatched in the correct order',function(){dispatchReceiveUser();expect(subscriber).not.toHaveBeenCalled();dispatchReceiveUser();expect(subscriber).not.toHaveBeenCalled();dispatchSuccessLogin();expect(subscriber).not.toHaveBeenCalled();dispatchReceiveUser();expect(subscriber).toHaveBeenCalledTimes(1);expect(subscriber).toHaveBeenCalledWith(mockedReceiveUser);dispatchReceiveUser();expect(subscriber).toHaveBeenCalledTimes(1);});});});
|
|
@@ -1,4 +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 getCart from"../selectors/cart";import*as helpers from"../helpers";import subscription from"./checkout";jest.mock('@shopgate/pwa-common/streams/app',function(){return{appDidStart$:jest.fn()};});jest.mock("../selectors/cart",function(){return function(state){return state;};});jest.mock('@shopgate/pwa-core/commands/registerEvents',function(){return jest.fn();});describe('Checkout subscriptions',function(){var subscribe=jest.fn();beforeEach(function(){jest.clearAllMocks();subscription(subscribe);});it('should call subscribe as expected',function(){expect(subscribe).toHaveBeenCalledTimes(2);});describe('checkoutDidEnter$',function(){var callback;beforeAll(function(){var _subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);var _subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);callback=_subscribe$mock$calls2[1];});it('should call the expected commands',function(){var trackSpy=jest.spyOn(helpers,'track');/**
|
|
2
|
-
* Mocked getState function.
|
|
3
|
-
* @return {Object}
|
|
4
|
-
*/var getState=function getState(){return{mocked:'state'};};callback({getState:getState});expect(trackSpy).toHaveBeenCalledTimes(1);expect(trackSpy).toHaveBeenCalledWith('initiatedCheckout',{cart:getCart(getState())},getState());});});});
|
|
@@ -1,5 +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;}/* eslint-disable extra-rules/no-single-line-objects */import core from'@shopgate/tracking-core/core/Core';import{mainSubject}from'@shopgate/pwa-common/store/middelwares/streams';import{ROUTE_DID_ENTER,ROUTE_DID_LEAVE}from'@shopgate/pwa-common/constants/ActionTypes';import{SCANNER_SCOPE_DEFAULT}from'@shopgate/pwa-core/constants/Scanner';import{SCANNER_PATH,SUCCESS_HANDLE_SCANNER}from'@shopgate/pwa-common-commerce/scanner/constants';import{scanActivated$,scanFail$,scanSuccess$}from"../streams/scanner";import*as helpers from"../helpers";import subscription from"./scanner";var createScannerEventData=helpers.createScannerEventData;var scannerEvents=core.getScannerEvents();describe('Scanner subscriptions',function(){var mockedState={};var subscribe=jest.fn();var getState=jest.fn().mockReturnValue(mockedState);var trackSpy=jest.spyOn(helpers,'track');var format='QR_CODE';var payload='some.payload';beforeEach(function(){jest.clearAllMocks();subscription(subscribe);});it('should call subscribe as expected',function(){expect(subscribe).toHaveBeenCalledTimes(4);});describe('scanActivated$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);var _subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);stream=_subscribe$mock$calls2[0];callback=_subscribe$mock$calls2[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(scanActivated$);});it('should call the track function',function(){callback({action:{format:format},getState:getState});expect(trackSpy).toHaveBeenCalledWith('qrScanner',createScannerEventData({event:scannerEvents.SCAN_ACTIVATED,userInteraction:false,format:format}),mockedState);});});describe('scanSuccess$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls3=_slicedToArray(subscribe.mock.calls,2);var _subscribe$mock$calls4=_slicedToArray(_subscribe$mock$calls3[1],2);stream=_subscribe$mock$calls4[0];callback=_subscribe$mock$calls4[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(scanSuccess$);});it('should call the track function',function(){callback({action:{format:format,payload:payload},getState:getState});expect(trackSpy).toHaveBeenCalledWith('qrScanner',createScannerEventData({event:scannerEvents.SCAN_SUCCESS,format:format,payload:payload}),mockedState);});});describe('scanFail$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls5=_slicedToArray(subscribe.mock.calls,3);var _subscribe$mock$calls6=_slicedToArray(_subscribe$mock$calls5[2],2);stream=_subscribe$mock$calls6[0];callback=_subscribe$mock$calls6[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(scanFail$);});it('should call the track function',function(){callback({action:{format:format,payload:payload},getState:getState});expect(trackSpy).toHaveBeenCalledWith('qrScanner',createScannerEventData({event:scannerEvents.SCAN_FAIL,format:format,payload:payload}),mockedState);});});describe('afterScan$ UTM params',function(){var refererAction={action:{type:ROUTE_DID_LEAVE,route:{pathname:'/',location:'/'}},getState:getState};var activatedAction={action:{type:ROUTE_DID_ENTER,route:{pathname:SCANNER_PATH,location:SCANNER_PATH}},getState:getState};var successAction={action:{type:SUCCESS_HANDLE_SCANNER,scope:SCANNER_SCOPE_DEFAULT},getState:getState};var afterScan$;var callback;beforeAll(function(){var _subscribe$mock$calls7=_slicedToArray(subscribe.mock.calls,4);var _subscribe$mock$calls8=_slicedToArray(_subscribe$mock$calls7[3],2);afterScan$=_subscribe$mock$calls8[0];callback=_subscribe$mock$calls8[1];});it('should call subscriber with both actions',function(){var subscriber=jest.fn();afterScan$.subscribe(subscriber);mainSubject.next(refererAction);// route did leave
|
|
2
|
-
mainSubject.next(activatedAction);// route did enter
|
|
3
|
-
mainSubject.next(successAction);// scan is handled
|
|
4
|
-
expect(subscriber).toBeCalledTimes(1);expect(subscriber).toBeCalledWith({activatedAction:activatedAction,refererAction:refererAction,successAction:successAction,getState:getState});});it('should call the track function',function(){// eslint-disable-next-line object-curly-newline
|
|
5
|
-
callback({activatedAction:activatedAction,refererAction:refererAction,successAction:successAction,getState:getState});expect(trackSpy).toHaveBeenCalledWith('setCampaignWithUrl',{type:'scanner',url:'/scanner?utm_source=shopgate&utm_medium=scanner&utm_campaign=30177Scanner&utm_content=%2F'},mockedState);});});});/* eslint-enable extra-rules/no-single-line-objects */
|
|
@@ -1 +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{loginDidFail$}from'@shopgate/engage/user';import*as helpers from"../helpers";import subscription from"./user";var mockedGetUser=jest.fn().mockReturnValue('getUser');jest.mock("../selectors/user",function(){return{makeGetUser:function makeGetUser(){return mockedGetUser;}};});describe('User subscriptions',function(){var subscribe=jest.fn();var getState=jest.fn().mockReturnValue('getState');var trackSpy=jest.spyOn(helpers,'track');beforeEach(function(){jest.clearAllMocks();subscription(subscribe);});it('should call subscribe as expected',function(){expect(subscribe).toHaveBeenCalledTimes(2);});describe('loginSuccess$',function(){var callback;beforeAll(function(){var _subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);var _subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);callback=_subscribe$mock$calls2[1];});it('should track the loginSuccess event',function(){callback({getState:getState});expect(trackSpy).toHaveBeenCalledTimes(1);expect(trackSpy).toHaveBeenCalledWith('loginSuccess','getUser','getState');});});describe('loginDidFail$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls3=_slicedToArray(subscribe.mock.calls,2);var _subscribe$mock$calls4=_slicedToArray(_subscribe$mock$calls3[1],2);stream=_subscribe$mock$calls4[0];callback=_subscribe$mock$calls4[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(loginDidFail$);});it('should track the loginFailed event',function(){callback({getState:getState});expect(trackSpy).toHaveBeenCalledTimes(1);expect(trackSpy).toHaveBeenCalledWith('loginFailed',undefined,'getState');});});});
|