Skip to content

Commit

Permalink
manual test for PaymentResponse.shippingAddress attr (web-platform-te…
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Cáceres authored and rachelandrew committed Nov 8, 2017
1 parent 0cb47cb commit 8197622
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion payment-request/payment-response/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function getPaymentRequestResponse(options, id) {
* @param {Object} expected What property values are expected to pass the test.
* @param {String?} id And id for the request/response pair.
*/
async function runManualTest(button, options = {}, expected = {}, id) {
async function runManualTest(button, options, expected = {}, id = undefined) {
button.disabled = true;
const { request, response } = await getPaymentRequestResponse(options, id);
await response.complete();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!doctype html>
<meta charset="utf8">
<link rel="help" href="https://w3c.github.io/payment-request/#dom-paymentresponse-shippingaddress">
<title>
PaymentResponse.prototype.shippingAddress
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="helpers.js"></script>
<script>
async function checkNullShippingAddress(button, options) {
button.disabled = true;
const { request, response } = await getPaymentRequestResponse(options);
await response.complete();
test(() => {
assert_equals(
response.shippingAddress,
null,
"Expected response.shippingAddress to be null"
);
assert_equals(
request.shippingAddress,
null,
"Expected request.shippingAddress to be null"
);
}, button.textContent.trim());
}

async function runManualTest(button, options = {}, expected = {}, id) {
button.disabled = true;
const { request, response } = await getPaymentRequestResponse(options, id);
await response.complete();
test(() => {
assert_equals(response.requestId, request.id, `Expected ids to match`);
const { shippingAddress: addr } = request;
assert_true(
addr instanceof PaymentAddress,
"Expect instance of PaymentAddress"
);
try {
addr.toJSON();
} catch (err) {
assert_unreached(
`Unexpected exception calling PaymentAddress.toJSON(): ${err}`
);
}
if (expected.shippingAddress === null) {
return;
}
assert_equals(addr.country, "AF", "Expected AF for country");
assert_true(
addr.addressLine instanceof Array,
"Expected addressLine to be an array"
);
assert_equals(
addr.addressLine.toString(),
"1 wpt street",
"Expected '1 wpt street' for addressLine"
);
assert_equals(addr.city, "Kabul", "Expected city to be Kabul");
assert_equals(addr.postalCode, "1001", "Expect postalCode to be 1001");
assert_equals(addr.recipient, "web platform test");
}, button.textContent.trim());
}
</script>
<h2>shippingAddress attribute</h2>
<p>
When prompted, please enter "web platform test" as recipient, at address "1 wpt street" in "Kabul, Afghanistan", zip/postal code 1001.
</p>
<ol>
<li>
<button onclick="checkNullShippingAddress(this, undefined)">
If options is undefined, then shippingAddress must be null.
</button>
</li>
<li>
<button onclick="checkNullShippingAddress(this, {})">
If the requestShipping member is missing, then shippingAddress must be null.
</button>
</li>
<li>
<button onclick="checkNullShippingAddress(this, {requestShipping: false})">
If the requestShipping member is false, then shippingAddress must be null.
</button>
</li>
<li>
<button onclick="runManualTest(this, {requestShipping: true}).then(done)">
If the requestShipping member is true, then shippingAddress must be "1 wpt street" in "Kabul, Afghanistan", zip code 1001.
</button>
</li>
</ol>

0 comments on commit 8197622

Please sign in to comment.