OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @fileoverview Runs the Polymer Autofill Settings tests. */ | 5 /** @fileoverview Runs the Polymer Autofill Settings tests. */ |
6 | 6 |
7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ | 7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ |
8 var ROOT_PATH = '../../../../../'; | 8 var ROOT_PATH = '../../../../../'; |
9 | 9 |
10 // Polymer BrowserTest fixture. | 10 // Polymer BrowserTest fixture. |
11 GEN_INCLUDE([ | 11 GEN_INCLUDE([ |
12 ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js', | 12 ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js', |
13 ROOT_PATH + | 13 ROOT_PATH + |
14 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js', | 14 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js', |
15 ROOT_PATH + 'ui/webui/resources/js/load_time_data.js', | 15 ROOT_PATH + 'ui/webui/resources/js/load_time_data.js', |
16 ]); | 16 ]); |
17 | 17 |
18 /** | 18 /** |
19 * Test implementation. | |
20 * @implements {settings.address.CountryDetailManager} | |
21 * @constructor | |
22 */ | |
23 function CountryDetailManagerTestImpl() {} | |
24 CountryDetailManagerTestImpl.prototype = { | |
25 /** @override */ | |
26 getCountryList: function() { | |
27 return new Promise(function(resolve) { | |
28 resolve([ | |
29 {name: 'United States', countryCode: 'US'}, // Default test country. | |
30 {name: 'Israel', countryCode: 'IL'}, | |
31 {name: 'United Kingdom', countryCode: 'GB'}, | |
32 ]); | |
33 }); | |
34 }, | |
35 | |
36 /** @override */ | |
37 getAddressFormat: function(countryCode) { | |
38 return new Promise(function(resolve) { | |
39 chrome.autofillPrivate.getAddressComponents(countryCode, resolve); | |
40 }); | |
41 }, | |
42 }; | |
43 | |
44 /** | |
45 * Will call |loopBody| for each item in |items|. Will only move to the next | |
46 * item after the promise from |loopBody| resolves. | |
47 * @param {!Array<Object>} items | |
48 * @param {!function(!Object):!Promise} loopBody | |
49 * @return {!Promise} | |
50 */ | |
51 function asyncForEach(items, loopBody) { | |
52 return new Promise(function(finish) { | |
53 var index = 0; | |
54 | |
55 function loop() { | |
56 var item = items[index++]; | |
57 if (item) | |
58 loopBody(item).then(loop); | |
59 else | |
60 finish(); | |
61 }; | |
62 | |
63 loop(); | |
64 }); | |
65 } | |
66 | |
67 /** | |
68 * Resolves the promise after the element fires the expected event. Will add and | |
69 * remove the listener so it is only triggered once. |causeEvent| is called | |
70 * after adding a listener to make sure that the event is captured. | |
71 * @param {!Element} element | |
72 * @param {string} eventName | |
73 * @param {function():void} causeEvent | |
74 * @return {!Promise} | |
75 */ | |
76 function expectEvent(element, eventName, causeEvent) { | |
77 return new Promise(function(resolve) { | |
78 var callback = function() { | |
79 element.removeEventListener(eventName, callback); | |
80 resolve.apply(this, arguments); | |
81 }; | |
82 element.addEventListener(eventName, callback); | |
83 causeEvent(); | |
84 }); | |
85 } | |
86 | |
87 /** | |
88 * @constructor | 19 * @constructor |
89 * @extends {PolymerTest} | 20 * @extends {PolymerTest} |
90 */ | 21 */ |
91 function SettingsAutofillSectionBrowserTest() {} | 22 function SettingsAutofillSectionBrowserTest() {} |
92 | 23 |
93 SettingsAutofillSectionBrowserTest.prototype = { | 24 SettingsAutofillSectionBrowserTest.prototype = { |
94 __proto__: PolymerTest.prototype, | 25 __proto__: PolymerTest.prototype, |
95 | 26 |
96 /** @override */ | 27 /** @override */ |
97 browsePreload: | 28 browsePreload: |
98 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', | 29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', |
99 | 30 |
100 /** @override */ | 31 /** @override */ |
101 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | 32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
102 | 33 |
103 i18nStrings: { | |
104 addAddressTitle: 'add-title', | |
105 addCreditCardTitle: 'add-title', | |
106 editAddressTitle: 'edit-title', | |
107 editCreditCardTitle: 'edit-title', | |
108 }, | |
109 | |
110 /** @override */ | 34 /** @override */ |
111 setUp: function() { | 35 setUp: function() { |
112 PolymerTest.prototype.setUp.call(this); | 36 PolymerTest.prototype.setUp.call(this); |
113 | 37 |
114 // Test is run on an individual element that won't have a page language. | 38 // Test is run on an individual element that won't have a page language. |
115 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); | 39 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
116 | 40 |
117 // Faking 'strings.js' for this test. | 41 // Faking 'strings.js' for this test. |
118 loadTimeData.data = this.i18nStrings; | 42 loadTimeData.data = { |
119 | 43 editCreditCardTitle: 'edit-title', |
120 settings.address.CountryDetailManagerImpl.instance_ = | 44 addCreditCardTitle: 'add-title' |
121 new CountryDetailManagerTestImpl(); | 45 }; |
122 }, | 46 }, |
123 | 47 |
124 /** | 48 /** |
125 * Allow the iron-list to be sized properly. | 49 * Allow the iron-list to be sized properly. |
126 * @param {!Object} autofillSection | 50 * @param {!Object} autofillSection |
127 * @private | 51 * @private |
128 */ | 52 */ |
129 flushAutofillSection_: function(autofillSection) { | 53 flushAutofillSection_: function(autofillSection) { |
130 autofillSection.$.addressList.notifyResize(); | 54 autofillSection.$.addressList.notifyResize(); |
131 autofillSection.$.creditCardList.notifyResize(); | 55 autofillSection.$.creditCardList.notifyResize(); |
(...skipping 10 matching lines...) Expand all Loading... |
142 createAutofillSection_: function(addresses, creditCards) { | 66 createAutofillSection_: function(addresses, creditCards) { |
143 var section = document.createElement('settings-autofill-section'); | 67 var section = document.createElement('settings-autofill-section'); |
144 section.addresses = addresses; | 68 section.addresses = addresses; |
145 section.creditCards = creditCards; | 69 section.creditCards = creditCards; |
146 document.body.appendChild(section); | 70 document.body.appendChild(section); |
147 this.flushAutofillSection_(section); | 71 this.flushAutofillSection_(section); |
148 return section; | 72 return section; |
149 }, | 73 }, |
150 | 74 |
151 /** | 75 /** |
152 * Creates the Edit Address dialog and fulfills the promise when the dialog | |
153 * has actually opened. | |
154 * @param {!chrome.autofillPrivate.AddressEntry} address | |
155 * @return {!Promise<Object>} | |
156 */ | |
157 createAddressDialog_: function(address) { | |
158 return new Promise(function(resolve) { | |
159 var section = document.createElement('settings-address-edit-dialog'); | |
160 document.body.appendChild(section); | |
161 var onOpen = function() { | |
162 resolve(section); | |
163 }; | |
164 section.addEventListener('iron-overlay-opened', onOpen); | |
165 | |
166 // |setTimeout| allows the dialog to async get the list of countries | |
167 // before running any tests. | |
168 window.setTimeout(function() { | |
169 section.open(address); // Opening the dialog will add the item. | |
170 Polymer.dom.flush(); | |
171 }, 0); | |
172 }); | |
173 }, | |
174 | |
175 /** | |
176 * Creates the Edit Credit Card dialog. | 76 * Creates the Edit Credit Card dialog. |
177 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem | 77 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem |
178 * @return {!Object} | 78 * @return {!Object} |
179 */ | 79 */ |
180 createCreditCardDialog_: function(creditCardItem) { | 80 createCreditCardDialog_: function(creditCardItem) { |
181 var section = document.createElement('settings-credit-card-edit-dialog'); | 81 var section = document.createElement('settings-credit-card-edit-dialog'); |
182 document.body.appendChild(section); | 82 document.body.appendChild(section); |
183 section.open(creditCardItem); // Opening the dialog will add the item. | 83 section.open(creditCardItem); // Opening the dialog will add the item. |
184 Polymer.dom.flush(); | 84 Polymer.dom.flush(); |
185 return section; | 85 return section; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 done(); | 203 done(); |
304 }); | 204 }); |
305 | 205 |
306 MockInteractions.tap(creditCardDialog.$.saveButton); | 206 MockInteractions.tap(creditCardDialog.$.saveButton); |
307 }), | 207 }), |
308 | 208 |
309 test('verifyCancelCreditCardEdit', function(done) { | 209 test('verifyCancelCreditCardEdit', function(done) { |
310 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | 210 var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
311 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 211 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
312 | 212 |
313 creditCardDialog.addEventListener('save-credit-card', function() { | 213 creditCardDialog.addEventListener('save-credit-card', function(event) { |
314 // Fail the test because the save event should not be called when cancel | 214 // Fail the test because the save event should not be called when cancel |
315 // is clicked. | 215 // is clicked. |
316 assertTrue(false); | 216 assertTrue(false); |
317 done(); | 217 done(); |
318 }); | 218 }); |
319 | 219 |
320 creditCardDialog.addEventListener('iron-overlay-closed', function() { | 220 creditCardDialog.addEventListener('iron-overlay-closed', function(event) { |
321 // Test is |done| in a timeout in order to ensure that | 221 // Test is |done| in a timeout in order to ensure that |
322 // 'save-credit-card' is NOT fired after this test. | 222 // 'save-credit-card' is NOT fired after this test. |
323 window.setTimeout(done, 100); | 223 window.setTimeout(done, 100); |
324 }); | 224 }); |
325 | 225 |
326 MockInteractions.tap(creditCardDialog.$.cancelButton); | 226 MockInteractions.tap(creditCardDialog.$.cancelButton); |
327 }), | 227 }), |
328 | 228 |
329 test('verifyAddressCount', function() { | 229 test('verifyAddressCount', function() { |
330 var addresses = [ | 230 var addresses = [ |
(...skipping 20 matching lines...) Expand all Loading... |
351 var addressList = section.$.addressList; | 251 var addressList = section.$.addressList; |
352 var row = addressList.children[1]; // Skip over the template. | 252 var row = addressList.children[1]; // Skip over the template. |
353 assertTrue(!!row); | 253 assertTrue(!!row); |
354 | 254 |
355 var addressSummary = address.metadata.summaryLabel + | 255 var addressSummary = address.metadata.summaryLabel + |
356 address.metadata.summarySublabel; | 256 address.metadata.summarySublabel; |
357 | 257 |
358 assertEquals(addressSummary, | 258 assertEquals(addressSummary, |
359 row.querySelector('#addressSummary').textContent); | 259 row.querySelector('#addressSummary').textContent); |
360 }); | 260 }); |
361 | |
362 test('verifyAddAddressDialog', function() { | |
363 return self.createAddressDialog_( | |
364 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { | |
365 var title = dialog.$$('.title'); | |
366 assertEquals(self.i18nStrings.addAddressTitle, title.textContent); | |
367 // Shouldn't be possible to save until something is typed in. | |
368 assertTrue(dialog.$.saveButton.disabled); | |
369 }); | |
370 }); | |
371 | |
372 test('verifyEditAddressDialog', function() { | |
373 return self.createAddressDialog_( | |
374 FakeDataMaker.addressEntry()).then(function(dialog) { | |
375 var title = dialog.$$('.title'); | |
376 assertEquals(self.i18nStrings.editAddressTitle, title.textContent); | |
377 // Should be possible to save when editing because fields are populated. | |
378 assertFalse(dialog.$.saveButton.disabled); | |
379 }); | |
380 }); | |
381 | |
382 test('verifyCountryIsSaved', function() { | |
383 var address = FakeDataMaker.emptyAddressEntry(); | |
384 return self.createAddressDialog_(address).then(function(dialog) { | |
385 assertEquals(undefined, dialog.$.countryList.selected); | |
386 assertEquals(undefined, address.countryCode); | |
387 dialog.$.countryList.selected = 'US'; | |
388 Polymer.dom.flush(); | |
389 assertEquals('US', dialog.$.countryList.selected); | |
390 assertEquals('US', address.countryCode); | |
391 }); | |
392 }); | |
393 | |
394 test('verifyPhoneAndEmailAreSaved', function() { | |
395 var address = FakeDataMaker.emptyAddressEntry(); | |
396 return self.createAddressDialog_(address).then(function(dialog) { | |
397 assertEquals('', dialog.$.phoneInput.value); | |
398 assertFalse(!!(address.phoneNumbers && address.phoneNumbers[0])); | |
399 | |
400 assertEquals('', dialog.$.emailInput.value); | |
401 assertFalse(!!(address.emailAddresses && address.emailAddresses[0])); | |
402 | |
403 var phoneNumber = '(555) 555-5555'; | |
404 var emailAddress = 'no-reply@chromium.org'; | |
405 | |
406 dialog.$.phoneInput.value = phoneNumber; | |
407 dialog.$.emailInput.value = emailAddress; | |
408 | |
409 Polymer.dom.flush(); | |
410 | |
411 assertEquals(phoneNumber, dialog.$.phoneInput.value); | |
412 assertEquals(phoneNumber, address.phoneNumbers[0]); | |
413 | |
414 assertEquals(emailAddress, dialog.$.emailInput.value); | |
415 assertEquals(emailAddress, address.emailAddresses[0]); | |
416 }); | |
417 }); | |
418 | |
419 // Test will set a value of 'foo' in each text field and verify that the | |
420 // save button is enabled, then it will clear the field and verify that the | |
421 // save button is disabled. Test passes after all elements have been tested. | |
422 test('verifySaveIsNotClickableIfAllInputFieldsAreEmpty', function() { | |
423 return self.createAddressDialog_( | |
424 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { | |
425 var saveButton = dialog.$.saveButton; | |
426 var testElements = | |
427 dialog.$.dialog.querySelectorAll('paper-input,paper-textarea'); | |
428 | |
429 // Default country is 'US' expecting: Name, Organization, | |
430 // Street address, City, State, ZIP code, Phone, and Email. | |
431 assertEquals(8, testElements.length); | |
432 | |
433 return asyncForEach(testElements, function(element) { | |
434 return expectEvent(dialog, 'on-update-can-save', function() { | |
435 assertTrue(saveButton.disabled); | |
436 element.value = 'foo'; | |
437 }).then(function() { | |
438 return expectEvent(dialog, 'on-update-can-save', function() { | |
439 assertFalse(saveButton.disabled); | |
440 element.value = ''; | |
441 }); | |
442 }).then(function() { | |
443 assertTrue(saveButton.disabled); | |
444 }); | |
445 }); | |
446 }); | |
447 }); | |
448 | |
449 // Setting the country should allow the address to be saved. | |
450 test('verifySaveIsNotClickableIfCountryNotSet', function() { | |
451 return self.createAddressDialog_( | |
452 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { | |
453 var saveButton = dialog.$.saveButton; | |
454 var countries = dialog.$.countryList; | |
455 | |
456 return expectEvent(dialog, 'on-update-can-save', function() { | |
457 assertTrue(saveButton.disabled); | |
458 countries.selected = 'US'; | |
459 }).then(function() { | |
460 assertFalse(saveButton.disabled); | |
461 countries.selected = ''; | |
462 }).then(function() { | |
463 assertTrue(saveButton.disabled); | |
464 }); | |
465 }); | |
466 }); | |
467 | |
468 // Test will timeout if save-address event is not fired. | |
469 test('verifyDefaultCountryIsAppliedWhenSaving', function() { | |
470 var address = FakeDataMaker.emptyAddressEntry(); | |
471 address.companyName = 'Google'; | |
472 return self.createAddressDialog_(address).then(function(dialog) { | |
473 return expectEvent(dialog, 'save-address', function() { | |
474 // Verify |countryCode| is not set. | |
475 assertEquals(undefined, address.countryCode); | |
476 MockInteractions.tap(dialog.$.saveButton); | |
477 }).then(function(event) { | |
478 // 'US' is the default country for these tests. | |
479 assertEquals('US', event.detail.countryCode); | |
480 }); | |
481 }); | |
482 }); | |
483 | |
484 test('verifyCancelDoesNotSaveAddress', function(done) { | |
485 self.createAddressDialog_( | |
486 FakeDataMaker.addressEntry()).then(function(dialog) { | |
487 dialog.addEventListener('save-address', function() { | |
488 // Fail the test because the save event should not be called when | |
489 // cancel is clicked. | |
490 assertTrue(false); | |
491 done(); | |
492 }); | |
493 | |
494 dialog.addEventListener('iron-overlay-closed', function() { | |
495 // Test is |done| in a timeout in order to ensure that | |
496 // 'save-address' is NOT fired after this test. | |
497 window.setTimeout(done, 100); | |
498 }); | |
499 | |
500 MockInteractions.tap(dialog.$.cancelButton); | |
501 }); | |
502 }); | |
503 | |
504 // US address has 3 fields on the same line. | |
505 test('verifyEditingUSAddress', function() { | |
506 var address = FakeDataMaker.emptyAddressEntry(); | |
507 | |
508 address.fullNames = [ 'Name' ]; | |
509 address.companyName = 'Organization'; | |
510 address.addressLines = 'Street address'; | |
511 address.addressLevel2 = 'City'; | |
512 address.addressLevel1 = 'State'; | |
513 address.postalCode = 'ZIP code'; | |
514 address.countryCode = 'US'; | |
515 address.phoneNumbers = [ 'Phone' ]; | |
516 address.emailAddresses = [ 'Email' ]; | |
517 | |
518 return self.createAddressDialog_(address).then(function(dialog) { | |
519 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
520 assertEquals(6, rows.length); | |
521 | |
522 // Name | |
523 var row = rows[0]; | |
524 var cols = row.querySelectorAll('.address-column'); | |
525 assertEquals(1, cols.length); | |
526 assertEquals(address.fullNames[0], cols[0].value); | |
527 // Organization | |
528 row = rows[1]; | |
529 cols = row.querySelectorAll('.address-column'); | |
530 assertEquals(1, cols.length); | |
531 assertEquals(address.companyName, cols[0].value); | |
532 // Street address | |
533 row = rows[2]; | |
534 cols = row.querySelectorAll('.address-column'); | |
535 assertEquals(1, cols.length); | |
536 assertEquals(address.addressLines, cols[0].value); | |
537 // City, State, ZIP code | |
538 row = rows[3]; | |
539 cols = row.querySelectorAll('.address-column'); | |
540 assertEquals(3, cols.length); | |
541 assertEquals(address.addressLevel2, cols[0].value); | |
542 assertEquals(address.addressLevel1, cols[1].value); | |
543 assertEquals(address.postalCode, cols[2].value); | |
544 // Country | |
545 row = rows[4]; | |
546 cols = row.querySelectorAll('.address-column'); | |
547 assertEquals(1, cols.length); | |
548 assertEquals('United States', cols[0].value); | |
549 // Phone, Email | |
550 row = rows[5]; | |
551 cols = row.querySelectorAll('.address-column'); | |
552 assertEquals(2, cols.length); | |
553 assertEquals(address.phoneNumbers[0], cols[0].value); | |
554 assertEquals(address.emailAddresses[0], cols[1].value); | |
555 }); | |
556 }); | |
557 | |
558 // GB address has 1 field per line for all lines that change. | |
559 test('verifyEditingGBAddress', function() { | |
560 var address = FakeDataMaker.emptyAddressEntry(); | |
561 | |
562 address.fullNames = [ 'Name' ]; | |
563 address.companyName = 'Organization'; | |
564 address.addressLines = 'Street address'; | |
565 address.addressLevel2 = 'Post town'; | |
566 address.addressLevel1 = 'County'; | |
567 address.postalCode = 'Postal code'; | |
568 address.countryCode = 'GB'; | |
569 address.phoneNumbers = [ 'Phone' ]; | |
570 address.emailAddresses = [ 'Email' ]; | |
571 | |
572 return self.createAddressDialog_(address).then(function(dialog) { | |
573 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
574 assertEquals(8, rows.length); | |
575 | |
576 // Name | |
577 var row = rows[0]; | |
578 var cols = row.querySelectorAll('.address-column'); | |
579 assertEquals(1, cols.length); | |
580 assertEquals(address.fullNames[0], cols[0].value); | |
581 // Organization | |
582 row = rows[1]; | |
583 cols = row.querySelectorAll('.address-column'); | |
584 assertEquals(1, cols.length); | |
585 assertEquals(address.companyName, cols[0].value); | |
586 // Street address | |
587 row = rows[2]; | |
588 cols = row.querySelectorAll('.address-column'); | |
589 assertEquals(1, cols.length); | |
590 assertEquals(address.addressLines, cols[0].value); | |
591 // Post Town | |
592 row = rows[3]; | |
593 cols = row.querySelectorAll('.address-column'); | |
594 assertEquals(1, cols.length); | |
595 assertEquals(address.addressLevel2, cols[0].value); | |
596 // County | |
597 row = rows[4]; | |
598 cols = row.querySelectorAll('.address-column'); | |
599 assertEquals(1, cols.length); | |
600 assertEquals(address.addressLevel1, cols[0].value); | |
601 // Postal code | |
602 row = rows[5]; | |
603 cols = row.querySelectorAll('.address-column'); | |
604 assertEquals(1, cols.length); | |
605 assertEquals(address.postalCode, cols[0].value); | |
606 // Country | |
607 row = rows[6]; | |
608 cols = row.querySelectorAll('.address-column'); | |
609 assertEquals(1, cols.length); | |
610 assertEquals('United Kingdom', cols[0].value); | |
611 // Phone, Email | |
612 row = rows[7]; | |
613 cols = row.querySelectorAll('.address-column'); | |
614 assertEquals(2, cols.length); | |
615 assertEquals(address.phoneNumbers[0], cols[0].value); | |
616 assertEquals(address.emailAddresses[0], cols[1].value); | |
617 }); | |
618 }); | |
619 | |
620 // IL address has 2 fields on the same line and is an RTL locale. | |
621 // RTL locale shouldn't affect this test. | |
622 test('verifyEditingILAddress', function() { | |
623 var address = FakeDataMaker.emptyAddressEntry(); | |
624 | |
625 address.fullNames = [ 'Name' ]; | |
626 address.companyName = 'Organization'; | |
627 address.addressLines = 'Street address'; | |
628 address.addressLevel2 = 'City'; | |
629 address.postalCode = 'Postal code'; | |
630 address.countryCode = 'IL'; | |
631 address.phoneNumbers = [ 'Phone' ]; | |
632 address.emailAddresses = [ 'Email' ]; | |
633 | |
634 return self.createAddressDialog_(address).then(function(dialog) { | |
635 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
636 assertEquals(6, rows.length); | |
637 | |
638 // Name | |
639 var row = rows[0]; | |
640 var cols = row.querySelectorAll('.address-column'); | |
641 assertEquals(1, cols.length); | |
642 assertEquals(address.fullNames[0], cols[0].value); | |
643 // Organization | |
644 row = rows[1]; | |
645 cols = row.querySelectorAll('.address-column'); | |
646 assertEquals(1, cols.length); | |
647 assertEquals(address.companyName, cols[0].value); | |
648 // Street address | |
649 row = rows[2]; | |
650 cols = row.querySelectorAll('.address-column'); | |
651 assertEquals(1, cols.length); | |
652 assertEquals(address.addressLines, cols[0].value); | |
653 // City, Postal code | |
654 row = rows[3]; | |
655 cols = row.querySelectorAll('.address-column'); | |
656 assertEquals(2, cols.length); | |
657 assertEquals(address.addressLevel2, cols[0].value); | |
658 assertEquals(address.postalCode, cols[1].value); | |
659 // Country | |
660 row = rows[4]; | |
661 cols = row.querySelectorAll('.address-column'); | |
662 assertEquals(1, cols.length); | |
663 assertEquals('Israel', cols[0].value); | |
664 // Phone, Email | |
665 row = rows[5]; | |
666 cols = row.querySelectorAll('.address-column'); | |
667 assertEquals(2, cols.length); | |
668 assertEquals(address.phoneNumbers[0], cols[0].value); | |
669 assertEquals(address.emailAddresses[0], cols[1].value); | |
670 }); | |
671 }); | |
672 | |
673 // US has an extra field 'State'. Validate that this field is | |
674 // persisted when switching to IL then back to US. | |
675 test('verifyAddressPersistanceWhenSwitchingCountries', function() { | |
676 var address = FakeDataMaker.emptyAddressEntry(); | |
677 address.countryCode = 'US'; | |
678 | |
679 return self.createAddressDialog_(address).then(function(dialog) { | |
680 var city = 'Los Angeles'; | |
681 var state = 'CA'; | |
682 var zip = '90291'; | |
683 | |
684 return expectEvent(dialog, 'on-update-address-wrapper', function() { | |
685 // US: | |
686 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
687 assertEquals(6, rows.length); | |
688 | |
689 // City, State, ZIP code | |
690 var row = rows[3]; | |
691 var cols = row.querySelectorAll('.address-column'); | |
692 assertEquals(3, cols.length); | |
693 cols[0].value = city; | |
694 cols[1].value = state; | |
695 cols[2].value = zip; | |
696 | |
697 dialog.$.countryList.selected = 'IL'; | |
698 }).then(function() { | |
699 return expectEvent(dialog, 'on-update-address-wrapper', function() { | |
700 // IL: | |
701 rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
702 assertEquals(6, rows.length); | |
703 | |
704 // City, Postal code | |
705 row = rows[3]; | |
706 cols = row.querySelectorAll('.address-column'); | |
707 assertEquals(2, cols.length); | |
708 assertEquals(city, cols[0].value); | |
709 assertEquals(zip, cols[1].value); | |
710 | |
711 dialog.$.countryList.selected = 'US'; | |
712 }); | |
713 }).then(function() { | |
714 // US: | |
715 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
716 assertEquals(6, rows.length); | |
717 | |
718 // City, State, ZIP code | |
719 row = rows[3]; | |
720 cols = row.querySelectorAll('.address-column'); | |
721 assertEquals(3, cols.length); | |
722 assertEquals(city, cols[0].value); | |
723 assertEquals(state, cols[1].value); | |
724 assertEquals(zip, cols[2].value); | |
725 }); | |
726 }); | |
727 }); | |
728 }); | 261 }); |
729 | 262 |
730 mocha.run(); | 263 mocha.run(); |
731 }); | 264 }); |
OLD | NEW |