Skip to content

Commit 12145bc

Browse files
committed
Updated paypal jasmine tests
1 parent 774cb4c commit 12145bc

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/Paypal/frontend/js/view/payment/method-renderer/paypal-express-abstract.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2+
3+
continueToPayPal ->
4+
Magento_Checkout/js/model/payment/additional-validators::validate -> true
5+
selectPaymentMethod
6+
setPaymentMethodAction -> called
7+
8+
9+
10+
11+
112
/**
213
* Copyright © Magento, Inc. All rights reserved.
314
* See COPYING.txt for license details.
@@ -16,13 +27,24 @@ define([
1627

1728
describe('paypal/js/view/payment/method-renderer/paypal-express-abstract', function () {
1829
var injector = new Squire(),
30+
successPromise = jasmine.createSpyObj('successPromise', ['done']),
31+
setPaymentMock = jasmine.createSpy('set-payment-information', function () {
32+
return successPromise;
33+
}).and.callThrough(),
34+
validateMock = jasmine.createSpy('validate', function () {
35+
return true;
36+
}).and.callThrough(),
1937
mocks = {
2038
'Magento_Checkout/js/model/quote': {
2139
billingAddress: ko.observable(),
2240
shippingAddress: ko.observable(),
2341
paymentMethod: ko.observable(),
2442
totals: ko.observable({})
2543

44+
},
45+
'Magento_Checkout/js/action/set-payment-information': setPaymentMock,
46+
'Magento_Checkout/js/model/payment/additional-validators': {
47+
validate: validateMock
2648
}
2749
},
2850
paypalExpressAbstract,
@@ -85,6 +107,25 @@ define([
85107
}, 500);
86108
});
87109

110+
it('setPaymentMethodAction is called before redirect to paypal', function () {
111+
spyOn(paypalExpressAbstract, 'selectPaymentMethod');
112+
paypalExpressAbstract.continueToPayPal();
113+
expect(paypalExpressAbstract.selectPaymentMethod).toHaveBeenCalled();
114+
expect(validateMock).toHaveBeenCalled();
115+
expect(validateMock.calls.mostRecent()).toEqual(jasmine.objectContaining({
116+
object: mocks['Magento_Checkout/js/model/payment/additional-validators'],
117+
args: [],
118+
returnValue: true
119+
}));
120+
expect(setPaymentMock).toHaveBeenCalled();
121+
expect(setPaymentMock.calls.mostRecent()).toEqual(jasmine.objectContaining({
122+
object: mocks['Magento_Checkout/js/action/set-payment-information'],
123+
args: [],
124+
returnValue: successPromise
125+
}));
126+
expect(successPromise.done).toHaveBeenCalledWith(jasmine.any(Function));
127+
});
128+
88129
afterAll(function (done) {
89130
tplElement.remove();
90131
done();

0 commit comments

Comments
 (0)