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