Skip to content

Commit

Permalink
DEV: Update components tests (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
CvX authored Nov 29, 2024
1 parent 3149828 commit 692f410
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 131 deletions.
53 changes: 53 additions & 0 deletions test/javascripts/integration/components/payment-options-test.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { tracked } from "@glimmer/tracking";
import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import PaymentOptions from "discourse/plugins/discourse-subscriptions/discourse/components/payment-options";

module("Subscriptions | payment-options", function (hooks) {
setupRenderingTest(hooks);

test("payment options have no plans", async function (assert) {
await render(<template><PaymentOptions @plans={{false}} /></template>);

assert
.dom(".btn-discourse-subscriptions-subscribe")
.doesNotExist("The plan buttons are not shown");
});

test("payment options has content", async function (assert) {
const plans = [
{
currency: "aud",
recurring: { interval: "year" },
amountDollars: "44.99",
},
{
currency: "gdp",
recurring: { interval: "month" },
amountDollars: "9.99",
},
];

class State {
@tracked selectedPlan;
}

const testState = new State();

await render(<template>
<PaymentOptions
@plans={{plans}}
@selectedPlan={{testState.selectedPlan}}
/>
</template>);

assert.dom(".btn-discourse-subscriptions-subscribe").exists({ count: 2 });

assert.strictEqual(
this.selectedPlan,
undefined,
"No plans are selected by default"
);
});
});
53 changes: 0 additions & 53 deletions test/javascripts/integration/components/payment-options-test.js

This file was deleted.

57 changes: 57 additions & 0 deletions test/javascripts/integration/components/payment-plan-test.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { tracked } from "@glimmer/tracking";
import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import PaymentPlan from "discourse/plugins/discourse-subscriptions/discourse/components/payment-plan";

module("Subscriptions | payment-plan", function (hooks) {
setupRenderingTest(hooks);

test("Payment plan subscription button rendered", async function (assert) {
const plan = {
type: "recurring",
currency: "aud",
recurring: { interval: "year" },
amountDollars: "44.99",
};
let selectedPlan;

await render(<template>
<PaymentPlan @plan={{plan}} @selectedPlan={{selectedPlan}} />
</template>);

assert
.dom(".btn-discourse-subscriptions-subscribe")
.exists("The payment button is shown");

assert
.dom(".btn-discourse-subscriptions-subscribe:first-child .interval")
.hasText("Yearly", "The plan interval is shown -- Yearly");

assert
.dom(".btn-discourse-subscriptions-subscribe:first-child .amount")
.hasText("$44.99", "The plan amount and currency is shown");
});

test("Payment plan one-time-payment button rendered", async function (assert) {
const plan = {
type: "one_time",
currency: "USD",
amountDollars: "3.99",
};

class State {
@tracked selectedPlan;
}

const testState = new State();

await render(<template>
<PaymentPlan @plan={{plan}} @selectedPlan={{testState.selectedPlan}} />
</template>);

assert
.dom(".btn-discourse-subscriptions-subscribe:first-child .interval")
.hasText("One-Time Payment", "Shown as one time payment");
});
});
78 changes: 0 additions & 78 deletions test/javascripts/integration/components/payment-plan-test.js

This file was deleted.

0 comments on commit 692f410

Please sign in to comment.