discourse-subscriptions/test/javascripts/components/payment-options-test.js.es6

75 lines
1.9 KiB
Plaintext
Raw Normal View History

2019-12-06 13:52:03 +11:00
import componentTest from "helpers/component-test";
2019-12-10 10:15:30 +11:00
import EmberObject from "@ember/object";
2019-12-06 13:52:03 +11:00
moduleForComponent("payment-options", { integration: true });
2019-12-06 14:33:38 +11:00
componentTest("Discourse Subscriptions payment options have no plans", {
2019-12-06 13:52:03 +11:00
template: `{{payment-options plans=plans}}`,
async test(assert) {
2019-12-06 14:33:38 +11:00
this.set("plans", false);
2019-12-06 13:52:03 +11:00
assert.equal(
2019-12-06 14:33:38 +11:00
find(".btn-discourse-subscriptions-subscribe").length,
2019-12-06 13:52:03 +11:00
0,
"The plan buttons are not shown"
);
}
});
2019-12-06 14:33:38 +11:00
componentTest("Discourse Subscriptions payment options has content", {
2019-12-06 13:52:03 +11:00
template: `{{payment-options plans=plans}}`,
async test(assert) {
2019-12-09 10:30:34 +11:00
this.set("plans", [
2019-12-09 12:01:10 +11:00
{ currency: "aud", interval: "year", amountDollars: "44.99" },
{ currency: "gdp", interval: "month", amountDollars: "9.99" }
2019-12-09 10:30:34 +11:00
]);
2019-12-06 13:52:03 +11:00
assert.equal(
2019-12-06 14:33:38 +11:00
find(".btn-discourse-subscriptions-subscribe").length,
2019-12-06 13:52:03 +11:00
2,
"The plan buttons are shown"
);
assert.equal(
find("#subscribe-buttons .btn-primary").length,
0,
"The none are selected"
);
2019-12-09 10:30:34 +11:00
assert.equal(
2019-12-09 12:01:10 +11:00
find(".btn-discourse-subscriptions-subscribe:first-child .interval")
.text()
.trim(),
"Yearly",
2019-12-09 10:30:34 +11:00
"The plan interval is shown"
);
assert.equal(
2019-12-09 12:01:10 +11:00
find(".btn-discourse-subscriptions-subscribe:first-child .amount")
.text()
.trim(),
2019-12-09 10:30:34 +11:00
"$AUD 44.99",
"The plan amount and currency is shown"
);
2019-12-06 13:52:03 +11:00
}
});
2019-12-06 14:33:38 +11:00
componentTest("Discourse Subscriptions payment options plan is selected", {
2019-12-10 10:15:30 +11:00
template: `{{payment-options plans=plans}}`,
2019-12-06 14:33:38 +11:00
beforeEach() {},
async test(assert) {
2019-12-09 12:01:10 +11:00
this.set("plans", [
2019-12-10 10:15:30 +11:00
EmberObject.create({
currency: "aud",
interval: "year",
amountDollars: "44.99"
})
2019-12-09 12:01:10 +11:00
]);
2019-12-06 14:33:38 +11:00
await click(".btn-discourse-subscriptions-subscribe:first-child");
2019-12-10 10:15:30 +11:00
assert.ok(this.get("plans.firstObject.selected"), "it selected the plan");
2019-12-06 14:33:38 +11:00
}
});