Skip to content

Commit 9c35d2d

Browse files
committed
ACP2E-2260: Recently viewed product data not updated as per the store view
- Fix unit tests
1 parent afa8efa commit 9c35d2d

File tree

1 file changed

+29
-32
lines changed
  • dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product

1 file changed

+29
-32
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/provider.test.js

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,35 @@ define([
2222
'use strict';
2323

2424
var injector = new Squire(),
25-
customerData,
26-
productResolver,
27-
productResolverIds,
28-
storage,
29-
mocks,
3025
obj,
26+
customerDataIds,
3127
localStorageIds,
28+
timestamp,
3229
namespace = 'namespace',
33-
windowCheckoutData,
34-
timestamp;
35-
36-
beforeEach(function (done) {
37-
customerData = {};
38-
productResolverIds = [];
30+
windowCheckoutData = window.checkout,
31+
customerDataGet = function () {
32+
return {
33+
items: customerDataIds
34+
};
35+
},
36+
customerData = {
37+
get: jasmine.createSpy().and.returnValue(customerDataGet)
38+
},
39+
productResolverIds = [],
3940
productResolver = jasmine.createSpy().and.callFake(function () {
4041
return productResolverIds;
41-
});
42+
}),
4243
storage = {
4344
onStorageInit: jasmine.createSpy(),
4445
createStorage: jasmine.createSpy()
45-
};
46+
},
4647
mocks = {
4748
'Magento_Customer/js/customer-data': customerData,
4849
'Magento_Catalog/js/product/view/product-ids-resolver': productResolver,
4950
'Magento_Catalog/js/product/storage/storage-service': storage
5051
};
52+
53+
beforeEach(function (done) {
5154
injector.mock(mocks);
5255
injector.require(['Magento_Catalog/js/product/provider'], function (UiClass) {
5356
timestamp = new Date().getTime() / 1000;
@@ -75,14 +78,20 @@ define([
7578
scope_id: 1
7679
},
7780
'website-1-3': {
78-
added_at: timestamp - 120,
81+
added_at: timestamp - 180,
7982
product_id: 3,
8083
scope_id: 1
8184
}
8285
};
86+
customerDataIds = {
87+
4: {
88+
added_at: timestamp - 360,
89+
product_id: 4,
90+
scope_id: 1
91+
}
92+
};
8393
done();
8494
});
85-
windowCheckoutData = window.checkout;
8695
});
8796

8897
afterEach(function () {
@@ -116,20 +125,8 @@ define([
116125
expect(obj.idsMerger).not.toHaveBeenCalled();
117126
});
118127
it('check that initial ids, localstorage ids and ids from customer data are processed', function () {
119-
var initialIds,
120-
customerDataIds,
121-
customerDataGet;
122-
123-
initialIds = obj.ids();
124-
customerDataIds = {
125-
4: {},
126-
6: {}
127-
};
128-
customerDataGet = function () {
129-
return {
130-
items: customerDataIds
131-
};
132-
};
128+
var initialIds = obj.ids();
129+
133130
window.checkout = {
134131
baseUrl: 'http://localhost/',
135132
websiteId: 1
@@ -179,11 +176,11 @@ define([
179176
});
180177

181178
it('argument is an object and has "items" property', function () {
182-
expect(obj.prepareDataFromCustomerData({items: {1: {}, 2: {}}})).toEqual({1: {}, 2: {}});
179+
expect(obj.prepareDataFromCustomerData({items: customerDataIds})).toEqual(customerDataIds);
183180
});
184181

185182
it('argument is an object and does not have "items" property', function () {
186-
expect(obj.prepareDataFromCustomerData({1: {}, 2: {}})).toEqual({1: {}, 2: {}});
183+
expect(obj.prepareDataFromCustomerData(customerDataIds)).toEqual(customerDataIds);
187184
});
188185
});
189186

@@ -203,7 +200,7 @@ define([
203200
});
204201

205202
it('filters out expired ids', function () {
206-
obj.idsStorage.lifetime = 70;
203+
obj.idsStorage.lifetime = 100;
207204
expect(obj.filterIds(localStorageIds)).toEqual({2: localStorageIds['website-1-2']});
208205
});
209206

0 commit comments

Comments
 (0)