Bug 1429260 - Add tests to verify handling of payment detail properties it is possible to updateWith. r=jaws
authorSam Foster <sfoster@mozilla.com>
Thu, 24 May 2018 17:34:42 -0700
changeset 474765 d7379d70b96374656b0102d8dc329f689a6c4872
parent 474764 42fb8fd8d64bc17dc20ec6ff66e522f8e11c872f
child 474766 609a288fe314039c44af39b4a1173f60a058a9b2
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1429260
milestone62.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 1429260 - Add tests to verify handling of payment detail properties it is possible to updateWith. r=jaws * Check update of displayItems, additionalDisplay items and total (via a modifier.) MozReview-Commit-ID: B4L7Ev9yR2f
browser/components/payments/test/PaymentTestUtils.jsm
browser/components/payments/test/browser/browser_change_shipping.js
package-lock.json
--- a/browser/components/payments/test/PaymentTestUtils.jsm
+++ b/browser/components/payments/test/PaymentTestUtils.jsm
@@ -237,16 +237,28 @@ var PaymentTestUtils = {
           amount: { currency: "USD", value: "1" },
         },
         {
           label: "Second",
           amount: { currency: "USD", value: "2" },
         },
       ],
     },
+    twoDisplayItemsEUR: {
+      displayItems: [
+        {
+          label: "First",
+          amount: { currency: "EUR", value: "0.85" },
+        },
+        {
+          label: "Second",
+          amount: { currency: "EUR", value: "1.70" },
+        },
+      ],
+    },
     twoShippingOptions: {
       shippingOptions: [
         {
           id: "1",
           label: "Meh Unreliable Shipping",
           amount: { currency: "USD", value: "1" },
         },
         {
@@ -303,16 +315,33 @@ var PaymentTestUtils = {
           supportedMethods: "https://www.example.com/bobpay",
           total: {
             label: "Total due",
             amount: { currency: "USD", value: "3.50" },
           },
         },
       ],
     },
+    additionalDisplayItemsEUR: {
+      modifiers: [
+        {
+          additionalDisplayItems: [
+            {
+              label: "Handling fee",
+              amount: { currency: "EUR", value: "1.00" },
+            },
+          ],
+          supportedMethods: "basic-card",
+          total: {
+            label: "Total due",
+            amount: { currency: "EUR", value: "2.50" },
+          },
+        },
+      ],
+    },
     noError: {
       error: "",
     },
     genericShippingError: {
       error: "Cannot ship with option 1 on days that end with Y",
     },
     fieldSpecificErrors: {
       error: "There are errors related to specific parts of the address",
--- a/browser/components/payments/test/browser/browser_change_shipping.js
+++ b/browser/components/payments/test/browser/browser_change_shipping.js
@@ -28,38 +28,80 @@ add_task(async function test_change_ship
 
     await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.selectShippingOptionById, "1");
 
     shippingOptions =
       await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.getShippingOptions);
     is(shippingOptions.optionCount, 2, "there should be two shipping options");
     is(shippingOptions.selectedOptionID, "1", "selected should be '1'");
 
+    let paymentDetails = Object.assign({},
+                                       PTU.Details.twoShippingOptionsEUR,
+                                       PTU.Details.total1pt75EUR,
+                                       PTU.Details.twoDisplayItemsEUR,
+                                       PTU.Details.additionalDisplayItemsEUR);
     await ContentTask.spawn(browser, {
       eventName: "shippingaddresschange",
-      details: Object.assign({}, PTU.Details.twoShippingOptionsEUR, PTU.Details.total2USD),
+      details: paymentDetails,
     }, PTU.ContentTasks.updateWith);
     info("added shipping change handler to change to EUR");
 
     await selectPaymentDialogShippingAddressByCountry(frame, "DE");
     info("changed shipping address to DE country");
 
     await ContentTask.spawn(browser, {
       eventName: "shippingaddresschange",
     }, PTU.ContentTasks.awaitPaymentRequestEventPromise);
     info("got shippingaddresschange event");
 
+    // verify update of shippingOptions
     shippingOptions =
       await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.getShippingOptions);
     is(shippingOptions.selectedOptionCurrency, "EUR",
        "Shipping options should be in EUR after the shippingaddresschange");
     is(shippingOptions.selectedOptionID, "1", "id:1 should still be selected");
     is(shippingOptions.selectedOptionValue, "1.01",
        "amount should be '1.01' after the shippingaddresschange");
 
+    await spawnPaymentDialogTask(frame, async function() {
+      let {
+        PaymentTestUtils: PTU,
+      } = ChromeUtils.import("resource://testing-common/PaymentTestUtils.jsm", {});
+      // verify update of total
+      // Note: The update includes a modifier, and modifiers must include a total
+      // so the expected total is that one
+      is(content.document.querySelector("#total > currency-amount").textContent,
+         "\u20AC2.50",
+         "Check updated total currency amount");
+
+      let btn = content.document.querySelector("#view-all");
+      btn.click();
+      await PTU.DialogContentUtils.waitForState(content, (state) => {
+        return state.orderDetailsShowing;
+      }, "Order details show be showing now");
+
+      let container = content.document.querySelector("order-details");
+      let items = [...container.querySelectorAll(".main-list payment-details-item")]
+                  .map(item => Cu.waiveXrays(item));
+
+      // verify the updated displayItems
+      is(items.length, 2, "2 display items");
+      is(items[0].amountCurrency, "EUR", "First display item is in Euros");
+      is(items[1].amountCurrency, "EUR", "2nd display item is in Euros");
+      is(items[0].amountValue, "0.85", "First display item has 0.85 value");
+      is(items[1].amountValue, "1.70", "2nd display item has 1.70 value");
+
+      // verify the updated modifiers
+      items = [...container.querySelectorAll(".footer-items-list payment-details-item")]
+              .map(item => Cu.waiveXrays(item));
+      is(items.length, 1, "1 additional display item");
+      is(items[0].amountCurrency, "EUR", "First display item is in Euros");
+      is(items[0].amountValue, "1.00", "First display item has 1.00 value");
+    });
+
     info("clicking pay");
     spawnPaymentDialogTask(frame, PTU.DialogContentTasks.completePayment);
 
     // Add a handler to complete the payment above.
     info("acknowledging the completion from the merchant page");
     let result = await ContentTask.spawn(browser, {}, PTU.ContentTasks.addCompletionHandler);
     is(result.response.methodName, "basic-card", "Check methodName");
 
--- a/package-lock.json
+++ b/package-lock.json
@@ -269,17 +269,17 @@
         "pify": "2.3.0",
         "pinkie-promise": "2.0.1",
         "rimraf": "2.6.2"
       }
     },
     "doctrine": {
       "version": "2.1.0",
       "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
-      "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==",
+      "integrity": "sha1-XNAfwQFiG0LEzX9dGmYkNxbT850=",
       "requires": {
         "esutils": "2.0.2"
       }
     },
     "dom-serializer": {
       "version": "0.1.0",
       "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.0.tgz",
       "integrity": "sha1-BzxpdUbOB4DOI75KKOKT5AvDDII=",
@@ -970,17 +970,17 @@
     "sax": {
       "version": "1.2.4",
       "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
       "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
     },
     "semver": {
       "version": "5.5.0",
       "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
-      "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA=="
+      "integrity": "sha1-3Eu8emyp2Rbe5dQ1FvAJK1j3uKs="
     },
     "shebang-command": {
       "version": "1.2.0",
       "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
       "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
       "requires": {
         "shebang-regex": "1.0.0"
       }