Skip to content

Commit 81e372b

Browse files
committed
Merge branch 'ACP2E-2260' of https://github.com/magento-l3/magento2ce into Tier4-PR-10-30-2023
2 parents 6235bb4 + 9c35d2d commit 81e372b

File tree

5 files changed

+242
-20
lines changed

5 files changed

+242
-20
lines changed

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertSeeProductDetailsOnStorefrontRecentlyViewedWidgetActionGroup.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
1111
<actionGroup name="AssertSeeProductDetailsOnStorefrontRecentlyViewedWidgetActionGroup">
1212
<annotations>
13-
<description>Goes to the home Page Recently VIewed Product and Grab the Prdouct name and Position from it.</description>
13+
<description>Goes to the home Page Recently Viewed Product and Grab the Product name and Position from it.</description>
1414
</annotations>
1515
<arguments>
1616
<argument name="productName" type="string"/>
1717
<argument name="productPosition" type="string"/>
1818
</arguments>
19+
<waitForElementVisible selector="{{StoreFrontRecentlyViewedProductSection.ProductName(productPosition)}}" stepKey="waitForProductToShowAtPosition"/>
1920
<grabTextFrom selector="{{StoreFrontRecentlyViewedProductSection.ProductName(productPosition)}}" stepKey="grabRelatedProductPosition"/>
2021
<assertStringContainsString stepKey="assertRelatedProductName">
2122
<actualResult type="const">$grabRelatedProductPosition</actualResult>

app/code/Magento/Catalog/view/frontend/web/js/product/provider.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,15 @@ define([
9898
return;
9999
}
100100

101+
// Filter initial ids to remove "out of scope" and "outdated" data
102+
this.ids(
103+
this.filterIds(this.ids())
104+
);
101105
this.initIdsListener();
102106
this.idsMerger(
103107
this.idsStorage.get(),
104108
this.prepareDataFromCustomerData(customerData.get(this.identifiersConfig.namespace)())
105109
);
106-
107-
if (!_.isEmpty(this.productStorage.data())) {
108-
this.dataCollectionHandler(this.productStorage.data());
109-
} else {
110-
this.productStorage.setIds(this.data.currency, this.data.store, this.ids());
111-
}
112110
},
113111

