forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ACP2E-2260' of https://github.com/magento-l3/magento2ce …
…into Tier4-PR-10-30-2023
- Loading branch information
Showing
5 changed files
with
242 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
213 changes: 213 additions & 0 deletions
213
dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/provider.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters