Skip to content

Commit b86644e

Browse files
committed
MAGETWO-54733: Unable to save product with all unchecked values for multiple select attribute #7687
1 parent cdab87a commit b86644e

File tree

2 files changed

+29
-46
lines changed

2 files changed

+29
-46
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/client.test.js

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,62 +53,45 @@ define([
5353

5454
expect(type).toEqual('object');
5555
});
56-
it('Check "beforeSave" method. Check call "filterFormData" inside themselves.', function () {
56+
it('Check "beforeSave" method. ' +
57+
'Check calls "filterFormData", "serialize" and "ajax" inside themselves.', function () {
5758
var data = {
5859
key: {
5960
anotherKey: 'value'
6061
},
6162
anotherKey: []
62-
};
63+
},
64+
params;
6365

6466
obj.urls.beforeSave = 'requestPath';
6567
obj.selectorPrefix = 'selectorPrefix';
6668
obj.messagesClass = 'messagesClass';
67-
utils.filterFormData = jasmine.createSpy().and.returnValue(utils.filterFormData(data));
68-
69-
obj.save(data);
70-
expect(utils.filterFormData).toHaveBeenCalledWith(data);
71-
});
72-
it('Check "beforeSave" method. Check call "serialize" inside themselves.', function () {
73-
var data = {
74-
key: {
75-
anotherKey: 'value'
76-
},
77-
anotherKey: []
78-
};
7969

80-
obj.urls.beforeSave = 'requestPath';
81-
obj.selectorPrefix = 'selectorPrefix';
82-
obj.messagesClass = 'messagesClass';
83-
utils.serialize = jasmine.createSpy().and.returnValue(utils.serialize(data));
70+
params = {
71+
url: obj.urls.beforeSave,
72+
data: _.extend(data, {
73+
form_key: 'magentoFormKey'
74+
}),
75+
success: jasmine.any(Function),
76+
complete: jasmine.any(Function)
77+
};
78+
79+
utils.filterFormData = jasmine.createSpy().and.returnValue(data);
80+
utils.serialize = jasmine.createSpy().and.returnValue(data);
81+
$.ajax = jasmine.createSpy();
8482

8583
obj.save(data);
84+
expect(utils.filterFormData).toHaveBeenCalledWith(data);
8685
expect(utils.serialize).toHaveBeenCalledWith(data);
87-
});
88-
it('Check "beforeSave" method. Check call "ajax" inside themselves.', function () {
89-
var data = {
90-
key: {
91-
anotherKey: 'value'
92-
},
93-
'anotherKey-prepared-for-send': []
94-
},
95-
result = {
96-
url: obj.urls.beforeSave,
97-
data: {
98-
'key[anotherKey]': 'value',
99-
'form_key': 'magentoFormKey'
100-
},
101-
success: jasmine.any(Function),
102-
complete: jasmine.any(Function)
103-
};
86+
expect($.ajax).toHaveBeenCalledWith(params);
10487

105-
obj.urls.beforeSave = 'requestPath';
106-
obj.selectorPrefix = 'selectorPrefix';
107-
obj.messagesClass = 'messagesClass';
88+
});
89+
it('Check call "beforeSave" method without parameters', function () {
10890
$.ajax = jasmine.createSpy();
91+
obj.urls.beforeSave = null;
92+
obj.save();
10993

110-
obj.save(data);
111-
expect($.ajax).toHaveBeenCalledWith(result);
94+
expect($.ajax).not.toHaveBeenCalled();
11295
});
11396
});
11497

lib/web/mage/utils/misc.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ define([
210210
},
211211

212212
/**
213-
* Filters data. Find properties with suffix
214-
* and set his value to original properties.
213+
* Filters data object. Finds properties with suffix
214+
* and sets their values to properties with the same name without suffix.
215215
*
216-
* @param {Object} data
217-
* @param {String} suffix
218-
* @param {String} separator
216+
* @param {Object} data - The data object that should be filtered
217+
* @param {String} suffix - The string by which data object should be filtered
218+
* @param {String} separator - The string that is separator between property and suffix
219219
*
220-
* @returns {Object}
220+
* @returns {Object} Filtered data object
221221
*/
222222
filterFormData: function (data, suffix, separator) {
223223
data = data || {};

0 commit comments

Comments
 (0)