Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/test/data/webui/settings/settings_autofill_section_browsertest.js

Issue 2079853002: Add Edit/Create Address Dialog to MD Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix chromium_presubmit Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.AddressEditDialog.CountryInformationHelper}
21 * @constructor
22 */
23 function CountryInformationHelperTestImpl() {}
24 CountryInformationHelperTestImpl.prototype = {
25 /** @override */
26 getCountryList: function(callback) {
27 callback([
28 {name: 'United States', countryCode: 'US'},
29 {name: undefined, countryCode: undefined}, // Spacer.
michaelpg 2016/06/22 00:25:14 oh, I see. Should the browser/browser proxy really
hcarmona 2016/06/24 18:27:51 Spacer is provided by API to keep the default sepa
30 {name: 'Israel', countryCode: 'IL'},
31 {name: 'United Kingdom', countryCode: 'GB'},
32 {name: 'United States', countryCode: 'US'},
33 ]);
34 },
35
36 /** @override */
37 getAddressFormat: function(countryCode, callback) {
38 chrome.autofillPrivate.getAddressComponents(countryCode || '', callback);
39 },
40 };
41
42 /**
19 * @constructor 43 * @constructor
20 * @extends {PolymerTest} 44 * @extends {PolymerTest}
21 */ 45 */
22 function SettingsAutofillSectionBrowserTest() {} 46 function SettingsAutofillSectionBrowserTest() {}
23 47
24 SettingsAutofillSectionBrowserTest.prototype = { 48 SettingsAutofillSectionBrowserTest.prototype = {
25 __proto__: PolymerTest.prototype, 49 __proto__: PolymerTest.prototype,
26 50
27 /** @override */ 51 /** @override */
28 browsePreload: 52 browsePreload:
29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', 53 'chrome://md-settings/passwords_and_forms_page/autofill_section.html',
30 54
31 /** @override */ 55 /** @override */
32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), 56 extraLibraries: PolymerTest.getLibraries(ROOT_PATH),
33 57
58 i18nStrings: {
59 addAddressTitle: 'add-title',
60 addCreditCardTitle: 'add-title',
61 editAddressTitle: 'add-title',
michaelpg 2016/06/22 00:25:14 edit-title?
hcarmona 2016/06/24 18:27:51 Done.
62 editCreditCardTitle: 'edit-title',
63 },
64
34 /** @override */ 65 /** @override */
35 setUp: function() { 66 setUp: function() {
36 PolymerTest.prototype.setUp.call(this); 67 PolymerTest.prototype.setUp.call(this);
37 68
38 // Test is run on an individual element that won't have a page language. 69 // Test is run on an individual element that won't have a page language.
39 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); 70 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing');
40 71
41 // Faking 'strings.js' for this test. 72 // Faking 'strings.js' for this test.
42 loadTimeData.data = { 73 loadTimeData.data = this.i18nStrings;
43 editCreditCardTitle: 'edit-title', 74
44 addCreditCardTitle: 'add-title' 75 settings.AddressEditDialog.CountryInformationHelperImpl.instance_ =
45 }; 76 new CountryInformationHelperTestImpl();
46 }, 77 },
47 78
48 /** 79 /**
49 * Allow the iron-list to be sized properly. 80 * Allow the iron-list to be sized properly.
50 * @param {!Object} autofillSection 81 * @param {!Object} autofillSection
51 * @private 82 * @private
52 */ 83 */
53 flushAutofillSection_: function(autofillSection) { 84 flushAutofillSection_: function(autofillSection) {
54 autofillSection.$.addressList.notifyResize(); 85 autofillSection.$.addressList.notifyResize();
55 autofillSection.$.creditCardList.notifyResize(); 86 autofillSection.$.creditCardList.notifyResize();
(...skipping 10 matching lines...) Expand all
66 createAutofillSection_: function(addresses, creditCards) { 97 createAutofillSection_: function(addresses, creditCards) {
67 var section = document.createElement('settings-autofill-section'); 98 var section = document.createElement('settings-autofill-section');
68 section.addresses = addresses; 99 section.addresses = addresses;
69 section.creditCards = creditCards; 100 section.creditCards = creditCards;
70 document.body.appendChild(section); 101 document.body.appendChild(section);
71 this.flushAutofillSection_(section); 102 this.flushAutofillSection_(section);
72 return section; 103 return section;
73 }, 104 },
74 105
75 /** 106 /**
107 * Creates the Edit Address dialog and fulfills the promise when the dialog
108 * has actually opened.
109 * @param {!chrome.autofillPrivate.AddressEntry} address
110 * @return {!Promise<Object>}
111 */
112 createAddressDialog_: function(address) {
113 return new Promise(function(resolve) {
114 var section = document.createElement('settings-address-edit-dialog');
115 document.body.appendChild(section);
116 var onOpen = function() {
117 resolve(section);
118 };
119 section.addEventListener('iron-overlay-opened', onOpen);
120 section.open(address); // Opening the dialog will add the item.
121 Polymer.dom.flush();
122 });
123 },
124
125 /**
76 * Creates the Edit Credit Card dialog. 126 * Creates the Edit Credit Card dialog.
77 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem 127 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem
78 * @return {!Object} 128 * @return {!Object}
79 */ 129 */
80 createCreditCardDialog_: function(creditCardItem) { 130 createCreditCardDialog_: function(creditCardItem) {
81 var section = document.createElement('settings-credit-card-edit-dialog'); 131 var section = document.createElement('settings-credit-card-edit-dialog');
82 document.body.appendChild(section); 132 document.body.appendChild(section);
83 section.open(creditCardItem); // Opening the dialog will add the item. 133 section.open(creditCardItem); // Opening the dialog will add the item.
84 Polymer.dom.flush(); 134 Polymer.dom.flush();
85 return section; 135 return section;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 done(); 253 done();
204 }); 254 });
205 255
206 MockInteractions.tap(creditCardDialog.$.saveButton); 256 MockInteractions.tap(creditCardDialog.$.saveButton);
207 }), 257 }),
208 258
209 test('verifyCancelCreditCardEdit', function(done) { 259 test('verifyCancelCreditCardEdit', function(done) {
210 var creditCard = FakeDataMaker.emptyCreditCardEntry(); 260 var creditCard = FakeDataMaker.emptyCreditCardEntry();
211 var creditCardDialog = self.createCreditCardDialog_(creditCard); 261 var creditCardDialog = self.createCreditCardDialog_(creditCard);
212 262
213 creditCardDialog.addEventListener('save-credit-card', function(event) { 263 creditCardDialog.addEventListener('save-credit-card', function() {
214 // Fail the test because the save event should not be called when cancel 264 // Fail the test because the save event should not be called when cancel
215 // is clicked. 265 // is clicked.
216 assertTrue(false); 266 assertTrue(false);
217 done(); 267 done();
218 }); 268 });
219 269
220 creditCardDialog.addEventListener('iron-overlay-closed', function(event) { 270 creditCardDialog.addEventListener('iron-overlay-closed', function() {
221 // Test is |done| in a timeout in order to ensure that 271 // Test is |done| in a timeout in order to ensure that
222 // 'save-credit-card' is NOT fired after this test. 272 // 'save-credit-card' is NOT fired after this test.
223 window.setTimeout(done, 100); 273 window.setTimeout(done, 100);
224 }); 274 });
225 275
226 MockInteractions.tap(creditCardDialog.$.cancelButton); 276 MockInteractions.tap(creditCardDialog.$.cancelButton);
227 }), 277 }),
228 278
229 test('verifyAddressCount', function() { 279 test('verifyAddressCount', function() {
230 var addresses = [ 280 var addresses = [
(...skipping 20 matching lines...) Expand all
251 var addressList = section.$.addressList; 301 var addressList = section.$.addressList;
252 var row = addressList.children[1]; // Skip over the template. 302 var row = addressList.children[1]; // Skip over the template.
253 assertTrue(!!row); 303 assertTrue(!!row);
254 304
255 var addressSummary = address.metadata.summaryLabel + 305 var addressSummary = address.metadata.summaryLabel +
256 address.metadata.summarySublabel; 306 address.metadata.summarySublabel;
257 307
258 assertEquals(addressSummary, 308 assertEquals(addressSummary,
259 row.querySelector('#addressSummary').textContent); 309 row.querySelector('#addressSummary').textContent);
260 }); 310 });
311
312 test('verifyAddAddressDialog', function(done) {
michaelpg 2016/06/22 00:25:14 here & below: return the Promise instead of using
hcarmona 2016/06/24 18:27:51 Nice! Didn't know you could return a promise in th
michaelpg 2016/06/27 21:29:18 Yep. See last paragraph: https://www.chromium.org/
313 self.createAddressDialog_(
314 FakeDataMaker.emptyAddressEntry()).then(function(dialog){
michaelpg 2016/06/22 00:25:14 missing space before {
hcarmona 2016/06/24 18:27:51 Done.
315 var title = dialog.$$('.title');
316 assertEquals(self.i18nStrings.addAddressTitle, title.textContent);
317 // Shouldn't be possible to save until something is typed in.
318 assertTrue(dialog.$.saveButton.disabled);
319 done();
320 });
321 });
322
323 test('verifyEditAddressDialog', function(done) {
324 self.createAddressDialog_(
michaelpg 2016/06/22 00:25:14 return self.createAddressDialog_(...
hcarmona 2016/06/24 18:27:51 Done.
325 FakeDataMaker.addressEntry()).then(function(dialog){
michaelpg 2016/06/22 00:25:14 missing space before {
hcarmona 2016/06/24 18:27:51 Done.
326 var title = dialog.$$('.title');
327 assertEquals(self.i18nStrings.editAddressTitle, title.textContent);
328 // Should be possible to save when editing because fields are populated.
329 assertFalse(dialog.$.saveButton.disabled);
330 done();
331 });
332 });
333
334 test('verifyCountryIsSaved', function(done) {
335 var address = FakeDataMaker.emptyAddressEntry();
336 self.createAddressDialog_(address).then(function(dialog) {
337 assertEquals(undefined, dialog.$.countryList.selected);
338 assertEquals(undefined, address.countryCode);
339 dialog.$.countryList.selected = 'US';
340 Polymer.dom.flush();
341 assertEquals('US', dialog.$.countryList.selected);
342 assertEquals('US', address.countryCode);
343 done();
344 });
345 });
346
347 test('verifyPhoneAndEmailAreSaved', function(done) {
348 var address = FakeDataMaker.emptyAddressEntry();
349 self.createAddressDialog_(address).then(function(dialog) {
350 assertFalse(!!dialog.$.phoneInput.value);
michaelpg 2016/06/22 00:25:14 why not assertEqual('', dialog.$.phoneInput.value)
hcarmona 2016/06/24 18:27:51 Done.
351 assertFalse(!!(address.phoneNumbers && address.phoneNumbers[0]));
352
353 assertFalse(!!dialog.$.emailInput.value);
354 assertFalse(!!(address.emailAddresses && address.emailAddresses[0]));
355
356 var phoneNumber = '(555) 555-5555';
357 var emailAddress = 'no-reply@chromium.org';
358
359 dialog.$.phoneInput.value = phoneNumber;
360 dialog.$.emailInput.value = emailAddress;
361
362 Polymer.dom.flush();
363
364 assertEquals(phoneNumber, dialog.$.phoneInput.value);
365 assertEquals(phoneNumber, address.phoneNumbers[0]);
366
367 assertEquals(emailAddress, dialog.$.emailInput.value);
368 assertEquals(emailAddress, address.emailAddresses[0]);
369
370 done();
371 });
372 });
373
374 // Test will set a value of 'foo' in each text field and verify that the
375 // save button is enabled, then it will clear the field and verify that the
376 // save button is disabled. Test passes after all elements have been tested.
377 test('verifySaveIsNotClickableIfAllInputFieldsAreEmpty', function(done) {
378 self.createAddressDialog_(
379 FakeDataMaker.emptyAddressEntry()).then(function(dialog){
380 var saveButton = dialog.$.saveButton;
381 var testElements =
382 dialog.$.dialog.querySelectorAll('paper-input,paper-textarea');
383
384 // Default country is 'US' expecting: Name, Organization,
385 // Street address, City, State, ZIP code, Phone, and Email.
386 assertEquals(8, testElements.length);
387
388 var testFunctions = {
389 index: 0,
390 currentInput: null,
391 nextTest: null,
392
393 beginTest: function() {
394 this.updateCurrentInput();
395 },
396
397 ensureDisabledAndPopulateInput: function() {
398 this.nextTest = this.ensureEnabledAndClearInput.bind(this);
399
400 assertTrue(saveButton.disabled);
401 this.currentInput.value = 'foo';
402 Polymer.dom.flush();
403 },
404
405 ensureEnabledAndClearInput: function() {
406 this.nextTest = this.updateCurrentInput.bind(this);
407
408 assertFalse(saveButton.disabled);
409 this.currentInput.value = '';
410 Polymer.dom.flush();
411 },
412
413 updateCurrentInput: function() {
414 this.currentInput = testElements[this.index++];
415
416 if (this.currentInput)
417 this.ensureDisabledAndPopulateInput();
418 else
419 this.finishTest();
420 },
421
422 finishTest: function() {
423 this.nextTest = null;
424
425 assertTrue(saveButton.disabled);
426 done();
427 },
428 };
429
430 dialog.addEventListener('on-update-can-save', function() {
431 if (testFunctions.nextTest)
432 testFunctions.nextTest();
433 });
434
435 testFunctions.beginTest();
436 });
437 });
438
439 // Setting the country should allow the address to be saved.
440 test('verifySaveIsNotClickableIfCountryNotSet', function(done) {
441 self.createAddressDialog_(
442 FakeDataMaker.emptyAddressEntry()).then(function(dialog){
443 var saveButton = dialog.$.saveButton;
444 var countries = dialog.$.countryList;
445
446 var testFunctions = {
447 nextTest: null,
448
449 beginTest: function() {
450 this.ensureDisabledAndPopulateInput();
451 },
452
453 ensureDisabledAndPopulateInput: function() {
454 this.nextTest = this.ensureEnabledAndClearInput.bind(this);
455
456 assertTrue(saveButton.disabled);
457 countries.selected = 'US';
458 Polymer.dom.flush();
459 },
460
461 ensureEnabledAndClearInput: function() {
462 this.nextTest = this.finishTest.bind(this);
463
464 assertFalse(saveButton.disabled);
465 countries.selected = '';
466 Polymer.dom.flush();
467 },
468
469 finishTest: function() {
470 this.nextTest = null;
471
472 assertTrue(saveButton.disabled);
473 done();
474 },
475 };
476
477 dialog.addEventListener('on-update-can-save', function() {
478 if (testFunctions.nextTest)
479 testFunctions.nextTest();
480 });
481
482 testFunctions.beginTest();
483 });
484 });
485
486 // Test will timeout if save-address event is not fired.
487 test('verifyDefaultCountryIsAppliedWhenSaving', function(done) {
488 var address = FakeDataMaker.emptyAddressEntry();
489 address.companyName = 'Google';
490 self.createAddressDialog_(address).then(function(dialog) {
491 // Verify |countryCode| is not set.
492 assertFalse(!!address.countryCode);
493
494 // Finish the test after dialog has fired the 'save-address' event.
495 dialog.addEventListener('save-address', function(event) {
496 // 'US' is the default country for these tests.
497 assertEquals('US', event.detail.countryCode);
498 done();
499 });
500
501 MockInteractions.tap(dialog.$.saveButton);
502 });
503 });
504
505 test('verifyCancelDoesNotSaveAddress', function(done) {
506 self.createAddressDialog_(
507 FakeDataMaker.addressEntry()).then(function(dialog){
508 dialog.addEventListener('save-address', function() {
509 // Fail the test because the save event should not be called when
510 // cancel is clicked.
511 assertTrue(false);
512 done();
513 });
514
515 dialog.addEventListener('iron-overlay-closed', function() {
516 // Test is |done| in a timeout in order to ensure that
517 // 'save-address' is NOT fired after this test.
518 window.setTimeout(done, 100);
519 });
520
521 MockInteractions.tap(dialog.$.cancelButton);
522 });
523 });
524
525 // US address has 3 fields on the same line.
526 test('verifyEditingUSAddress', function(done) {
527 var address = FakeDataMaker.emptyAddressEntry();
528
529 address.fullNames = [ 'Name' ];
530 address.companyName = 'Organization';
531 address.addressLines = 'Street address';
532 address.addressLevel2 = 'City';
533 address.addressLevel1 = 'State';
534 address.postalCode = 'ZIP code';
535 address.countryCode = 'US';
536 address.phoneNumbers = [ 'Phone' ];
537 address.emailAddresses = [ 'Email' ];
538
539 self.createAddressDialog_(address).then(function(dialog) {
540 var rows = dialog.$.dialog.querySelectorAll('.address-row');
541 assertEquals(6, rows.length);
542
543 // Name
544 var row = rows[0];
545 var cols = row.querySelectorAll('.address-column');
546 assertEquals(1, cols.length);
547 assertEquals(address.fullNames[0], cols[0].value);
548 // Organization
549 row = rows[1];
550 cols = row.querySelectorAll('.address-column');
551 assertEquals(1, cols.length);
552 assertEquals(address.companyName, cols[0].value);
553 // Street address
554 row = rows[2];
555 cols = row.querySelectorAll('.address-column');
556 assertEquals(1, cols.length);
557 assertEquals(address.addressLines, cols[0].value);
558 // City, State, ZIP code
559 row = rows[3];
560 cols = row.querySelectorAll('.address-column');
561 assertEquals(3, cols.length);
562 assertEquals(address.addressLevel2, cols[0].value);
563 assertEquals(address.addressLevel1, cols[1].value);
564 assertEquals(address.postalCode, cols[2].value);
565 // Country
566 row = rows[4];
567 cols = row.querySelectorAll('.address-column');
568 assertEquals(1, cols.length);
569 assertEquals('United States', cols[0].value);
570 // Phone, Email
571 row = rows[5];
572 cols = row.querySelectorAll('.address-column');
573 assertEquals(2, cols.length);
574 assertEquals(address.phoneNumbers[0], cols[0].value);
575 assertEquals(address.emailAddresses[0], cols[1].value);
576
577 done();
578 });
579 });
580
581 // GB address has 1 field per line for all lines that change.
582 test('verifyEditingGBAddress', function(done) {
583 var address = FakeDataMaker.emptyAddressEntry();
584
585 address.fullNames = [ 'Name' ];
586 address.companyName = 'Organization';
587 address.addressLines = 'Street address';
588 address.addressLevel2 = 'Post town';
589 address.addressLevel1 = 'County';
590 address.postalCode = 'Postal code';
591 address.countryCode = 'GB';
592 address.phoneNumbers = [ 'Phone' ];
593 address.emailAddresses = [ 'Email' ];
594
595 self.createAddressDialog_(address).then(function(dialog) {
596 var rows = dialog.$.dialog.querySelectorAll('.address-row');
597 assertEquals(8, rows.length);
598
599 // Name
600 var row = rows[0];
601 var cols = row.querySelectorAll('.address-column');
602 assertEquals(1, cols.length);
603 assertEquals(address.fullNames[0], cols[0].value);
604 // Organization
605 row = rows[1];
606 cols = row.querySelectorAll('.address-column');
607 assertEquals(1, cols.length);
608 assertEquals(address.companyName, cols[0].value);
609 // Street address
610 row = rows[2];
611 cols = row.querySelectorAll('.address-column');
612 assertEquals(1, cols.length);
613 assertEquals(address.addressLines, cols[0].value);
614 // Post Town
615 row = rows[3];
616 cols = row.querySelectorAll('.address-column');
617 assertEquals(1, cols.length);
618 assertEquals(address.addressLevel2, cols[0].value);
619 // County
620 row = rows[4];
621 cols = row.querySelectorAll('.address-column');
622 assertEquals(1, cols.length);
623 assertEquals(address.addressLevel1, cols[0].value);
624 // Postal code
625 row = rows[5];
626 cols = row.querySelectorAll('.address-column');
627 assertEquals(1, cols.length);
628 assertEquals(address.postalCode, cols[0].value);
629 // Country
630 row = rows[6];
631 cols = row.querySelectorAll('.address-column');
632 assertEquals(1, cols.length);
633 assertEquals('United Kingdom', cols[0].value);
634 // Phone, Email
635 row = rows[7];
636 cols = row.querySelectorAll('.address-column');
637 assertEquals(2, cols.length);
638 assertEquals(address.phoneNumbers[0], cols[0].value);
639 assertEquals(address.emailAddresses[0], cols[1].value);
640
641 done();
642 });
643 });
644
645 // IL address has 2 fields on the same line and is an RTL locale.
646 // RTL locale shouldn't affect this test.
647 test('verifyEditingILAddress', function(done) {
648 var address = FakeDataMaker.emptyAddressEntry();
649
650 address.fullNames = [ 'Name' ];
651 address.companyName = 'Organization';
652 address.addressLines = 'Street address';
653 address.addressLevel2 = 'City';
654 address.postalCode = 'Postal code';
655 address.countryCode = 'IL';
656 address.phoneNumbers = [ 'Phone' ];
657 address.emailAddresses = [ 'Email' ];
658
659 self.createAddressDialog_(address).then(function(dialog) {
660 var rows = dialog.$.dialog.querySelectorAll('.address-row');
661 assertEquals(6, rows.length);
662
663 // Name
664 var row = rows[0];
665 var cols = row.querySelectorAll('.address-column');
666 assertEquals(1, cols.length);
667 assertEquals(address.fullNames[0], cols[0].value);
668 // Organization
669 row = rows[1];
670 cols = row.querySelectorAll('.address-column');
671 assertEquals(1, cols.length);
672 assertEquals(address.companyName, cols[0].value);
673 // Street address
674 row = rows[2];
675 cols = row.querySelectorAll('.address-column');
676 assertEquals(1, cols.length);
677 assertEquals(address.addressLines, cols[0].value);
678 // City, Postal code
679 row = rows[3];
680 cols = row.querySelectorAll('.address-column');
681 assertEquals(2, cols.length);
682 assertEquals(address.addressLevel2, cols[0].value);
683 assertEquals(address.postalCode, cols[1].value);
684 // Country
685 row = rows[4];
686 cols = row.querySelectorAll('.address-column');
687 assertEquals(1, cols.length);
688 assertEquals('Israel', cols[0].value);
689 // Phone, Email
690 row = rows[5];
691 cols = row.querySelectorAll('.address-column');
692 assertEquals(2, cols.length);
693 assertEquals(address.phoneNumbers[0], cols[0].value);
694 assertEquals(address.emailAddresses[0], cols[1].value);
695
696 done();
697 });
698 });
699
700 // US has an extra field 'State'. Validate that this field is
701 // persisted when switching to IL then back to US.
702 test('verifyAddressPersistanceWhenSwitchingCountries', function(done) {
703 var address = FakeDataMaker.emptyAddressEntry();
704 address.countryCode = 'US';
705
706 self.createAddressDialog_(address).then(function(dialog) {
707 var city = 'Los Angeles';
708 var state = 'CA';
709 var zip = '90291';
710
711 // US:
712 var rows = dialog.$.dialog.querySelectorAll('.address-row');
713 assertEquals(6, rows.length);
714
715 // City, State, ZIP code
716 var row = rows[3];
717 var cols = row.querySelectorAll('.address-column');
718 assertEquals(3, cols.length);
719 cols[0].value = city;
720 cols[1].value = state;
721 cols[2].value = zip;
722
723 Polymer.dom.flush();
724
725 var validateCountry = 'IL';
726
727 // Triggered several times.
728 dialog.addEventListener('on-update-address-wrapper', function() {
729 // Country is still updating. Do nothing.
730 if (validateCountry != dialog.$.countryList.selected)
731 return;
732
733 if (validateCountry == 'IL') {
734 // IL:
735 rows = dialog.$.dialog.querySelectorAll('.address-row');
736 assertEquals(6, rows.length);
737
738 // City, Postal code
739 row = rows[3];
740 cols = row.querySelectorAll('.address-column');
741 assertEquals(2, cols.length);
742 assertEquals(city, cols[0].value);
743 assertEquals(zip, cols[1].value);
744
745 dialog.$.countryList.selected = 'US';
746 Polymer.dom.flush();
747
748 validateCountry = 'US';
749 } else if (validateCountry == 'US') {
750 // US:
751 var rows = dialog.$.dialog.querySelectorAll('.address-row');
752 assertEquals(6, rows.length);
753
754 // City, State, ZIP code
755 row = rows[3];
756 cols = row.querySelectorAll('.address-column');
757 assertEquals(3, cols.length);
758 assertEquals(city, cols[0].value);
759 assertEquals(state, cols[1].value);
760 assertEquals(zip, cols[2].value);
761
762 done();
763 } else {
764 assertTrue(false, 'Test state is invalid. Just fail.');
765 done();
766 }
767 });
768
769 dialog.$.countryList.selected = 'IL';
770 Polymer.dom.flush();
771 });
772 });
261 }); 773 });
262 774
263 mocha.run(); 775 mocha.run();
264 }); 776 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698