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

95 lines
2.5 KiB
Plaintext
Raw Normal View History

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