Skip to content

Commit 629cdef

Browse files
committed
Merge remote-tracking branch 'l3/MC-41334' into L3-PR-20210324
2 parents 30892b1 + 660f7be commit 629cdef

File tree

4 files changed

+213
-4
lines changed

4 files changed

+213
-4
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="OnePageCheckoutCancelEditingBillingAddress">
12+
<annotations>
13+
<features value="OnePageCheckout"/>
14+
<stories value="MC-39581: Billing Address empty after going back and forth between shipping and payment step"/>
15+
<title value="Billing Address empty after going back and forth between shipping and payment step"/>
16+
<description value="Check billing address editing cancelation during checkout on the payment step"/>
17+
<severity value="AVERAGE"/>
18+
<group value="checkout"/>
19+
</annotations>
20+
<before>
21+
<!-- Create Simple Product -->
22+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct">
23+
<field key="price">160</field>
24+
</createData>
25+
</before>
26+
<after>
27+
<!-- Delete created product -->
28+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
29+
</after>
30+
31+
<!-- Add Simple Product to cart -->
32+
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.custom_attributes[url_key]$$)}}" stepKey="navigateToSimpleProductPage"/>
33+
<waitForPageLoad stepKey="waitForSimpleProductPageLoad"/>
34+
<actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage">
35+
<argument name="productName" value="$$createSimpleProduct.name$$"/>
36+
</actionGroup>
37+
38+
<!-- Navigate to checkout -->
39+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
40+
<!-- Fill shipping address -->
41+
<actionGroup ref="GuestCheckoutFillingShippingSectionActionGroup" stepKey="guestCheckoutFillingShipping">
42+
<argument name="shippingMethod" value="Flat Rate"/>
43+
</actionGroup>
44+
45+
<!-- Change the address -->
46+
47+
<waitForElementVisible selector="{{CheckoutPaymentSection.billingAddressNotSameCheckbox}}" stepKey="waitForElementToBeVisible"/>
48+
<uncheckOption selector="{{CheckoutPaymentSection.billingAddressNotSameCheckbox}}" stepKey="uncheckSameBillingAndShippingAddress"/>
49+
<conditionalClick selector="{{CheckoutShippingSection.editActiveAddressButton}}" dependentSelector="{{CheckoutShippingSection.editActiveAddressButton}}" visible="true" stepKey="clickEditButton"/>
50+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
51+
52+
<!-- Fill in New Billing Address -->
53+
<actionGroup ref="StorefrontFillBillingAddressActionGroup" stepKey="fillBillingAddress">
54+
<argument name="address" value="US_Address_CA"/>
55+
</actionGroup>
56+
<selectOption selector="{{CheckoutPaymentSection.guestRegion}}" userInput="{{US_Address_CA.state}}" stepKey="selectRegion"/>
57+
<click selector="{{CheckoutPaymentSection.update}}" stepKey="clickOnUpdateButton"/>
58+
59+
60+
<!-- Edit Billing Address -->
61+
<click selector="{{CheckoutShippingSection.editAddressButton}}" stepKey="clickOnEditButton"/>
62+
<fillField selector="{{CheckoutPaymentSection.guestFirstName}}" userInput="" stepKey="enterEmptyFirstName"/>
63+
<fillField selector="{{CheckoutPaymentSection.guestLastName}}" userInput="" stepKey="enterEmptyLastName"/>
64+
65+
<!-- Cancel Editing Billing Address -->
66+
<click selector="{{CheckoutHeaderSection.shippingMethodStep}}" stepKey="goToShipping"/>
67+
<actionGroup ref="StorefrontCheckoutClickNextButtonActionGroup" stepKey="clickOnNextButton"/>
68+
69+
<!-- Place order -->
70+
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" stepKey="waitForPaymentSectionLoaded"/>
71+
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrderButton"/>
72+
<seeElement selector="{{CheckoutSuccessMainSection.success}}" stepKey="orderIsSuccessfullyPlaced"/>
73+
</test>
74+
</tests>

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ define([
1818
'Magento_Checkout/js/action/set-billing-address',
1919
'Magento_Ui/js/model/messageList',
2020
'mage/translate',
21-
'Magento_Checkout/js/model/billing-address-postcode-validator'
21+
'Magento_Checkout/js/model/billing-address-postcode-validator',
22+
'Magento_Checkout/js/model/address-converter'
2223
],
2324
function (
2425
ko,
@@ -35,11 +36,14 @@ function (
3536
setBillingAddressAction,
3637
globalMessageList,
3738
$t,
38-
billingAddressPostcodeValidator
39+
billingAddressPostcodeValidator,
40+
addressConverter
3941
) {
4042
'use strict';
4143

4244
var lastSelectedBillingAddress = null,
45+
addressUpadated = false,
46+
addressEdited = false,
4347
countryData = customerData.get('directory-data'),
4448
addressOptions = addressList().filter(function (address) {
4549
return address.getType() === 'customer-address';
@@ -140,6 +144,8 @@ function (
140144
updateAddress: function () {
141145
var addressData, newBillingAddress;
142146

147+
addressUpadated = true;
148+
143149
if (this.selectedAddress() && !this.isAddressFormVisible()) {
144150
selectBillingAddress(this.selectedAddress());
145151
checkoutData.setSelectedBillingAddress(this.selectedAddress().getKey());
@@ -172,6 +178,8 @@ function (
172178
* Edit address action
173179
*/
174180
editAddress: function () {
181+
addressUpadated = false;
182+
addressEdited = true;
175183
lastSelectedBillingAddress = quote.billingAddress();
176184
quote.billingAddress(null);
177185
this.isAddressDetailsVisible(false);
@@ -181,6 +189,7 @@ function (
181189
* Cancel address edit action
182190
*/
183191
cancelAddressEdit: function () {
192+
addressUpadated = true;
184193
this.restoreBillingAddress();
185194

186195
if (quote.billingAddress()) {
@@ -201,12 +210,26 @@ function (
201210
return quote.billingAddress() || lastSelectedBillingAddress;
202211
}),
203212

213+
/**
214+
* Check if Billing Address Changes should be canceled
215+
*/
216+
needCancelBillingAddressChanges: function () {
217+
if (addressEdited && !addressUpadated) {
218+
this.cancelAddressEdit();
219+
}
220+
},
221+
204222
/**
205223
* Restore billing address
206224
*/
207225
restoreBillingAddress: function () {
226+
var lastBillingAddress;
227+
208228
if (lastSelectedBillingAddress != null) {
209229
selectBillingAddress(lastSelectedBillingAddress);
230+
lastBillingAddress = addressConverter.quoteAddressToFormAddressData(lastSelectedBillingAddress);
231+
232+
checkoutData.setNewCustomerBillingAddress(lastBillingAddress);
210233
}
211234
},
212235

app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ define([
88
'underscore',
99
'ko',
1010
'uiComponent',
11-
'Magento_Checkout/js/model/step-navigator'
12-
], function ($, _, ko, Component, stepNavigator) {
11+
'Magento_Checkout/js/model/step-navigator',
12+
'Magento_Checkout/js/view/billing-address'
13+
], function ($, _, ko, Component, stepNavigator, billingAddress) {
1314
'use strict';
1415

1516
var steps = stepNavigator.steps;
@@ -52,6 +53,9 @@ define([
5253
* @param {Object} step
5354
*/
5455
navigateTo: function (step) {
56+
if (step.code === 'shipping') {
57+
billingAddress().needCancelBillingAddressChanges();
58+
}
5559
stepNavigator.navigateTo(step.code);
5660
},
5761

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
'squire',
9+
'ko'
10+
], function (Squire, ko) {
11+
'use strict';
12+
13+
var injector = new Squire(),
14+
checkoutData = jasmine.createSpyObj('checkoutData', ['setNewCustomerBillingAddress']),
15+
mocks = {
16+
'Magento_Checkout/js/checkout-data': checkoutData,
17+
'Magento_Customer/js/customer-data': {
18+
/** Stub */
19+
get: function () {}
20+
},
21+
'Magento_Checkout/js/model/quote': {
22+
/** Stub */
23+
getQuoteId: function () {},
24+
25+
billingAddress: ko.observable(null),
26+
27+
/** Stub */
28+
isVirtual: function () {
29+
return false;
30+
},
31+
32+
shippingAddress: ko.observable(null),
33+
paymentMethod: ko.observable(null)
34+
}
35+
},
36+
lastSelectedBillingAddress = {
37+
city: 'Culver City',
38+
company: 'Magento',
39+
country_id: 'US',// jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
40+
firstname: 'John',
41+
lastname: 'Doe',
42+
postcode: '90230',
43+
region: '',
44+
region_id: '12',// jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
45+
street: {
46+
0: '6161 West Centinela Avenue',
47+
1: ''
48+
},
49+
telephone: '+15555555555'
50+
},
51+
billingAddress;
52+
53+
beforeEach(function (done) {
54+
window.checkoutConfig = {
55+
quoteData: {},
56+
storeCode: 'US'
57+
};
58+
59+
spyOn(mocks['Magento_Checkout/js/model/quote'], 'billingAddress').and.returnValue(lastSelectedBillingAddress);
60+
61+
injector.mock(mocks);
62+
injector.require(['Magento_Checkout/js/view/billing-address'], function (Constr) {
63+
billingAddress = new Constr;
64+
65+
billingAddress.source = {
66+
/** Stub */
67+
get: function () {
68+
return [];
69+
},
70+
71+
/** Stub */
72+
set: function () {},
73+
74+
/** Stub */
75+
trigger: function () {}
76+
};
77+
78+
done();
79+
});
80+
});
81+
82+
describe('Magento_Checkout/js/view/billing-address', function () {
83+
describe('"needCancelBillingAddressChanges" method', function () {
84+
it('Test negative scenario', function () {
85+
spyOn(billingAddress, 'cancelAddressEdit');
86+
billingAddress.editAddress();
87+
billingAddress.updateAddress();
88+
billingAddress.needCancelBillingAddressChanges();
89+
expect(billingAddress.cancelAddressEdit).not.toHaveBeenCalled();
90+
});
91+
92+
it('Test that billing address editing was canceled automatically', function () {
93+
spyOn(billingAddress, 'cancelAddressEdit');
94+
billingAddress.editAddress();
95+
billingAddress.needCancelBillingAddressChanges();
96+
expect(billingAddress.cancelAddressEdit).toHaveBeenCalled();
97+
});
98+
});
99+
100+
describe('"restoreBillingAddress" method', function () {
101+
it('Test that lastSelectedBillingAddress was restored correctly', function () {
102+
billingAddress.editAddress();
103+
billingAddress.restoreBillingAddress();
104+
expect(checkoutData.setNewCustomerBillingAddress).toHaveBeenCalledWith(lastSelectedBillingAddress);
105+
});
106+
});
107+
});
108+
});

0 commit comments

Comments
 (0)