@@ -160,6 +160,92 @@ define([
160160 jQueryAjax = undefined ;
161161 } ) ;
162162
163+ describe ( 'Testing syncAddressField method' , function ( ) {
164+ it ( 'Synchronize region and region_id fields display when called with field named "country"' , function ( ) {
165+ let form , billingCountryId , billingRegionId , billingRegion , billingCountryIdOption1 ,
166+ billingCountryIdOption2 , shippingCountryId , shippingRegionId , shippingRegion , billingRegionOption1 ,
167+ billingRegionOption2 , shippingCountryIdOption1 , shippingOption2 , shippingRegionOption1 ,
168+ shippingRegionOption2 ;
169+
170+ form = document . createElement ( 'form' ) ;
171+
172+ //create billing country id field
173+ billingCountryId = document . createElement ( 'select' ) ;
174+ billingCountryId . name = 'order[billing_address][country_id]' ;
175+ billingCountryIdOption1 = document . createElement ( 'option' ) ;
176+ billingCountryIdOption1 . value = 'USA' ;
177+ billingCountryIdOption1 . innerText = 'United States of America' ;
178+ billingCountryIdOption2 = document . createElement ( 'option' ) ;
179+ billingCountryIdOption2 . value = 'RO' ;
180+ billingCountryIdOption2 . innerText = 'Romania' ;
181+ billingCountryId . appendChild ( billingCountryIdOption1 ) ;
182+ billingCountryId . appendChild ( billingCountryIdOption2 ) ;
183+ form . appendChild ( billingCountryId ) ;
184+
185+ //create billing region id field
186+ billingRegionId = document . createElement ( 'select' ) ;
187+ billingRegionId . name = 'order[billing_address][region_id]' ;
188+ billingRegionId . id = 'order-billing_address_region_id' ;
189+ billingRegionOption1 = document . createElement ( 'option' ) ;
190+ billingRegionOption1 . value = 'NY' ;
191+ billingRegionOption1 . innerText = 'New York' ;
192+ billingRegionOption2 = document . createElement ( 'option' ) ;
193+ billingRegionOption2 . value = 'TX' ;
194+ billingRegionOption2 . innerText = 'Texas' ;
195+ billingRegionId . appendChild ( billingRegionOption1 ) ;
196+ billingRegionId . appendChild ( billingRegionOption2 ) ;
197+ form . appendChild ( billingRegionId ) ;
198+
199+ //create hidden billing region field
200+ billingRegion = document . createElement ( 'input' ) ;
201+ billingRegion . name = 'order[billing_address][region]' ;
202+ billingRegion . id = 'order-billing_address_region' ;
203+ billingRegion . style . display = 'none' ;
204+ form . appendChild ( billingRegion ) ;
205+
206+ //create shipping country id field
207+ shippingCountryId = document . createElement ( 'select' ) ;
208+ shippingCountryId . name = 'order[shipping_address][country_id]' ;
209+ shippingCountryIdOption1 = document . createElement ( 'option' ) ;
210+ shippingCountryIdOption1 . value = 'USA' ;
211+ shippingCountryIdOption1 . innerText = 'United States of America' ;
212+ shippingOption2 = document . createElement ( 'option' ) ;
213+ shippingOption2 . value = 'RO' ;
214+ shippingOption2 . innerText = 'Romania' ;
215+ shippingCountryId . appendChild ( shippingCountryIdOption1 ) ;
216+ shippingCountryId . appendChild ( shippingOption2 ) ;
217+ shippingCountryId . value = 'RO' ;
218+ form . appendChild ( shippingCountryId ) ;
219+
220+ //create shipping region id field
221+ shippingRegionId = document . createElement ( 'select' ) ;
222+ shippingRegionId . name = 'order[shipping_address][region_id]' ;
223+ shippingRegionId . id = 'order-shipping_address_region_id' ;
224+ shippingRegionOption1 = document . createElement ( 'option' ) ;
225+ shippingRegionOption1 . value = 'B' ;
226+ shippingRegionOption1 . innerText = 'Bucuresti' ;
227+ shippingRegionOption2 = document . createElement ( 'option' ) ;
228+ shippingRegionOption2 . value = 'CT' ;
229+ shippingRegionOption2 . innerText = 'Constanta' ;
230+ shippingRegionId . appendChild ( shippingRegionOption1 ) ;
231+ shippingRegionId . appendChild ( shippingRegionOption2 ) ;
232+ form . appendChild ( shippingRegionId ) ;
233+
234+ //create shipping region field
235+ shippingRegion = document . createElement ( 'input' ) ;
236+ shippingRegion . name = 'order[shipping_address][region]' ;
237+ shippingRegion . id = 'order-shipping_address_region' ;
238+ form . appendChild ( shippingRegion ) ;
239+
240+ document . body . appendChild ( form ) ;
241+ order = new window . AdminOrder ( { } ) ;
242+ order . syncAddressField ( form , 'order[billing_address][country_id]' , billingCountryId ) ;
243+
244+ expect ( shippingCountryId . value ) . toEqual ( 'USA' ) ;
245+ expect ( shippingRegion . style . display ) . toEqual ( 'none' ) ;
246+ } ) ;
247+ } ) ;
248+
163249 it ( 'test that setStoreId calls loadArea with a callback' , function ( ) {
164250 init ( ) ;
165251 spyOn ( order , 'loadArea' ) . and . callFake ( function ( ) {
0 commit comments