Skip to content

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

1.4 KB
Raw Blame
import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import MinimalGamificationLeaderboard from "discourse/plugins/discourse-gamification/discourse/components/minimal-gamification-leaderboard";

module(
  "Discourse Gamification | Component | MinimalGamificationLeaderboard",
  function (hooks) {
    setupRenderingTest(hooks);

    test("regular leaderboard endpoint", async function (assert) {
      pretender.get("/leaderboard", () =>
        response({
          leaderboard: "",
          personal: "",
          users: [{ id: 1, username: "foo" }],
        })
      );

      await render(<template><MinimalGamificationLeaderboard /></template>);

      assert.dom(".user__name").hasText("foo");
    });

    test("leaderboard by id and with custom user count", async function (assert) {
      pretender.get("/leaderboard/3", ({ queryParams }) => {
        assert.strictEqual(queryParams.user_limit, "5");

        return response({
          leaderboard: "",
          personal: "",
          users: [{ id: 1, username: "foo" }],
        });
      });

      await render(
        <template>
          <MinimalGamificationLeaderboard @count="5" @id="3" />
        </template>
      );

      assert.dom(".user__name").hasText("foo");
    });
  }
);