Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual test for PaymentResponse.shippingAddress attr #6952

Merged
merged 4 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>