Bug 1497514 - Initialize BasicCardPage selectedStateKey to 'selectPaymentCard'. r=MattN
authorDiego Pino Garcia <dpino@igalia.com>
Thu, 18 Oct 2018 23:56:00 +0300
changeset 490397 25594c3013c4852ee5441321b340983c2a8d6364
parent 490396 f35ac5e55bb4ea3a74c53b964bec3627c984961b
child 490398 646f2d021c1163ac0c58c3878aa6921dc92311cb
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersMattN
bugs1497514
milestone64.0a1
Bug 1497514 - Initialize BasicCardPage selectedStateKey to 'selectPaymentCard'. r=MattN Also require basicCardPage has a selectedStateKey
browser/components/payments/res/containers/basic-card-form.js
browser/components/payments/res/mixins/PaymentStateSubscriberMixin.js
browser/components/payments/res/paymentRequest.js
browser/components/payments/test/browser/browser.ini
browser/components/payments/test/browser/browser_onboarding_wizard.js
browser/components/payments/test/browser/browser_payments_onboarding_wizard.js
browser/components/payments/test/mochitest/test_basic_card_form.html
--- a/browser/components/payments/res/containers/basic-card-form.js
+++ b/browser/components/payments/res/containers/basic-card-form.js
@@ -146,16 +146,20 @@ export default class BasicCardForm exten
       "basic-card-page": basicCardPage,
     } = state;
 
     if (this.id && page && page.id !== this.id) {
       log.debug(`BasicCardForm: no need to further render inactive page: ${page.id}`);
       return;
     }
 
+    if (!basicCardPage.selectedStateKey) {
+      throw new Error("A `selectedStateKey` is required");
+    }
+
     let editing = !!basicCardPage.guid;
     this.cancelButton.textContent = this.dataset.cancelButtonLabel;
     this.backButton.textContent = this.dataset.backButtonLabel;
     if (editing) {
       this.saveButton.textContent = this.dataset.updateButtonLabel;
     } else {
       this.saveButton.textContent = this.dataset.nextButtonLabel;
     }
--- a/browser/components/payments/res/mixins/PaymentStateSubscriberMixin.js
+++ b/browser/components/payments/res/mixins/PaymentStateSubscriberMixin.js
@@ -12,17 +12,17 @@ import PaymentsStore from "../PaymentsSt
  * State of the payment request dialog.
  */
 export let requestStore = new PaymentsStore({
   changesPrevented: false,
   orderDetailsShowing: false,
   "basic-card-page": {
     guid: null,
     // preserveFieldValues: true,
-    selectedStateKey: null,
+    selectedStateKey: "selectedPaymentCard",
   },
   "address-page": {
     guid: null,
     selectedStateKey: null,
     title: "",
   },
   "payment-summary": {
   },
--- a/browser/components/payments/res/paymentRequest.js
+++ b/browser/components/payments/res/paymentRequest.js
@@ -162,16 +162,19 @@ var paymentRequest = {
           title: paymentDialog.dataset.billingAddressTitleAdd,
         });
       }
     } else if (!hasSavedCards) {
       state.page = {
         id: "basic-card-page",
         onboardingWizard: true,
       };
+      state["basic-card-page"] = {
+        selectedStateKey: "selectedPaymentCard",
+      };
     }
 
     paymentDialog.setStateFromParent(state);
   },
 
   openPreferences() {
     this.sendMessageToChrome("openPreferences");
   },
--- a/browser/components/payments/test/browser/browser.ini
+++ b/browser/components/payments/test/browser/browser.ini
@@ -9,19 +9,19 @@ support-files =
 
 [browser_address_edit.js]
 skip-if = verify && debug && os == 'mac'
 [browser_card_edit.js]
 skip-if = os == 'linux' && debug # bug 1465673
 [browser_change_shipping.js]
 [browser_dropdowns.js]
 [browser_host_name.js]
+[browser_onboarding_wizard.js]
 [browser_openPreferences.js]
 [browser_payment_completion.js]