114112
/**
@@ -176,7 +174,7 @@ define([
176174

177175
if (!_.isEmpty(data)) {
178176
this.ids(
179-
this.filterIds(_.extend(this.ids(), data))
177+
this.filterIds(_.extend(utils.copy(this.ids()), data))
180178
);
181179
}
182180
},

app/code/Magento/Catalog/view/frontend/web/js/product/storage/data-storage.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ define([
149149
if (data.items && ids.length) {
150150
//we can extend only items
151151
data = data.items;
152-
this.data(_.extend(data, currentData));
152+
this.data(_.extend(currentData, data));
153153
}
154154
},
155155

@@ -271,13 +271,9 @@ define([
271271
sentDataIds = _.keys(this.request.data);
272272
currentDataIds = _.keys(ids);
273273

274-
_.each(currentDataIds, function (id) {
275-
if (_.lastIndexOf(sentDataIds, id) === -1) {
276-
return false;
277-
}
274+
return _.every(currentDataIds, function (id) {
275+
return _.lastIndexOf(sentDataIds, id) !== -1;
278276
});
279-
280-
return true;
281277
}
282278

283279
return false;
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/************************************************************************
2+
*
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
* ************************************************************************
15+
*/
16+
17+
/* eslint-disable max-nested-callbacks */
18+
define([
19+
'squire',
20+
'underscore'
21+
], function (Squire, _) {
22+
'use strict';
23+
24+
var injector = new Squire(),
25+
obj,
26+
customerDataIds,
27+
localStorageIds,
28+
timestamp,
29+
namespace = 'namespace',
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 = [],
40+
productResolver = jasmine.createSpy().and.callFake(function () {
41+
return productResolverIds;
42+
}),
43+
storage = {
44+
onStorageInit: jasmine.createSpy(),
45+
createStorage: jasmine.createSpy()
46+
},
47+
mocks = {
48+
'Magento_Customer/js/customer-data': customerData,
49+
'Magento_Catalog/js/product/view/product-ids-resolver': productResolver,
50+
'Magento_Catalog/js/product/storage/storage-service': storage
51+
};
52+
53+
beforeEach(function (done) {
54+
injector.mock(mocks);
55+
injector.require(['Magento_Catalog/js/product/provider'], function (UiClass) {
56+
timestamp = new Date().getTime() / 1000;
57+
obj = new UiClass({
58+
identifiersConfig: {
59+
namespace: namespace
60+
},
61+
ids: {
62+
'website-1-1': {
63+
added_at: timestamp - 300,
64+
product_id: 1,
65+
scope_id: 1
66+
}
67+
},
68+
data: {
69+
store: '1',
70+
currency: 'USD',
71+
productCurrentScope: 'website'
72+
}
73+
});
74+
localStorageIds = {
75+
'website-1-2': {
76+
added_at: timestamp - 60,
77+
product_id: 2,
78+
scope_id: 1
79+
},
80+
'website-1-3': {
81+
added_at: timestamp - 180,
82+
product_id: 3,
83+
scope_id: 1
84+
}
85+
};
86+
customerDataIds = {
87+
4: {
88+
added_at: timestamp - 360,
89+
product_id: 4,
90+
scope_id: 1
91+
}
92+
};
93+
done();
94+
});
95+
});
96+
97+
afterEach(function () {
98+
try {
99+
injector.clean();
100+
injector.remove();
101+
} catch (e) {
102+
}
103+
window.localStorage.clear();
104+
window.checkout = windowCheckoutData;
105+
});
106+
107+
describe('Magento_Catalog/js/product/provider', function () {
108+
describe('"_resolveDataByIds" method', function () {
109+
beforeEach(function () {
110+
obj.initIdsListener = jasmine.createSpy();
111+
obj.idsMerger = jasmine.createSpy();
112+
obj.idsHandler = jasmine.createSpy();
113+
obj.filterIds = jasmine.createSpy().and.returnValue({});
114+
});
115+
it('check "window.checkout" is required', function () {
116+
window.checkout = undefined;
117+
obj.ids = jasmine.createSpy();
118+
119+
obj._resolveDataByIds();
120+
121+
expect(obj.ids).not.toHaveBeenCalled();
122+
expect(obj.filterIds).not.toHaveBeenCalled();
123+
expect(obj.idsHandler).not.toHaveBeenCalled();
124+
expect(obj.initIdsListener).not.toHaveBeenCalled();
125+
expect(obj.idsMerger).not.toHaveBeenCalled();
126+
});
127+
it('check that initial ids, localstorage ids and ids from customer data are processed', function () {
128+
var initialIds = obj.ids();
129+
130+
window.checkout = {
131+
baseUrl: 'http://localhost/',
132+
websiteId: 1
133+
};
134+
obj.idsStorage = {
135+
get: jasmine.createSpy().and.returnValue(localStorageIds),
136+
lifetime: 1000
137+
};
138+
obj.prepareDataFromCustomerData = jasmine.createSpy().and.returnValue(customerDataIds);
139+
customerData.get = jasmine.createSpy().and.returnValue(customerDataGet);
140+
141+
obj._resolveDataByIds();
142+
143+
expect(obj.filterIds).toHaveBeenCalledOnceWith(initialIds);
144+
expect(obj.idsHandler).toHaveBeenCalledOnceWith({});
145+
expect(obj.initIdsListener).toHaveBeenCalled();
146+
expect(customerData.get).toHaveBeenCalledOnceWith(namespace);
147+
expect(obj.prepareDataFromCustomerData).toHaveBeenCalledOnceWith({items: customerDataIds});
148+
expect(obj.idsMerger).toHaveBeenCalledOnceWith(localStorageIds, customerDataIds);
149+
});
150+
});
151+
describe('"idsMerger" method', function () {
152+
beforeEach(function () {
153+
obj.idsHandler = jasmine.createSpy();
154+
obj.filterIds = jasmine.createSpy().and.returnValue({});
155+
});
156+
it('check merge empty', function () {
157+
obj.idsMerger({}, {});
158+
159+
expect(obj.filterIds).not.toHaveBeenCalled();
160+
expect(obj.idsHandler).not.toHaveBeenCalled();
161+
});
162+
163+
it('check merge not empty', function () {
164+
var initialIds = obj.ids();
165+
166+
obj.idsMerger(localStorageIds, {});
167+
168+
expect(obj.filterIds).toHaveBeenCalledOnceWith(_.extend({}, initialIds, localStorageIds));
169+
expect(obj.idsHandler).toHaveBeenCalledOnceWith({});
170+
});
171+
});
172+
173+
describe('"prepareDataFromCustomerData" method', function () {
174+
it('argument is empty', function () {
175+
expect(obj.prepareDataFromCustomerData({})).toEqual({});
176+
});
177+
178+
it('argument is an object and has "items" property', function () {
179+
expect(obj.prepareDataFromCustomerData({items: customerDataIds})).toEqual(customerDataIds);
180+
});
181+
182+
it('argument is an object and does not have "items" property', function () {
183+
expect(obj.prepareDataFromCustomerData(customerDataIds)).toEqual(customerDataIds);
184+
});
185+
});
186+
187+
describe('"filterIds" method', function () {
188+
beforeEach(function () {
189+
window.checkout = {
190+
websiteId: 1
191+
};
192+
obj.idsStorage = {
193+
lifetime: 1000
194+
};
195+
});
196+
197+
it('filters out "out of scope" ids', function () {
198+
window.checkout.websiteId = 2;
199+
expect(obj.filterIds(localStorageIds)).toEqual({});
200+
});
201+
202+
it('filters out expired ids', function () {
203+
obj.idsStorage.lifetime = 100;
204+
expect(obj.filterIds(localStorageIds)).toEqual({2: localStorageIds['website-1-2']});
205+
});
206+
207+
it('filters out current product id', function () {
208+
productResolverIds.push(2);
209+
expect(obj.filterIds(localStorageIds)).toEqual({3: localStorageIds['website-1-3']});
210+
});
211+
});
212+
});
213+
});

dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/storage/data-storage.test.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ define([
119119
obj.data = function (data) {
120120
if (!data) {
121121
return {
122-
dataProperty: 'dataValue'
122+
existingKey1: 'existingKey1Value',
123+
existingKey2: 'existingKey2Value'
123124
};
124125
}
125126

@@ -130,14 +131,16 @@ define([
130131
it('check calls "providerHandler" method with data', function () {
131132
var data = {
132133
items: {
133-
key: 'value'
134+
newKey: 'newKeyValue',
135+
existingKey2: 'existingKey2NewValue'
134136
}
135137
};
136138

137139
obj.providerHandler(data);
138140

139-
expect(obj.result.key).toBe('value');
140-
expect(obj.result.dataProperty).toBe('dataValue');
141+
expect(obj.result.existingKey1).toBe('existingKey1Value');
142+
expect(obj.result.existingKey2).toBe('existingKey2NewValue');
143+
expect(obj.result.newKey).toBe('newKeyValue');
141144
});
142145
it('check calls "providerHandler" method without data', function () {
143146
obj.providerHandler({});
@@ -344,9 +347,20 @@ define([
344347
expect(obj.hasIdsInSentRequest(ids)).toBe(false);
345348
});
346349

347-
it('check calls "hasIdsInSentRequest" with request data', function () {
350+
it('check calls "hasIdsInSentRequest" with request data #1', function () {
348351
expect(obj.hasIdsInSentRequest(ids)).toBe(true);
349352
});
353+
354+
it('check calls "hasIdsInSentRequest" with request data #2', function () {
355+
obj.request = {
356+
data: {
357+
'2': {
358+
data: 'value'
359+
}
360+
}
361+
};
362+
expect(obj.hasIdsInSentRequest(ids)).toBe(false);
363+
});
350364
});
351365
describe('"addDataFromPageCache" method', function () {
352366
beforeEach(function () {

0 commit comments

Comments
 (0)