Skip to content

Commit 5a86f4b

Browse files
committed
Merge remote-tracking branch 'origin/MC-36226' into 2.4-develop-pr36
2 parents fa53b0f + 41c499f commit 5a86f4b

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ define([
5656
if (this.options.isMultipleCountriesAllowed) {
5757
this.element.parents('div.field').show();
5858
this.element.on('change', $.proxy(function (e) {
59+
// clear region inputs on country change
60+
$(this.options.regionListId).val('');
61+
$(this.options.regionInputId).val('');
5962
this._updateRegion($(e.target).val());
6063
}, this));
6164

@@ -165,9 +168,6 @@ define([
165168
this._clearError();
166169
this._checkRegionRequired(country);
167170

168-
$(regionList).find('option:selected').removeAttr('selected');
169-
regionInput.val('');
170-
171171
// Populate state/province dropdown list if available or use input box
172172
if (this.options.regionJson[country]) {
173173
this._removeSelectOptions(regionList);

dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/region-updater.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ define([
5151
'': '',
5252
'US': 'United States',
5353
'GB': 'United Kingdom',
54-
'DE': 'Germany'
54+
'DE': 'Germany',
55+
'IT': 'Italy'
5556
},
5657
regions = {
5758
'': 'Please select a region, state or province.'
@@ -202,5 +203,41 @@ define([
202203
expect($(regionSelectEl).is(':visible')).toBe(false);
203204
expect($(regionInputEl).is(':visible')).toBe(false);
204205
});
206+
it('Check that initial values are not overwritten - region input', function () {
207+
$(countryEl).val('GB');
208+
$(regionInputEl).val('Liverpool');
209+
$(postalCodeEl).val('L13 0AL');
210+
init();
211+
expect($(countryEl).val()).toBe('GB');
212+
expect($(regionInputEl).val()).toBe('Liverpool');
213+
expect($(postalCodeEl).val()).toBe('L13 0AL');
214+
});
215+
it('Check that initial values are not overwritten - region select', function () {
216+
$(countryEl).val('US');
217+
$(postalCodeEl).val('99501');
218+
init({
219+
defaultRegion: '2'
220+
});
221+
expect($(countryEl).val()).toBe('US');
222+
expect($(regionSelectEl).find('option:selected').text()).toBe('Alaska');
223+
expect($(postalCodeEl).val()).toBe('99501');
224+
});
225+
it('Check that region values are cleared out on country change - region input', function () {
226+
$(countryEl).val('GB');
227+
$(regionInputEl).val('Liverpool');
228+
init();
229+
$(countryEl).val('IT').change();
230+
expect($(countryEl).val()).toBe('IT');
231+
expect($(regionInputEl).val()).toBe('');
232+
});
233+
it('Check that region values are cleared out on country change - region select', function () {
234+
$(countryEl).val('US');
235+
init({
236+
defaultRegion: '2'
237+
});
238+
$(countryEl).val('DE').change();
239+
expect($(countryEl).val()).toBe('DE');
240+
expect($(regionSelectEl).val()).toBe('');
241+
});
205242
});
206243
});

0 commit comments

Comments
 (0)