-[browser_payments_onboarding_wizard.js]
 [browser_profile_storage.js]
 [browser_request_serialization.js]
 [browser_request_shipping.js]
 [browser_retry.js]
 [browser_shippingaddresschange_error.js]
 [browser_show_dialog.js]
 skip-if = os == 'win' && debug # bug 1418385
 [browser_total.js]
rename from browser/components/payments/test/browser/browser_payments_onboarding_wizard.js
rename to browser/components/payments/test/browser/browser_onboarding_wizard.js
--- a/browser/components/payments/test/mochitest/test_basic_card_form.html
+++ b/browser/components/payments/test/mochitest/test_basic_card_form.html
@@ -88,16 +88,17 @@ add_task(async function test_backButton(
   let form = new BasicCardForm();
   form.dataset.backButtonLabel = "Back";
   form.dataset.addBasicCardTitle = "Sample page title 2";
   await form.requestStore.setState({
     page: {
       id: "basic-card-page",
     },
     "basic-card-page": {
+      selectedStateKey: "selectedPaymentCard",
     },
   });
   await form.promiseReady;
   display.appendChild(form);
   await asyncElementRendered();
 
   let stateChangePromise = promiseStateChange(form.requestStore);
   is(form.pageTitleHeading.textContent, "Sample page title 2", "Check title");
@@ -364,16 +365,17 @@ add_task(async function test_edit() {
     request: {
       paymentMethods,
     },
     page: {
       id: "basic-card-page",
     },
     "basic-card-page": {
       guid: card1.guid,
+      selectedStateKey: "selectedPaymentCard",
     },
     savedAddresses: {
       [address1.guid]: deepClone(address1),
     },
     savedBasicCards: {
       [card1.guid]: deepClone(card1),
     },
   });
@@ -417,16 +419,17 @@ add_task(async function test_edit() {
     guid: "9gnjdhen46",
   };
   await form.requestStore.setState({
     page: {
       id: "basic-card-page",
     },
     "basic-card-page": {
       guid: minimalCard.guid,
+      selectedStateKey: "selectedPaymentCard",
     },
     savedBasicCards: {
       [minimalCard.guid]: deepClone(minimalCard),
     },
   });
   await asyncElementRendered();
   ok(form.querySelectorAll(":-moz-ui-invalid").length > 0,
      "Check fields are visibly invalid on an 'edit' form with missing fields");
@@ -434,16 +437,17 @@ add_task(async function test_edit() {
 
   info("change to no selected card");
   await form.requestStore.setState({
     page: {
       id: "basic-card-page",
     },
     "basic-card-page": {
       guid: null,
+      selectedStateKey: "selectedPaymentCard",
     },
   });
   await asyncElementRendered();
   is(form.querySelectorAll(":-moz-ui-invalid").length, 0,
      "Check no fields are visibly invalid after converting to an 'add' form");
   checkCCForm(form, {
     billingAddressGUID: address1.guid, // Default selected
   });
@@ -521,16 +525,17 @@ add_task(async function test_numberCusto
   ok(form.querySelector("#cc-number:-moz-ui-invalid"), "cc-number field is visibly invalid");
 
   info("simulate triggering an add again to reset the form");
   await form.requestStore.setState({
     page: {
       id: "basic-card-page",
     },
     "basic-card-page": {
+      selectedStateKey: "selectedPaymentCard",
     },
   });
 
   ok(!form.querySelector("#cc-number:-moz-ui-invalid"), "cc-number field is not visibly invalid");
 
   form.remove();
 });
 
@@ -546,16 +551,17 @@ add_task(async function test_noCardNetwo
   delete card1["cc-type"];
 
   await form.requestStore.setState({
     page: {
       id: "basic-card-page",
     },
     "basic-card-page": {
       guid: card1.guid,
+      selectedStateKey: "selectedPaymentCard",
     },
     savedBasicCards: {
       [card1.guid]: deepClone(card1),
     },
   });
   await asyncElementRendered();
   checkCCForm(form, card1);
   is(document.getElementById("cc-type").selectedIndex, 0, "Initial empty option is selected");