/**
 * @jest-environment jsdom
 */
import { renderHook, waitFor } from "@testing-library/react";

import { useSelectableCurrencies } from "./useSelectableCurrencies";
import { getCryptoCurrencyById } from "../../../currencies";
import { setupMockCryptoAssetsStore } from "../../../test-helpers/cryptoAssetsStore";

// Setup mock store for unit tests
setupMockCryptoAssetsStore();

describe("useSelectableCurrencies", () => {
  test("returns an empty array when empty list are passed", async () => {
    const allCurrencies = [];

    const { result } = renderHook(() => useSelectableCurrencies({ allCurrencies }));

    await waitFor(() => {
      expect(result.current).toEqual([]);
    });
  });

  test("returns an empty array when incorrect ids are passed", async () => {
    const allCurrencies = ["ethercoin", "bitether", "polkamos"];

    const { result } = renderHook(() => useSelectableCurrencies({ allCurrencies }));

    await waitFor(() => {
      expect(result.current).toEqual([]);
    });
  });

  test("returns correct currencies for all correct ids, in the same order", async () => {
    const allCurrencies = ["ethereum", "bitcoin", "polkamos"];
    const ethereumCurrency = getCryptoCurrencyById("ethereum");
    const bitcoinCurrency = getCryptoCurrencyById("bitcoin");

    const { result } = renderHook(() => useSelectableCurrencies({ allCurrencies }));

    await waitFor(() => {
      expect(result.current).toHaveLength(2);
      expect(result.current).toEqual([ethereumCurrency, bitcoinCurrency]);
    });
  });
});
