Skip to content

Commit 56a0f6c

Browse files
committed
MC-29967: [Braintree] Place Order button is not disabled
1 parent fa00ff7 commit 56a0f6c

File tree

3 files changed

+145
-1
lines changed
  • app/code/Magento/Vault/view/frontend/web
  • dev/tests/js/jasmine/tests/app/code/Magento/Vault/view/frontend/web/js/view/payment/method-renderer

3 files changed

+145
-1
lines changed

app/code/Magento/Vault/view/frontend/web/js/view/payment/method-renderer/vault.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ define(
104104
: false;
105105
},
106106

107+
/**
108+
* Return state of place order button.
109+
*
110+
* @return {Boolean}
111+
*/
112+
isButtonActive: function () {
113+
return this.isActive() && this.isPlaceOrderActionAllowed();
114+
},
115+
116+
/**
117+
* Check if payment is active.
118+
*
119+
* @return {Boolean}
120+
*/
121+
isActive: function () {
122+
return this.isChecked() === this.getId();
123+
},
124+
107125
/**
108126
* @returns {*}
109127
*/

app/code/Magento/Vault/view/frontend/web/template/payment/form.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
type="submit"
5050
data-bind="
5151
click: placeOrder,
52-
attr: {title: $t('Place Order')}">
52+
attr: {title: $t('Place Order')},
53+
enable: isButtonActive()
54+
"
55+
disabled>
5356
<span translate="'Place Order'"></span>
5457
</button>
5558
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'squire',
8+
'ko'
9+
], function (Squire, ko) {
10+
'use strict';
11+
12+
var injector = new Squire(),
13+
vault,
14+
mocks = {
15+
'Magento_Checkout/js/model/checkout-data-resolver': {
16+
resolveBillingAddress: jasmine.createSpy().and.returnValue(true)
17+
},
18+
'Magento_Checkout/js/checkout-data': {
19+
setSelectedPaymentMethod: jasmine.createSpy().and.returnValue(false)
20+
},
21+
'Magento_Checkout/js/model/quote': {
22+
billingAddress: ko.observable(null),
23+
shippingAddress: ko.observable(null),
24+
paymentMethod: ko.observable(null),
25+
totals: ko.observable({})
26+
}
27+
},
28+
billingAddress = {
29+
city: 'Culver City',
30+
company: 'Magento',
31+
country_id: 'US',// jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
32+
firstname: 'John',
33+
lastname: 'Doe',
34+
postcode: '90230',
35+
region: '',
36+
region_id: '12',// jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
37+
street: {
38+
0: '6161 West Centinela Avenue',
39+
1: ''
40+
},
41+
telephone: '+15555555555'
42+
};
43+
44+
beforeEach(function (done) {
45+
window.checkoutConfig = {
46+
quoteData: {
47+
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
48+
entity_Id: 1
49+
},
50+
formKey: 'formKey'
51+
};
52+
injector.mock(mocks);
53+
injector.require(['Magento_Vault/js/view/payment/method-renderer/vault'], function (Constr) {
54+
var params = {
55+
index: 'vaultIndex',
56+
item: {
57+
method: 'vault'
58+
}
59+
};
60+
61+
vault = new Constr(params);
62+
// eslint-disable-next-line max-nested-callbacks
63+
/** Stub */
64+
vault.isChecked = function () {
65+
return mocks['Magento_Checkout/js/model/quote'].paymentMethod() ?
66+
mocks['Magento_Checkout/js/model/quote'].paymentMethod().method : null;
67+
};
68+
done();
69+
});
70+
});
71+
72+
afterEach(function () {
73+
try {
74+
injector.remove();
75+
injector.clean();
76+
} catch (e) {
77+
}
78+
mocks['Magento_Checkout/js/model/quote'].billingAddress(null);
79+
mocks['Magento_Checkout/js/model/quote'].paymentMethod(null);
80+
});
81+
82+
describe('Magento_Vault/js/view/payment/method-renderer/vault', function () {
83+
84+
it('There is no payment method and billing address', function () {
85+
expect(vault.isButtonActive()).toBeFalsy();
86+
87+
expect(vault.isActive()).toBeFalsy();
88+
expect(vault.isPlaceOrderActionAllowed()).toBeFalsy();
89+
});
90+
91+
it('Payment method exist but place order action is not allowed', function () {
92+
vault.selectPaymentMethod();
93+
expect(mocks['Magento_Checkout/js/model/quote'].paymentMethod().method).toEqual('vaultIndex');
94+
95+
expect(vault.isButtonActive()).toBeFalsy();
96+
97+
expect(vault.isActive()).toBeTruthy();
98+
expect(vault.isPlaceOrderActionAllowed()).toBeFalsy();
99+
100+
});
101+
102+
it('Billing address exist but there is no selected payment method', function () {
103+
mocks['Magento_Checkout/js/model/quote'].billingAddress(billingAddress);
104+
105+
expect(vault.isButtonActive()).toBeFalsy();
106+
107+
expect(vault.isActive()).toBeFalsy();
108+
expect(vault.isPlaceOrderActionAllowed).toBeTruthy();
109+
});
110+
111+
it('Button is active', function () {
112+
vault.selectPaymentMethod();
113+
expect(mocks['Magento_Checkout/js/model/quote'].paymentMethod().method).toEqual('vaultIndex');
114+
115+
mocks['Magento_Checkout/js/model/quote'].billingAddress(billingAddress);
116+
117+
expect(vault.isButtonActive()).toBeTruthy();
118+
119+
expect(vault.isActive()).toBeTruthy();
120+
expect(vault.isPlaceOrderActionAllowed()).toBeTruthy();
121+
});
122+
});
123+
});

0 commit comments

Comments
 (0)