Skip to content

Commit

Permalink
ACP2E-2260: Recently viewed product data not updated as per the store…
Browse files Browse the repository at this point in the history
… view

- Fix unit tests
  • Loading branch information
bubasuma committed Oct 23, 2023
1 parent afa8efa commit 9c35d2d
Showing 1 changed file with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,35 @@ define([
'use strict';

var injector = new Squire(),
customerData,
productResolver,
productResolverIds,
storage,
mocks,
obj,
customerDataIds,
localStorageIds,
timestamp,
namespace = 'namespace',
windowCheckoutData,
timestamp;

beforeEach(function (done) {
customerData = {};
productResolverIds = [];
windowCheckoutData = window.checkout,
customerDataGet = function () {
return {
items: customerDataIds
};
},
customerData = {
get: jasmine.createSpy().and.returnValue(customerDataGet)
},
productResolverIds = [],
productResolver = jasmine.createSpy().and.callFake(function () {
return productResolverIds;
});
}),
storage = {
onStorageInit: jasmine.createSpy(),
createStorage: jasmine.createSpy()
};
},
mocks = {
'Magento_Customer/js/customer-data': customerData,
'Magento_Catalog/js/product/view/product-ids-resolver': productResolver,
'Magento_Catalog/js/product/storage/storage-service': storage
};

beforeEach(function (done) {
injector.mock(mocks);
injector.require(['Magento_Catalog/js/product/provider'], function (UiClass) {
timestamp = new Date().getTime() / 1000;
Expand Down Expand Up @@ -75,14 +78,20 @@ define([
scope_id: 1
},
'website-1-3': {
added_at: timestamp - 120,
added_at: timestamp - 180,
product_id: 3,
scope_id: 1
}
};
customerDataIds = {
4: {
added_at: timestamp - 360,
product_id: 4,
scope_id: 1
}
};
done();
});
windowCheckoutData = window.checkout;
});

afterEach(function () {
Expand Down Expand Up @@ -116,20 +125,8 @@ define([
expect(obj.idsMerger).not.toHaveBeenCalled();
});
it('check that initial ids, localstorage ids and ids from customer data are processed', function () {
var initialIds,
customerDataIds,
customerDataGet;

initialIds = obj.ids();
customerDataIds = {
4: {},
6: {}
};
customerDataGet = function () {
return {
items: customerDataIds
};
};
var initialIds = obj.ids();

window.checkout = {
baseUrl: 'http://localhost/',
websiteId: 1
Expand Down Expand Up @@ -179,11 +176,11 @@ define([
});

it('argument is an object and has "items" property', function () {
expect(obj.prepareDataFromCustomerData({items: {1: {}, 2: {}}})).toEqual({1: {}, 2: {}});
expect(obj.prepareDataFromCustomerData({items: customerDataIds})).toEqual(customerDataIds);
});

it('argument is an object and does not have "items" property', function () {
expect(obj.prepareDataFromCustomerData({1: {}, 2: {}})).toEqual({1: {}, 2: {}});
expect(obj.prepareDataFromCustomerData(customerDataIds)).toEqual(customerDataIds);
});
});

Expand All @@ -203,7 +200,7 @@ define([
});

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

Expand Down

0 comments on commit 9c35d2d

Please sign in to comment.