Skip to content

Commit 5a0b6c9

Browse files
committed
Merge remote-tracking branch 'mpi/MC-36755' into MPI-2020-09-14
2 parents fa74fae + 503c428 commit 5a0b6c9

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_grid.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</settings>
5959
</filterSelect>
6060
</filters>
61-
<massaction name="listing_massaction" component="Magento_Ui/js/grid/tree-massactions">
61+
<massaction name="listing_massaction" component="Magento_Sales/js/grid/tree-massactions">
6262
<action name="cancel">
6363
<settings>
6464
<url path="sales/order/massCancel"/>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'underscore',
8+
'mageUtils',
9+
'Magento_Ui/js/grid/tree-massactions'
10+
], function (_, utils, Massactions) {
11+
'use strict';
12+
13+
return Massactions.extend({
14+
/**
15+
* Overwrite Default action callback.
16+
* Sends selections data with ids
17+
* via POST request.
18+
*
19+
* @param {Object} action - Action data.
20+
* @param {Object} data - Selections data.
21+
*/
22+
defaultCallback: function (action, data) {
23+
var itemsType = 'selected',
24+
selections = {};
25+
26+
selections[itemsType] = data[itemsType];
27+
_.extend(selections, data.params || {});
28+
utils.submit({
29+
url: action.url,
30+
data: selections
31+
});
32+
}
33+
});
34+
});
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/*eslint max-nested-callbacks: 0*/
7+
define([
8+
'jquery',
9+
'squire',
10+
'underscore',
11+
'Magento_Sales/js/grid/tree-massactions'
12+
], function ($, Squire, _, TreeMassaction) {
13+
'use strict';
14+
15+
var injector = new Squire(),
16+
mocks = {
17+
'Magento_Ui/js/grid/massactions': {
18+
defaultCallback: jasmine.createSpy().and.returnValue({}),
19+
applyAction: jasmine.createSpy().and.returnValue({})
20+
}
21+
},
22+
obj,
23+
utils;
24+
25+
describe('Magento_Sales/js/grid/tree-massactions', function () {
26+
var model;
27+
28+
beforeEach(function (done) {
29+
injector.mock(mocks);
30+
injector.require([
31+
'Magento_Ui/js/grid/massactions',
32+
'mageUtils'
33+
], function (instance, mageUtils) {
34+
obj = _.extend({}, instance);
35+
utils = mageUtils;
36+
done();
37+
});
38+
model = new TreeMassaction({
39+
actions: [
40+
{
41+
type: 'availability',
42+
actions: [{
43+
type: 'enable'
44+
}, {
45+
type: 'disable'
46+
}]
47+
},
48+
{
49+
type: 'hold_order',
50+
component: 'uiComponent',
51+
label: 'hold',
52+
url: 'http://local.magento/hold_order',
53+
modules: {
54+
selections: ['1','2','3']
55+
},
56+
actions: [{
57+
callback: 'defaultCallback'
58+
}]
59+
}]
60+
});
61+
});
62+
63+
afterEach(function () {
64+
try {
65+
injector.clean();
66+
injector.remove();
67+
} catch (e) {}
68+
});
69+
70+
describe('check applyAction', function () {
71+
it('change visibility of submenu', function () {
72+
expect(model.actions()[0].visible()).toBeFalsy();
73+
expect(model.applyAction('availability')).toBe(model);
74+
expect(model.actions()[0].visible()).toBeTruthy();
75+
});
76+
});
77+
describe('check defaultCallback', function () {
78+
it('check model called with action and selected data', function () {
79+
expect(model.applyAction('hold_order')).toBe(model);
80+
expect(model.actions()[1].visible()).toBeTruthy();
81+
expect(model.actions()[1].modules.selections).toBeTruthy();
82+
expect(model.actions()[1].modules.selections.total).toBeFalsy();
83+
});
84+
85+
it('check defaultCallback submitted the data', function () {
86+
var action = {
87+
component: 'uiComponent',
88+
label: 'Hold',
89+
type: 'hold_order',
90+
url: 'http://local.magento/hold_order/'
91+
},
92+
data = {
93+
excludeMode: true,
94+
excluded: [],
95+
params: {},
96+
selected: ['7', '6', '5', '4', '3', '2', '1'],
97+
total: 7
98+
},
99+
result;
100+
101+
obj.getAction = jasmine.createSpy().and.returnValue('hold_order');
102+
103+
obj.applyAction(action);
104+
105+
result = obj.defaultCallback(action, data);
106+
107+
expect(typeof result).toBe('object');
108+
spyOn(utils, 'submit').and.callThrough();
109+
utils.submit({
110+
url: action.url,
111+
data: data.selected
112+
});
113+
expect(utils.submit).toHaveBeenCalled();
114+
});
115+
});
116+
});
117+
});

0 commit comments

Comments
 (0)