Skip to content

Commit c555627

Browse files
Chhandak.BaruaChhandak.Barua
authored andcommitted
ACP2E-3037: Checkout page Validation message incorrect.
1 parent 4295217 commit c555627

File tree

2 files changed

+124
-8
lines changed

2 files changed

+124
-8
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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', ['setSelectedBillingAddress', 'setNewCustomerBillingAddress']),
15+
createBillingAddress = jasmine.createSpy('createBillingAddress').and.callFake(function (addressData) {
16+
return {
17+
getKey: function () {
18+
return 'new-billing-address-key';
19+
}
20+
};
21+
}),
22+
selectBillingAddress = jasmine.createSpy('selectBillingAddress'),
23+
mocks = {
24+
'Magento_Checkout/js/checkout-data': checkoutData,
25+
'Magento_Checkout/js/action/create-billing-address': createBillingAddress,
26+
'Magento_Checkout/js/action/select-billing-address': selectBillingAddress,
27+
'Magento_Customer/js/model/customer': {
28+
isLoggedIn: function () {
29+
return true;
30+
}
31+
},
32+
'Magento_Checkout/js/model/quote': {
33+
billingAddress: ko.observable(null),
34+
shippingAddress: ko.observable(null),
35+
isVirtual: function () {
36+
return false;
37+
},
38+
/** Stub */
39+
getQuoteId: function () {},
40+
paymentMethod: ko.observable(null)
41+
},
42+
'Magento_Customer/js/customer-data': {
43+
get: function () {
44+
return function () {
45+
return {};
46+
};
47+
}
48+
},
49+
},
50+
lastSelectedBillingAddress = {
51+
city: 'Culver City',
52+
company: 'Magento',
53+
country_id: 'US',
54+
firstname: 'John',
55+
lastname: '',
56+
postcode: '90230',
57+
region: '',
58+
region_id: '12',
59+
street: {
60+
0: '6161 West Centinela Avenue',
61+
1: ''
62+
},
63+
telephone: '+15555555555'
64+
},
65+
billingAddress;
66+
67+
beforeEach(function (done) {
68+
window.checkoutConfig = {
69+
quoteData: {},
70+
storeCode: 'US',
71+
reloadOnBillingAddress: false,
72+
displayBillingOnPaymentMethod: true
73+
};
74+
75+
spyOn(mocks['Magento_Checkout/js/model/quote'], 'billingAddress').and.returnValue(lastSelectedBillingAddress);
76+
77+
injector.mock(mocks);
78+
injector.require(['Magento_Checkout/js/view/billing-address'], function (Constr) {
79+
billingAddress = new Constr;
80+
81+
billingAddress.source = {
82+
get: jasmine.createSpy('get').and.callFake(function (key) {
83+
if (key === billingAddress.dataScopePrefix + '.custom_attributes') {
84+
return true;
85+
} else if (key === 'params.invalid') {
86+
return true; // Simulate valid form data
87+
} else if (key === billingAddress.dataScopePrefix) {
88+
return lastSelectedBillingAddress; // Return mock address data
89+
}
90+
return null;
91+
}),
92+
set: jasmine.createSpy('set'),
93+
trigger: jasmine.createSpy('trigger').and.callFake(function (event) {
94+
if (event === billingAddress.dataScopePrefix + '.data.validate' || event === billingAddress.dataScopePrefix + '.custom_attributes.data.validate') {
95+
billingAddress.source.set('params.invalid', false); // Simulate valid form data
96+
}
97+
})
98+
};
99+
100+
done();
101+
});
102+
});
103+
104+
describe('Magento_Checkout/js/view/billing-address', function () {
105+
describe('"updateAddress" method', function () {
106+
it('should not call updateAddresses when form is invalid', function () {
107+
billingAddress.source.set.and.callFake(function (key, value) {
108+
if (key === 'params.invalid' && value === true) {
109+
billingAddress.source.get.and.callFake(function (key) {
110+
if (key === 'params.invalid') {
111+
return true; // Simulate invalid form data
112+
}
113+
return null;
114+
});
115+
}
116+
});
117+
spyOn(billingAddress, 'updateAddresses');
118+
billingAddress.updateAddress();
119+
expect(billingAddress.updateAddresses).not.toHaveBeenCalled();
120+
expect(selectBillingAddress).not.toHaveBeenCalled();
121+
});
122+
});
123+
});
124+
});

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,5 @@ define([
104104
expect(checkoutData.setNewCustomerBillingAddress).toHaveBeenCalledWith(lastSelectedBillingAddress);
105105
});
106106
});
107-
108-
describe('"updateAddress" method', function () {
109-
it('should call updateAddresses(true) when form is valid', function () {
110-
spyOn(billingAddress, 'updateAddresses');
111-
billingAddress.updateAddress();
112-
expect(billingAddress.updateAddresses).toHaveBeenCalledWith(true);
113-
});
114-
});
115107
});
116108
});

0 commit comments

Comments
 (0)