Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into Tier4-PR-10-30-2023
  • Loading branch information
thiaramus committed Nov 20, 2023
2 parents 6235bb4 + 9c35d2d commit 81e372b
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AssertSeeProductDetailsOnStorefrontRecentlyViewedWidgetActionGroup">
<annotations>
<description>Goes to the home Page Recently VIewed Product and Grab the Prdouct name and Position from it.</description>
<description>Goes to the home Page Recently Viewed Product and Grab the Product name and Position from it.</description>
</annotations>
<arguments>
<argument name="productName" type="string"/>
<argument name="productPosition" type="string"/>
</arguments>
<waitForElementVisible selector="{{StoreFrontRecentlyViewedProductSection.ProductName(productPosition)}}" stepKey="waitForProductToShowAtPosition"/>
<grabTextFrom selector="{{StoreFrontRecentlyViewedProductSection.ProductName(productPosition)}}" stepKey="grabRelatedProductPosition"/>
<assertStringContainsString stepKey="assertRelatedProductName">
<actualResult type="const">$grabRelatedProductPosition</actualResult>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,15 @@ define([
return;
}

// Filter initial ids to remove "out of scope" and "outdated" data
this.ids(
this.filterIds(this.ids())
);
this.initIdsListener();
this.idsMerger(
this.idsStorage.get(),
this.prepareDataFromCustomerData(customerData.get(this.identifiersConfig.namespace)())
);

if (!_.isEmpty(this.productStorage.data())) {
this.dataCollectionHandler(this.productStorage.data());
} else {
this.productStorage.setIds(this.data.currency, this.data.store, this.ids());
}
},

/**
Expand Down Expand Up @@ -176,7 +174,7 @@ define([

if (!_.isEmpty(data)) {
this.ids(
this.filterIds(_.extend(this.ids(), data))
this.filterIds(_.extend(utils.copy(this.ids()), data))
);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ define([
if (data.items && ids.length) {
//we can extend only items
data = data.items;
this.data(_.extend(data, currentData));
this.data(_.extend(currentData, data));
}
},

Expand Down Expand Up @@ -271,13 +271,9 @@ define([
sentDataIds = _.keys(this.request.data);
currentDataIds = _.keys(ids);

_.each(currentDataIds, function (id) {
if (_.lastIndexOf(sentDataIds, id) === -1) {
return false;
}
return _.every(currentDataIds, function (id) {
return _.lastIndexOf(sentDataIds, id) !== -1;
});

return true;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/************************************************************************
*
* Copyright 2023 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
* ************************************************************************
*/

/* eslint-disable max-nested-callbacks */
define([
'squire',
'underscore'
], function (Squire, _) {
'use strict';

var injector = new Squire(),
obj,
customerDataIds,
localStorageIds,
timestamp,
namespace = 'namespace',
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;
obj = new UiClass({
identifiersConfig: {
namespace: namespace
},
ids: {
'website-1-1': {
added_at: timestamp - 300,
product_id: 1,
scope_id: 1
}
},
data: {
store: '1',
currency: 'USD',
productCurrentScope: 'website'
}
});
localStorageIds = {
'website-1-2': {
added_at: timestamp - 60,
product_id: 2,
scope_id: 1
},
'website-1-3': {
added_at: timestamp - 180,
product_id: 3,
scope_id: 1
}
};
customerDataIds = {
4: {
added_at: timestamp - 360,
product_id: 4,
scope_id: 1
}
};
done();
});
});

afterEach(function () {
try {
injector.clean();
injector.remove();
} catch (e) {
}
window.localStorage.clear();
window.checkout = windowCheckoutData;
});

