Skip to content

Commit b48d29d

Browse files
MAGETWO-69499: Update select.js #9475
2 parents 357b6e6 + 24244e9 commit b48d29d

File tree

2 files changed

+51
-5
lines changed
  • app/code/Magento/Ui/view/base/web/js/grid/columns
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns

2 files changed

+51
-5
lines changed

app/code/Magento/Ui/view/base/web/js/grid/columns/select.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ define([
2727
values = values.split(',');
2828
}
2929

30-
if (!Array.isArray(values)) {
30+
if (!_.isArray(values)) {
3131
values = [values];
3232
}
3333

@@ -55,6 +55,10 @@ define([
5555
flatOptions: function (options) {
5656
var self = this;
5757

58+
if (!_.isArray(options)) {
59+
options = _.values(options);
60+
}
61+
5862
return options.reduce(function (opts, option) {
5963
if (_.isArray(option.value)) {
6064
opts = opts.concat(self.flatOptions(option.value));

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/select.test.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
2+
* Copyright © 2016 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
55
/*eslint max-nested-callbacks: 0*/
@@ -10,15 +10,57 @@ define([
1010
'use strict';
1111

1212
describe('Ui/js/grid/columns/select', function () {
13-
var select;
13+
var fieldName = 'selectField',
14+
opts = [{
15+
label: 'a', value: 1
16+
}, {
17+
label: 'b', value: 2
18+
}],
19+
optsAsObject = {
20+
1: {
21+
label: 'a', value: 1
22+
},
23+
2: {
24+
label: 'b', value: 2
25+
},
26+
4: {
27+
label: 'c', value: 3
28+
}
29+
},
30+
select;
1431

1532
beforeEach(function () {
16-
select = new Select();
33+
select = new Select({
34+
index: fieldName
35+
});
1736
});
1837

1938
describe('getLabel method', function () {
2039
it('get label while options empty', function () {
21-
expect(select.getLabel(2)).toBe('');
40+
expect(select.getLabel({
41+
selectField: '2'
42+
})).toBe('');
43+
});
44+
45+
it('get label for existed value', function () {
46+
select.options = opts;
47+
expect(select.getLabel({
48+
selectField: '2'
49+
})).toBe('b');
50+
});
51+
52+
it('get label for existed value in case the options are initialized as an object', function () {
53+
select.options = optsAsObject;
54+
expect(select.getLabel({
55+
selectField: '3'
56+
})).toBe('c');
57+
});
58+
59+
it('get labels for existed values in case the options are initialized as an object', function () {
60+
select.options = optsAsObject;
61+
expect(select.getLabel({
62+
selectField: '1,3'
63+
})).toBe('a, c');
2264
});
2365
});
2466
});

0 commit comments

Comments
 (0)