Skip to content

Commit 72bd339

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

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/multiselect.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ define([
4141
return _.isString(value) ? value.split(',') : value;
4242
},
4343

44+
/**
45+
* Sets the prepared data to dataSource
46+
* by path, where key is component link to dataSource with
47+
* suffix "-prepared-for-send"
48+
*
49+
* @param {Array} data - current component value
50+
*/
4451
setPrepareToSendData: function (data) {
45-
4652
if (!data.length) {
4753
data = '';
4854
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint max-nested-callbacks: 0 */
7+
define([
8+
'squire'
9+
], function (Squire) {
10+
'use strict';
11+
12+
var injector = new Squire(),
13+
mocks = {
14+
'Magento_Ui/js/lib/core/events': {
15+
on: jasmine.createSpy()
16+
},
17+
'Magento_Ui/js/lib/registry/registry': {
18+
get: function() {
19+
return {
20+
get: jasmine.createSpy(),
21+
set: jasmine.createSpy()
22+
};
23+
},
24+
create: jasmine.createSpy(),
25+
set: jasmine.createSpy(),
26+
async: jasmine.createSpy()
27+
},
28+
'/mage/utils/wrapper': jasmine.createSpy()
29+
},
30+
obj,
31+
dataScope = 'dataScope';
32+
33+
beforeEach(function (done) {
34+
injector.mock(mocks);
35+
injector.require(['Magento_Ui/js/form/element/multiselect'], function (Constr) {
36+
obj = new Constr({
37+
provider: 'provName',
38+
name: '',
39+
index: '',
40+
dataScope: dataScope
41+
});
42+
43+
done();
44+
});
45+
});
46+
47+
describe('Magento_Ui/js/form/element/multiselect', function () {
48+
describe('"setPrepareToSendData" method', function () {
49+
it('Check method call with empty array as parameter.', function () {
50+
expect(obj.setPrepareToSendData([])).toBeUndefined();
51+
expect(obj.source.set).toHaveBeenCalledWith(dataScope + '-prepared-for-send', '');
52+
});
53+
54+
it('Check method call with array with data as parameter.', function () {
55+
expect(obj.setPrepareToSendData(['1', '2', '3'])).toBeUndefined();
56+
expect(obj.source.set).toHaveBeenCalledWith(dataScope + '-prepared-for-send', ['1', '2', '3']);
57+
});
58+
});
59+
});
60+
});

0 commit comments

Comments
 (0)