Skip to content

Commit c6fc3d8

Browse files
committed
Merge remote-tracking branch 'origin/MC-39820' into 2.4-develop-pr122
2 parents 8d7e504 + ed13587 commit c6fc3d8

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

app/code/Magento/Multishipping/view/frontend/requirejs-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var config = {
1010
orderOverview: 'Magento_Multishipping/js/overview',
1111
payment: 'Magento_Multishipping/js/payment',
1212
billingLoader: 'Magento_Checkout/js/checkout-loader',
13-
cartUpdate: 'Magento_Checkout/js/action/update-shopping-cart'
13+
cartUpdate: 'Magento_Checkout/js/action/update-shopping-cart',
14+
multiShippingBalance: 'Magento_Multishipping/js/multi-shipping-balance'
1415
}
1516
}
1617
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'mage/dataPost',
9+
'jquery-ui-modules/widget'
10+
], function ($, dataPost) {
11+
'use strict';
12+
13+
$.widget('mage.multiShippingBalance', {
14+
options: {
15+
changeUrl: ''
16+
},
17+
18+
/**
19+
* Initialize balance checkbox events.
20+
*
21+
* @private
22+
*/
23+
_create: function () {
24+
this.element.on('change', $.proxy(function (event) {
25+
dataPost().postData({
26+
action: this.options.changeUrl,
27+
data: {
28+
useBalance: +$(event.target).is(':checked')
29+
}
30+
});
31+
}, this));
32+
}
33+
});
34+
35+
return $.mage.multiShippingBalance;
36+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define(['squire', 'jquery'], function (Squire, $) {
7+
'use strict';
8+
9+
var injector = new Squire(),
10+
dataPost = {
11+
postData: jasmine.createSpy()
12+
},
13+
mocks = {
14+
/** Stub */
15+
'mage/dataPost': function () {
16+
return dataPost;
17+
}
18+
},
19+
checkbox,
20+
url = 'example.com',
21+
22+
/**
23+
* Toggle checkbox and assert that event was triggered.
24+
*
25+
* @param {Integer} value
26+
*/
27+
toggleCheckbox = function (value) {
28+
checkbox.trigger('click');
29+
expect(dataPost.postData.calls.mostRecent().args[0]).toEqual({
30+
action: url,
31+
data: {
32+
useBalance: value
33+
}
34+
});
35+
};
36+
37+
beforeEach(function (done) {
38+
checkbox = $('<input type="checkbox" name="use_balance" checked="checked"/>');
39+
$(document.body).append(checkbox);
40+
41+
injector.mock(mocks);
42+
injector.require(['multiShippingBalance'], function (balance) {
43+
balance({
44+
changeUrl: url
45+
}, checkbox);
46+
done();
47+
});
48+
});
49+
50+
afterEach(function () {
51+
try {
52+
injector.clean();
53+
injector.remove();
54+
} catch (e) {}
55+
56+
checkbox.remove();
57+
});
58+
59+
describe('multiShippingBalance', function () {
60+
it('Check actions after clicking on checkbox.', function () {
61+
toggleCheckbox(0);
62+
toggleCheckbox(1);
63+
toggleCheckbox(0);
64+
expect(dataPost.postData).toHaveBeenCalledTimes(3);
65+
});
66+
});
67+
});

0 commit comments

Comments
 (0)