Bug 1490805 - Include temporary basic cards in validity check for supportedNetworks. r=sfoster
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 27 Sep 2018 05:57:40 +0000
changeset 438513 42fac3928107b21fb99e63649386484acb34df5f
parent 438512 2b40812f97abd1461265674007c469ae3f059a73
child 438514 4ba6db4fd39bb4e5bf8a1a5422dd8e58ef6a646f
push id34724
push userccoroiu@mozilla.com
push dateThu, 27 Sep 2018 21:36:09 +0000
treeherdermozilla-central@e1d012b989ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs1490805
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 1490805 - Include temporary basic cards in validity check for supportedNetworks. r=sfoster Depends on D6848 Differential Revision: https://phabricator.services.mozilla.com/D6882
browser/components/payments/res/containers/payment-method-picker.js
browser/components/payments/test/mochitest/test_payment_method_picker.html
--- a/browser/components/payments/res/containers/payment-method-picker.js
+++ b/browser/components/payments/res/containers/payment-method-picker.js
@@ -84,17 +84,17 @@ export default class PaymentMethodPicker
       return false;
     }
     let selectedOption = this.selectedOption;
     if (!selectedOption) {
       return true;
     }
 
     let acceptedNetworks = paymentRequest.getAcceptedNetworks(state.request);
-    let selectedCard = state.savedBasicCards[selectedOption.value];
+    let selectedCard = paymentRequest.getBasicCards(state)[selectedOption.value];
     let isSupported = selectedCard["cc-type"] &&
                       acceptedNetworks.includes(selectedCard["cc-type"]);
     return isSupported;
   }
 
   get selectedStateKey() {
     return this.getAttribute("selected-state-key");
   }
--- a/browser/components/payments/test/mochitest/test_payment_method_picker.html
+++ b/browser/components/payments/test/mochitest/test_payment_method_picker.html
@@ -205,12 +205,71 @@ add_task(async function test_delete() {
     },
   });
   await asyncElementRendered();
   let options = picker1.dropdown.popupBox.children;
   is(options.length, 2, "Check dropdown has two remaining cards");
   ok(options[0].textContent.includes("J Smith"), "Check remaining card #1");
   ok(options[1].textContent.includes("Jane Fields"), "Check remaining card #2");
 });
+
+add_task(async function test_supportedNetworks_tempCards() {
+  await picker1.requestStore.reset();
+
+  let request = Object.assign({}, picker1.requestStore.getState().request);
+  request.paymentMethods = [
+    {
+      supportedMethods: "basic-card",
+      data: {
+        supportedNetworks: [
+          "mastercard",
+          "visa",
+        ],
+      },
+    },
+  ];
+
+  await picker1.requestStore.setState({
+    request,
+    selectedPaymentCard: "68gjdh354j",
+    tempBasicCards: {
+      "68gjdh354j": {
+        "cc-exp": "2017-08",
+        "cc-exp-month": 8,
+        "cc-exp-year": 2017,
+        "cc-name": "J Smith",
+        "cc-number": "***********1234",
+        "cc-type": "discover",
+        "guid": "68gjdh354j",
+      },
+    },
+  });
+  await asyncElementRendered();
+  let options = picker1.dropdown.popupBox.children;
+  is(options.length, 1, "Check dropdown has one card");
+  ok(options[0].textContent.includes("J Smith"), "Check remaining card #1");
+
+  ok(picker1.classList.contains("invalid-selected-option"),
+     "Check discover is recognized as not supported");
+
+  info("change the card to be a visa");
+  await picker1.requestStore.setState({
+    tempBasicCards: {
+      "68gjdh354j": {
+        "cc-exp": "2017-08",
+        "cc-exp-month": 8,
+        "cc-exp-year": 2017,
+        "cc-name": "J Smith",
+        "cc-number": "***********1234",
+        "cc-type": "visa",
+        "guid": "68gjdh354j",
+      },
+    },
+  });
+  await asyncElementRendered();
+
+  ok(!picker1.classList.contains("invalid-selected-option"),
+     "Check visa is recognized as supported");
+});
 </script>
 
 </body>
 </html>