https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 94fd139ae5d0bdc4274b5e2c4e91035d63876e5c authored by Marcos Cáceres on 29 November 2018, 10:38:58 UTC
Test payment request is showing boolean
Tip revision: 94fd139
payment-request-shippingType-attribute.https.html
<!DOCTYPE html>
<!-- Copyright © 2017 Mozilla and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<meta charset="utf-8">
<title>Test for PaymentRequest's shippingType attribute</title>
<link rel="help" href="https://w3c.github.io/payment-request/#shippingtype-attribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
const paymentShipingTypes = Object.freeze(["delivery", "pickup", "shipping"]);
const basicCard = Object.freeze({ supportedMethods: "basic-card" });
const defaultMethods = Object.freeze([basicCard]);
const defaultDetails = Object.freeze({
  total: {
    label: "",
    amount: {
      currency: "USD",
      value: "1.00",
    },
  },
});

test(() => {
  const request = new PaymentRequest(defaultMethods, defaultDetails);
  assert_idl_attribute(request, "shippingType");
}, "Must have a shippingType IDL attribute");

test(() => {
  const request1 = new PaymentRequest(defaultMethods, defaultDetails, {});
  assert_equals(request1.shippingType, null, "must be null");
  const request2 = new PaymentRequest(defaultMethods, defaultDetails, {
    requestShipping: false,
  });
  assert_equals(request2.shippingType, null, "must be null");
  for (const shippingType of paymentShipingTypes) {
    const request = new PaymentRequest(defaultMethods, defaultDetails, {
      requestShipping: false,
      shippingType,
    });
    assert_equals(request.shippingType, null, "must be null");
  }
}, "If options.requestShipping is false, then request.shippingType attribute is null.");

test(() => {
  // option.shippingType defaults to 'shipping'
  const defaultRequest = new PaymentRequest(defaultMethods, defaultDetails, {
    requestShipping: true,
  });
  assert_equals(defaultRequest.shippingType, "shipping", "must be shipping");
  for (const shippingType of paymentShipingTypes) {
    const request = new PaymentRequest(defaultMethods, defaultDetails, {
      requestShipping: true,
      shippingType,
    });
    assert_equals(
      request.shippingType,
      shippingType,
      `must be ${shippingType}`
    );
  }
}, "If options.requestShipping is true, request.shippingType will be options.shippingType.");
</script>
back to top