Skip to content

A platform for community discussion. Free, open, simple.

1.7 KB
Raw Blame
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("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 = null;

    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",
    };

    const selectedPlan = tracked(undefined);

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

    assert
      .dom(".btn-discourse-subscriptions-subscribe:first-child .interval")
      .hasText("One-Time Payment", "Shown as one time payment");
  });
});