Bug 1464102 - Uncomment the shippingOptions portion of browser_request_serialization now that todo_is is supported. r?mattn draft
authorJared Wein <jwein@mozilla.com>
Thu, 24 May 2018 12:15:07 -0400
changeset 799962 2ad482540f4b661f239a75ca346b265ce3fddf68
parent 799961 9d9dab3f0428f39b82c3092f5fc63d69634f48e2
child 799963 53dcd89f77e99819ba44c006089bff3c54a1c628
push id111229
push userbmo:jaws@mozilla.com
push dateFri, 25 May 2018 17:33:49 +0000
reviewersmattn
bugs1464102
milestone62.0a1
Bug 1464102 - Uncomment the shippingOptions portion of browser_request_serialization now that todo_is is supported. r?mattn MozReview-Commit-ID: GdOLGW2i4O1
browser/components/payments/test/browser/browser_request_serialization.js
--- a/browser/components/payments/test/browser/browser_request_serialization.js
+++ b/browser/components/payments/test/browser/browser_request_serialization.js
@@ -24,43 +24,55 @@ add_task(async function test_serializeRe
   const args = {
     methodData: [PTU.MethodData.basicCard],
     details: PTU.Details.twoDisplayItems,
   };
   await spawnInDialogForMerchantTask(PTU.ContentTasks.createAndShowRequest, testTask, args);
 });
 
 add_task(async function test_serializeRequest_shippingOptions() {
-  const testTask = ({methodData, details}) => {
+  const testTask = ({methodData, details, options}) => {
     let contentWin = Cu.waiveXrays(content);
     let store = contentWin.document.querySelector("payment-dialog").requestStore;
     let state = store && store.getState();
     ok(state, "got request store state");
 
-    // let expected = details;
-    // let actual = state.request.paymentDetails;
-    // if (expected.shippingOptions) {
-    //   is(actual.shippingOptions.length, expected.shippingOptions.length,
-    //      "shippingOptions have same length");
-    //   for (let i = 0; i < actual.shippingOptions.length; i++) {
-    //     let item = actual.shippingOptions[i], expectedItem = expected.shippingOptions[i];
-    //     is(item.label, expectedItem.label, "shippingOption label matches");
-    //     is(item.amount.value, expectedItem.amount.value, "shippingOption label matches");
-    //     is(item.amount.currency, expectedItem.amount.currency, "shippingOption label matches");
-    //   }
-    // } else {
-    //   is(actual.shippingOptions, null, "falsey input shippingOptions is serialized to null");
-    // }
+    // The following test cases are conditionally todo because
+    // the spec currently does not state the shippingOptions
+    // should be null when requestShipping is not set. A future
+    // spec change (bug 1436903 comments 7-12) will fix this.
+    let cond_is = options && options.requestShipping ? is : todo_is;
+
+    let expected = details;
+    let actual = state.request.paymentDetails;
+    if (expected.shippingOptions) {
+      cond_is(actual.shippingOptions.length, expected.shippingOptions.length,
+              "shippingOptions have same length");
+      for (let i = 0; i < actual.shippingOptions.length; i++) {
+        let item = actual.shippingOptions[i], expectedItem = expected.shippingOptions[i];
+        cond_is(item.label, expectedItem.label, "shippingOption label matches");
+        cond_is(item.amount.value, expectedItem.amount.value, "shippingOption label matches");
+        cond_is(item.amount.currency, expectedItem.amount.currency, "shippingOption label matches");
+      }
+    } else {
+      cond_is(actual.shippingOptions, null, "falsey input shippingOptions is serialized to null");
+    }
   };
 
-  const args = {
+  const argsTestCases = [{
+    methodData: [PTU.MethodData.basicCard],
+    details: PTU.Details.twoShippingOptions,
+  }, {
     methodData: [PTU.MethodData.basicCard],
     details: PTU.Details.twoShippingOptions,
-  };
-  await spawnInDialogForMerchantTask(PTU.ContentTasks.createAndShowRequest, testTask, args);
+    options: PTU.Options.requestShippingOption,
+  }];
+  for (let args of argsTestCases) {
+    await spawnInDialogForMerchantTask(PTU.ContentTasks.createAndShowRequest, testTask, args);
+  }
 });
 
 add_task(async function test_serializeRequest_paymentMethods() {
   const testTask = ({methodData, details}) => {
     let contentWin = Cu.waiveXrays(content);
     let store = contentWin.document.querySelector("payment-dialog").requestStore;
     let state = store && store.getState();
     ok(state, "got request store state");