Skip to content

Commit

Permalink
Bug 1429260 - Add tests to verify handling of payment detail properti…
Browse files Browse the repository at this point in the history
…es it is possible to updateWith. r=jaws

* Check update of displayItems, additionalDisplay items and total (via a modifier.)

MozReview-Commit-ID: B4L7Ev9yR2f
  • Loading branch information
sfoster committed May 25, 2018
1 parent d8c1bac commit ecea77c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
29 changes: 29 additions & 0 deletions browser/components/payments/test/PaymentTestUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ var PaymentTestUtils = {
},
],
},
twoDisplayItemsEUR: {
displayItems: [
{
label: "First",
amount: { currency: "EUR", value: "0.85" },
},
{
label: "Second",
amount: { currency: "EUR", value: "1.70" },
},
],
},
twoShippingOptions: {
shippingOptions: [
{
Expand Down Expand Up @@ -308,6 +320,23 @@ var PaymentTestUtils = {
},
],
},
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: "",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ add_task(async function test_change_shipping() {
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");

Expand All @@ -47,6 +52,7 @@ add_task(async function test_change_shipping() {
}, PTU.ContentTasks.awaitPaymentRequestEventPromise);
info("got shippingaddresschange event");

// verify update of shippingOptions
shippingOptions =
await spawnPaymentDialogTask(frame, PTU.DialogContentTasks.getShippingOptions);
is(shippingOptions.selectedOptionCurrency, "EUR",
Expand All @@ -55,6 +61,42 @@ add_task(async function test_change_shipping() {
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);

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ecea77c

Please sign in to comment.