describe('Magento_Catalog/js/product/provider', function () {
describe('"_resolveDataByIds" method', function () {
beforeEach(function () {
obj.initIdsListener = jasmine.createSpy();
obj.idsMerger = jasmine.createSpy();
obj.idsHandler = jasmine.createSpy();
obj.filterIds = jasmine.createSpy().and.returnValue({});
});
it('check "window.checkout" is required', function () {
window.checkout = undefined;
obj.ids = jasmine.createSpy();

obj._resolveDataByIds();

expect(obj.ids).not.toHaveBeenCalled();
expect(obj.filterIds).not.toHaveBeenCalled();
expect(obj.idsHandler).not.toHaveBeenCalled();
expect(obj.initIdsListener).not.toHaveBeenCalled();
expect(obj.idsMerger).not.toHaveBeenCalled();
});
it('check that initial ids, localstorage ids and ids from customer data are processed', function () {
var initialIds = obj.ids();

window.checkout = {
baseUrl: 'http://localhost/',
websiteId: 1
};
obj.idsStorage = {
get: jasmine.createSpy().and.returnValue(localStorageIds),
lifetime: 1000
};
obj.prepareDataFromCustomerData = jasmine.createSpy().and.returnValue(customerDataIds);
customerData.get = jasmine.createSpy().and.returnValue(customerDataGet);

obj._resolveDataByIds();

expect(obj.filterIds).toHaveBeenCalledOnceWith(initialIds);
expect(obj.idsHandler).toHaveBeenCalledOnceWith({});
expect(obj.initIdsListener).toHaveBeenCalled();
expect(customerData.get).toHaveBeenCalledOnceWith(namespace);
expect(obj.prepareDataFromCustomerData).toHaveBeenCalledOnceWith({items: customerDataIds});
expect(obj.idsMerger).toHaveBeenCalledOnceWith(localStorageIds, customerDataIds);
});
});
describe('"idsMerger" method', function () {
beforeEach(function () {
obj.idsHandler = jasmine.createSpy();
obj.filterIds = jasmine.createSpy().and.returnValue({});
});
it('check merge empty', function () {
obj.idsMerger({}, {});

expect(obj.filterIds).not.toHaveBeenCalled();
expect(obj.idsHandler).not.toHaveBeenCalled();
});

it('check merge not empty', function () {
var initialIds = obj.ids();

obj.idsMerger(localStorageIds, {});

expect(obj.filterIds).toHaveBeenCalledOnceWith(_.extend({}, initialIds, localStorageIds));
expect(obj.idsHandler).toHaveBeenCalledOnceWith({});
});
});

describe('"prepareDataFromCustomerData" method', function () {
it('argument is empty', function () {
expect(obj.prepareDataFromCustomerData({})).toEqual({});
});

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

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

describe('"filterIds" method', function () {
beforeEach(function () {
window.checkout = {
websiteId: 1
};
obj.idsStorage = {
lifetime: 1000
};
});

it('filters out "out of scope" ids', function () {
window.checkout.websiteId = 2;
expect(obj.filterIds(localStorageIds)).toEqual({});
});

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

it('filters out current product id', function () {
productResolverIds.push(2);
expect(obj.filterIds(localStorageIds)).toEqual({3: localStorageIds['website-1-3']});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ define([
obj.data = function (data) {
if (!data) {
return {
dataProperty: 'dataValue'
existingKey1: 'existingKey1Value',
existingKey2: 'existingKey2Value'
};
}

Expand All @@ -130,14 +131,16 @@ define([
it('check calls "providerHandler" method with data', function () {
var data = {
items: {
key: 'value'
newKey: 'newKeyValue',
existingKey2: 'existingKey2NewValue'
}
};

obj.providerHandler(data);

expect(obj.result.key).toBe('value');
expect(obj.result.dataProperty).toBe('dataValue');
expect(obj.result.existingKey1).toBe('existingKey1Value');
expect(obj.result.existingKey2).toBe('existingKey2NewValue');
expect(obj.result.newKey).toBe('newKeyValue');
});
it('check calls "providerHandler" method without data', function () {
obj.providerHandler({});
Expand Down Expand Up @@ -344,9 +347,20 @@ define([
expect(obj.hasIdsInSentRequest(ids)).toBe(false);
});

it('check calls "hasIdsInSentRequest" with request data', function () {
it('check calls "hasIdsInSentRequest" with request data #1', function () {
expect(obj.hasIdsInSentRequest(ids)).toBe(true);
});

it('check calls "hasIdsInSentRequest" with request data #2', function () {
obj.request = {
data: {
'2': {
data: 'value'
}
}
};
expect(obj.hasIdsInSentRequest(ids)).toBe(false);
});
});
describe('"addDataFromPageCache" method', function () {
beforeEach(function () {
Expand Down

0 comments on commit 81e372b

Please sign in to comment.