Bug 1482808 - Clear the field-specific merchant error invalid state when the field has been edited. r=sfoster
authorJared Wein <jwein@mozilla.com>
Fri, 07 Sep 2018 23:15:09 +0000
changeset 435349 f669be991db6
parent 435348 4b50d292d249
child 435350 62f9269dd530
child 435355 9bb0f7fc73ad
push id68985
push userjwein@mozilla.com
push dateSun, 09 Sep 2018 18:04:22 +0000
treeherderautoland@f669be991db6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs1482808
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1482808 - Clear the field-specific merchant error invalid state when the field has been edited. r=sfoster Differential Revision: https://phabricator.services.mozilla.com/D5081
browser/components/payments/res/containers/address-form.js
browser/components/payments/test/browser/browser_shippingaddresschange_error.js
--- a/browser/components/payments/res/containers/address-form.js
+++ b/browser/components/payments/res/containers/address-form.js
@@ -260,16 +260,26 @@ export default class AddressForm extends
       }
       default: {
         throw new Error("Unexpected click target");
       }
     }
   }
 
   onInput(event) {
+    let container = event.target.closest(`#${event.target.id}-container`);
+    if (container) {
+      container.classList.remove("error");
+      event.target.setCustomValidity("");
+
+      let span = container.querySelector(".error-text");
+      if (span) {
+        span.textContent = "";
+      }
+    }
     this.updateSaveButtonState();
   }
 
   onInvalid(event) {
     this.saveButton.disabled = true;
   }
 
   updateRequiredState() {
--- a/browser/components/payments/test/browser/browser_shippingaddresschange_error.js
+++ b/browser/components/payments/test/browser/browser_shippingaddresschange_error.js
@@ -126,22 +126,37 @@ add_task(async function test_show_field_
       // check errors and make corrections
       let {shippingAddressErrors} = PTU.Details.fieldSpecificErrors;
       is(content.document.querySelectorAll("address-form .error-text:not(:empty)").length,
          Object.keys(shippingAddressErrors).length,
          "Each error should be presented");
       let errorFieldMap =
         Cu.waiveXrays(content.document.querySelector("address-form"))._errorFieldMap;
       for (let [errorName, errorValue] of Object.entries(shippingAddressErrors)) {
-        let field = content.document.querySelector(errorFieldMap[errorName] + "-container");
+        let fieldSelector = errorFieldMap[errorName];
+        let containerSelector = fieldSelector + "-container";
+        let container = content.document.querySelector(containerSelector);
         try {
-          is(field.querySelector(".error-text").textContent, errorValue,
+          is(container.querySelector(".error-text").textContent, errorValue,
              "Field specific error should be associated with " + errorName);
         } catch (ex) {
-          ok(false, `no field found for ${errorName}. selector= ${errorFieldMap[errorName]}`);
+          ok(false, `no container for ${errorName}. selector= ${containerSelector}`);
+        }
+        try {
+          let field = content.document.querySelector(fieldSelector);
+          let oldValue = field.value;
+          if (field.localName == "select") {
+            // Flip between empty and the selected entry so country fields won't change.
+            content.fillField(field, "");
+            content.fillField(field, oldValue);
+          } else {
+            content.fillField(field, field.value.split("").reverse().join(""));
+          }
+        } catch (ex) {
+          ok(false, `no field found for ${errorName}. selector= ${fieldSelector}`);
         }
       }
     });
 
     info("setup updateWith to clear errors");
     await ContentTask.spawn(browser, {
       eventName: "shippingaddresschange",
       details: Object.assign({},
@@ -149,30 +164,16 @@ add_task(async function test_show_field_
                              PTU.Details.total2USD),
     }, PTU.ContentTasks.updateWith);
 
     await spawnPaymentDialogTask(frame, async () => {
       let {
         PaymentTestUtils: PTU,
       } = ChromeUtils.import("resource://testing-common/PaymentTestUtils.jsm", {});
 
-      // TODO: bug 1482808 - Clear setCustomValidity from merchant errors since
-      // they don't currently ever get cleared.
-      for (let field of content.document.querySelector("address-form form").elements) {
-        if (!field.validity.customError) {
-          continue;
-        }
-        field.setCustomValidity("");
-        todo(false, `Clearing custom validity on #${field.id}`);
-      }
-
-      Cu.waiveXrays(content.document.querySelector("address-form")).updateSaveButtonState();
-
-      // End bug 1482808 TODO
-
       info("saving corrections");
       content.document.querySelector("address-form .save-button").click();
 
       await PTU.DialogContentUtils.waitForState(content, (state) => {
         return state.page.id == "payment-summary";
       }, "Check we're back on summary view");
 
       await PTU.DialogContentUtils.waitForState(content, (state) => {