Skip to content

Commit 92d25de

Browse files
author
Mariana Lashch
committed
Merge branch 'MAGETWO-92502' into mpi-PR-2506
2 parents f4714fe + c46bc6c commit 92d25de

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ define([
4747
* @param {*} data
4848
*/
4949
add: function (data) {
50-
if (!utils.compare(data, this.data()).equal) {
50+
if (!_.isEmpty(data) && !utils.compare(data, this.data()).equal) {
5151
this.data(_.extend(utils.copy(this.data()), data));
5252
}
5353
},

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

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,11 @@ define([
1212

1313
var injector = new Squire(),
1414
mocks = {
15-
'Magento_Catalog/js/product/storage/ids-storage': {
16-
name: 'IdsStorage',
17-
initialize: jasmine.createSpy().and.returnValue({})
18-
},
1915
'Magento_Catalog/js/product/storage/data-storage': {},
2016
'Magento_Catalog/js/product/storage/ids-storage-compare': {}
2117
},
22-
obj;
23-
24-
beforeEach(function (done) {
25-
injector.mock(mocks);
26-
injector.require(['Magento_Catalog/js/product/storage/storage-service'], function (insance) {
27-
obj = insance;
28-
done();
29-
});
30-
});
18+
obj,
19+
utils;
3120

3221
describe('Magento_Catalog/js/product/storage/storage-service', function () {
3322
var config = {
@@ -36,6 +25,19 @@ define([
3625
},
3726
storage;
3827

28+
beforeEach(function (done) {
29+
injector.mock(mocks);
30+
injector.require([
31+
'Magento_Catalog/js/product/storage/ids-storage',
32+
'Magento_Catalog/js/product/storage/storage-service',
33+
'mageUtils'
34+
], function (IdsStorage, instance, mageUtils) {
35+
obj = instance;
36+
utils = mageUtils;
37+
done();
38+
});
39+
});
40+
3941
describe('"createStorage" method', function () {
4042
it('create new storage', function () {
4143
obj.processSubscribers = jasmine.createSpy();
@@ -66,5 +68,54 @@ define([
6668
expect(typeof obj.getStorage(config.namespace)).toBe('object');
6769
});
6870
});
71+
describe('"add" method', function () {
72+
var storageValue;
73+
74+
beforeEach(function () {
75+
storage = new obj.createStorage(config);
76+
storageValue = {
77+
'property1': 1
78+
};
79+
80+
storage.set(storageValue);
81+
});
82+
83+
it('method exists', function () {
84+
expect(storage.add).toBeDefined();
85+
expect(typeof storage.add).toEqual('function');
86+
});
87+
88+
it('update value', function () {
89+
spyOn(utils, 'copy').and.callThrough();
90+
expect(storage.get()).toEqual(storageValue);
91+
92+
storageValue = {
93+
'property2': 2
94+
};
95+
96+
storage.add(storageValue);
97+
98+
expect(utils.copy).toHaveBeenCalled();
99+
expect(storage.get()).toEqual(
100+
{
101+
'property1': 1,
102+
'property2': 2
103+
}
104+
);
105+
});
106+
107+
it('add empty value', function () {
108+
spyOn(utils, 'copy').and.callThrough();
109+
110+
storage.add({});
111+
112+
expect(utils.copy).not.toHaveBeenCalled();
113+
expect(storage.get()).toEqual(
114+
{
115+
'property1': 1
116+
}
117+
);
118+
});
119+
});
69120
});
70121
});

0 commit comments

Comments
 (0)