Skip to content

Commit

Permalink
MAGETWO-54733: Unable to save product with all unchecked values for m…
Browse files Browse the repository at this point in the history
…ultiple select attribute #7687
  • Loading branch information
VladimirZaets committed Jan 18, 2017
1 parent cdab87a commit b86644e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,62 +53,45 @@ define([

expect(type).toEqual('object');
});
it('Check "beforeSave" method. Check call "filterFormData" inside themselves.', function () {
it('Check "beforeSave" method. ' +
'Check calls "filterFormData", "serialize" and "ajax" inside themselves.', function () {
var data = {
key: {
anotherKey: 'value'
},
anotherKey: []
};
},
params;

obj.urls.beforeSave = 'requestPath';
obj.selectorPrefix = 'selectorPrefix';
obj.messagesClass = 'messagesClass';
utils.filterFormData = jasmine.createSpy().and.returnValue(utils.filterFormData(data));

obj.save(data);
expect(utils.filterFormData).toHaveBeenCalledWith(data);
});
it('Check "beforeSave" method. Check call "serialize" inside themselves.', function () {
var data = {
key: {
anotherKey: 'value'
},
anotherKey: []
};

obj.urls.beforeSave = 'requestPath';
obj.selectorPrefix = 'selectorPrefix';
obj.messagesClass = 'messagesClass';
utils.serialize = jasmine.createSpy().and.returnValue(utils.serialize(data));
params = {
url: obj.urls.beforeSave,
data: _.extend(data, {
form_key: 'magentoFormKey'
}),
success: jasmine.any(Function),
complete: jasmine.any(Function)
};

utils.filterFormData = jasmine.createSpy().and.returnValue(data);
utils.serialize = jasmine.createSpy().and.returnValue(data);
$.ajax = jasmine.createSpy();

obj.save(data);
expect(utils.filterFormData).toHaveBeenCalledWith(data);
expect(utils.serialize).toHaveBeenCalledWith(data);
});
it('Check "beforeSave" method. Check call "ajax" inside themselves.', function () {
var data = {
key: {
anotherKey: 'value'
},
'anotherKey-prepared-for-send': []
},
result = {
url: obj.urls.beforeSave,
data: {
'key[anotherKey]': 'value',
'form_key': 'magentoFormKey'
},
success: jasmine.any(Function),
complete: jasmine.any(Function)
};
expect($.ajax).toHaveBeenCalledWith(params);

obj.urls.beforeSave = 'requestPath';
obj.selectorPrefix = 'selectorPrefix';
obj.messagesClass = 'messagesClass';
});
it('Check call "beforeSave" method without parameters', function () {
$.ajax = jasmine.createSpy();
obj.urls.beforeSave = null;
obj.save();

obj.save(data);
expect($.ajax).toHaveBeenCalledWith(result);
expect($.ajax).not.toHaveBeenCalled();
});
});

Expand Down
12 changes: 6 additions & 6 deletions lib/web/mage/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ define([
},

/**
* Filters data. Find properties with suffix
* and set his value to original properties.
* Filters data object. Finds properties with suffix
* and sets their values to properties with the same name without suffix.
*
* @param {Object} data
* @param {String} suffix
* @param {String} separator
* @param {Object} data - The data object that should be filtered
* @param {String} suffix - The string by which data object should be filtered
* @param {String} separator - The string that is separator between property and suffix
*
* @returns {Object}
* @returns {Object} Filtered data object
*/
filterFormData: function (data, suffix, separator) {
data = data || {};
Expand Down

0 comments on commit b86644e

Please sign in to comment.