show the plans in the buttons proper

This commit is contained in:
Rimian Perkins 2019-12-09 12:01:10 +11:00
parent 71d6c6dab2
commit 1c31884475
4 changed files with 23 additions and 12 deletions

View File

@ -5,12 +5,10 @@ import Subscription from "discourse/plugins/discourse-subscriptions/discourse/mo
export default Discourse.Route.extend({ export default Discourse.Route.extend({
model(params) { model(params) {
const product_id = params["subscription-id"]; const product_id = params["subscription-id"];
const product = Product.find(product_id);
const product = Product.find(product_id);
const subscription = Subscription.create(); const subscription = Subscription.create();
const plans = Plan.findAll({ product_id: product_id }).then(results => const plans = Plan.findAll({ product_id: product_id });
results.map(p => ({ id: p.id, name: p.subscriptionRate }))
);
return Ember.RSVP.hash({ plans, product, subscription }); return Ember.RSVP.hash({ plans, product, subscription });
} }

View File

@ -18,7 +18,7 @@
class="btn btn-discourse-subscriptions-subscribe" class="btn btn-discourse-subscriptions-subscribe"
}} }}
<div class="interval"> <div class="interval">
{{plan.interval}} {{i18n (concat "discourse_subscriptions.plans.interval.adverb." plan.interval)}}
</div> </div>
<span class="amount"> <span class="amount">
{{format-currency plan.currency plan.amountDollars}} {{format-currency plan.currency plan.amountDollars}}

View File

@ -25,6 +25,12 @@ en:
subscriptions: Subscriptions subscriptions: Subscriptions
subscribe: Subscribe subscribe: Subscribe
billing: Billing billing: Billing
plans:
interval:
adverb:
week: Weekly
month: Monthly
year: Yearly
user: user:
plans: plans:
rate: Rate rate: Rate

View File

@ -21,8 +21,8 @@ componentTest("Discourse Subscriptions payment options has content", {
async test(assert) { async test(assert) {
this.set("plans", [ this.set("plans", [
{ currency: 'AUD', interval: 'year', amountDollars: "44.99" }, { currency: "aud", interval: "year", amountDollars: "44.99" },
{ currency: 'GDP', interval: 'month', amountDollars: "9.99" }, { currency: "gdp", interval: "month", amountDollars: "9.99" }
]); ]);
assert.equal( assert.equal(
@ -36,12 +36,16 @@ componentTest("Discourse Subscriptions payment options has content", {
"The none are selected" "The none are selected"
); );
assert.equal( assert.equal(
find(".btn-discourse-subscriptions-subscribe:first-child .interval").text().trim(), find(".btn-discourse-subscriptions-subscribe:first-child .interval")
"year", .text()
.trim(),
"Yearly",
"The plan interval is shown" "The plan interval is shown"
); );
assert.equal( assert.equal(
find(".btn-discourse-subscriptions-subscribe:first-child .amount").text().trim(), find(".btn-discourse-subscriptions-subscribe:first-child .amount")
.text()
.trim(),
"$AUD 44.99", "$AUD 44.99",
"The plan amount and currency is shown" "The plan amount and currency is shown"
); );
@ -55,10 +59,13 @@ componentTest("Discourse Subscriptions payment options plan is selected", {
async test(assert) { async test(assert) {
assert.expect(1); assert.expect(1);
this.set("plans", [1, 2]); this.set("plans", [
{ currency: "aud", interval: "year", amountDollars: "44.99" },
{ currency: "gdp", interval: "month", amountDollars: "9.99" }
]);
this.set("selectPlan", function(plan) { this.set("selectPlan", function(plan) {
assert.equal(plan, 1, "the plan is selected"); assert.equal(plan, this.get('plans.firstObject'), "the plan is selected");
}); });
await click(".btn-discourse-subscriptions-subscribe:first-child"); await click(".btn-discourse-subscriptions-subscribe:first-child");