Skip to content

Commit c3d8e90

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3171' into Tier4-Kings-PR-07-24-2024
2 parents a08db5e + 333f81c commit c3d8e90

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ function (
141141
* Update address action
142142
*/
143143
updateAddress: function () {
144-
var addressData, newBillingAddress;
144+
var addressData, newBillingAddress, needsToUpdateAddress;
145145

146+
needsToUpdateAddress = true;
146147
addressUpdated = true;
147148

148149
if (this.selectedAddress() && !this.isAddressFormVisible()) {
@@ -156,7 +157,9 @@ function (
156157
this.source.trigger(this.dataScopePrefix + '.custom_attributes.data.validate');
157158
}
158159

159-
if (!this.source.get('params.invalid')) {
160+
if (this.source.get('params.invalid')) {
161+
needsToUpdateAddress = false;
162+
} else {
160163
addressData = this.source.get(this.dataScopePrefix);
161164

162165
if (customer.isLoggedIn() && !this.customerHasAddresses) { //eslint-disable-line max-depth
@@ -168,9 +171,9 @@ function (
168171
selectBillingAddress(newBillingAddress);
169172
checkoutData.setSelectedBillingAddress(newBillingAddress.getKey());
170173
checkoutData.setNewCustomerBillingAddress(addressData);
171-
this.updateAddresses(true);
172174
}
173175
}
176+
this.updateAddresses(needsToUpdateAddress);
174177
},
175178

176179
/**

dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/billing-address-validate.test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ define([
107107

108108
describe('Magento_Checkout/js/view/billing-address', function () {
109109
describe('"updateAddress" method', function () {
110-
it('should not call updateAddresses when form is invalid', function () {
110+
it('should call updateAddresses when form is invalid with false', function () {
111111
billingAddress.source.set.and.callFake(function (key, value) {
112112
if (key === 'params.invalid' && value === true) {
113113
billingAddress.source.get.and.callFake(function () {
@@ -120,9 +120,25 @@ define([
120120
});
121121
spyOn(billingAddress, 'updateAddresses');
122122
billingAddress.updateAddress();
123-
expect(billingAddress.updateAddresses).not.toHaveBeenCalled();
123+
expect(billingAddress.updateAddresses).toHaveBeenCalledWith(false);
124124
expect(selectBillingAddress).not.toHaveBeenCalled();
125125
});
126+
127+
it('should call updateAddresses when form is valid with true', function () {
128+
billingAddress.source.get.and.callFake(function (key) {
129+
if (key === 'params.invalid') {
130+
return false; // Simulate valid form data
131+
} else if (key === billingAddress.dataScopePrefix) {
132+
return lastSelectedBillingAddress; // Return mock address data
133+
}
134+
return null;
135+
});
136+
137+
spyOn(billingAddress, 'updateAddresses');
138+
billingAddress.updateAddress();
139+
expect(billingAddress.updateAddresses).toHaveBeenCalledWith(true);
140+
expect(selectBillingAddress).toHaveBeenCalled();
141+
});
126142
});
127143
});
128144
});

0 commit comments

Comments
 (0)