Skip to content

Commit cc1b742

Browse files
committed
Merge remote-tracking branch 'origin/MC-24725' into 2.4-develop-pr123
2 parents 7f4b115 + 08f0b14 commit cc1b742

File tree

2 files changed

+87
-1
lines changed
  • app/code/Magento/Checkout/view/frontend/web/js/model
  • dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/model

2 files changed

+87
-1
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/totals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ define([
2222
quoteItems(newValue.items);
2323
});
2424

25-
if (quoteSubtotal !== subtotalAmount) {
25+
if (!isNaN(subtotalAmount) && quoteSubtotal !== subtotalAmount) {
2626
customerData.reload(['cart'], false);
2727
}
2828

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable max-nested-callbacks */
7+
/*jscs:disable jsDoc*/
8+
define([
9+
'squire', 'jquery', 'ko'
10+
], function (Squire, $, ko) {
11+
'use strict';
12+
13+
var injector = new Squire(),
14+
cartData = {
15+
'subtotalAmount': 10
16+
},
17+
cart = ko.observable(cartData),
18+
cartDataTwo = {
19+
'subtotalAmount': NaN
20+
},
21+
cartTwo = ko.observable(cartDataTwo),
22+
mocks = {
23+
'Magento_Checkout/js/model/quote': {
24+
totals: ko.observable({
25+
'subtotal': 4
26+
})
27+
},
28+
'Magento_Customer/js/customer-data': {
29+
get: function () {
30+
return cart;
31+
},
32+
reload: jasmine.createSpy(),
33+
getInitCustomerData: function () {}
34+
}
35+
},
36+
mocksTwo = {
37+
'Magento_Checkout/js/model/quote': {
38+
totals: ko.observable({
39+
'subtotal': 10
40+
})
41+
},
42+
'Magento_Customer/js/customer-data': {
43+
get: function () {
44+
return cartTwo;
45+
},
46+
reload: jasmine.createSpy(),
47+
getInitCustomerData: function () {}
48+
}
49+
};
50+
51+
afterEach(function () {
52+
try {
53+
injector.clean();
54+
injector.remove();
55+
} catch (e) {}
56+
});
57+
58+
describe('Test that customer data is reloaded when quote subtotal and cart subtotal are different', function () {
59+
beforeEach(function (done) {
60+
injector.mock(mocks);
61+
injector.require(['Magento_Checkout/js/model/totals'], function () {
62+
done();
63+
});
64+
});
65+
it('Test that customer data is reloaded when quote subtotal and cart subtotal are different', function () {
66+
expect(mocks['Magento_Checkout/js/model/quote'].totals().subtotal).toBe(4);
67+
expect(cart().subtotalAmount).toBe(10);
68+
expect(mocks['Magento_Customer/js/customer-data'].reload).toHaveBeenCalled();
69+
});
70+
});
71+
72+
describe('Test that customer data is not reloaded when cart subtotal is NaN', function () {
73+
beforeEach(function (done) {
74+
injector.mock(mocksTwo);
75+
injector.require(['Magento_Checkout/js/model/totals'], function () {
76+
done();
77+
});
78+
});
79+
it('Test that customer data is not reloaded when cart subtotal is NaN', function () {
80+
expect(mocksTwo['Magento_Checkout/js/model/quote'].totals().subtotal).toBe(10);
81+
expect(cartTwo().subtotalAmount).toBeNaN();
82+
expect(mocksTwo['Magento_Customer/js/customer-data'].reload).not.toHaveBeenCalled();
83+
});
84+
});
85+
});
86+

0 commit comments

Comments
 (0)