@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
64 lines • 3.01 kB
JavaScript
/**
* @jest-environment jsdom
*/
import { renderHook } from "@testing-library/react";
import { usePickDefaultCurrency } from "./usePickDefaultCurrency";
import { getCryptoCurrencyById } from "../../../currencies";
describe("usePickDefaultCurrency", () => {
const setCurrency = jest.fn();
beforeEach(() => {
setCurrency.mockClear();
});
test("do nothing when the passed currency is valid", () => {
const currencies = [
getCryptoCurrencyById("ethereum"),
getCryptoCurrencyById("bitcoin"),
getCryptoCurrencyById("bsc"),
];
renderHook(() => usePickDefaultCurrency(currencies, getCryptoCurrencyById("ethereum"), setCurrency));
expect(setCurrency).toHaveBeenCalledTimes(0);
});
test("do nothing if the currency is undefined/null and the currencies list don't include eth/btc", () => {
const currencies = [
getCryptoCurrencyById("solana"),
getCryptoCurrencyById("polkadot"),
getCryptoCurrencyById("bsc"),
];
renderHook(() => usePickDefaultCurrency(currencies, undefined, setCurrency));
expect(setCurrency).toHaveBeenCalledTimes(0);
});
test("do nothing if the currency passed isn't valid in the list and the currencies list don't include eth/btc", () => {
const currencies = [
getCryptoCurrencyById("solana"),
getCryptoCurrencyById("polkadot"),
getCryptoCurrencyById("bsc"),
];
renderHook(() => usePickDefaultCurrency(currencies, getCryptoCurrencyById("stellar"), setCurrency));
expect(setCurrency).toHaveBeenCalledTimes(0);
});
test("returns the ethereum currency if the passed currency isn't valid and ethereum comes before bitcoin in the list", () => {
const ethereumCurrency = getCryptoCurrencyById("ethereum");
const currencies = [
getCryptoCurrencyById("bsc"),
ethereumCurrency,
getCryptoCurrencyById("bitcoin"),
getCryptoCurrencyById("polkadot"),
];
renderHook(() => usePickDefaultCurrency(currencies, getCryptoCurrencyById("stellar"), setCurrency));
expect(setCurrency).toHaveBeenCalledTimes(1);
expect(setCurrency).toHaveBeenCalledWith(ethereumCurrency);
});
test("returns the bitcoin currency if the passed currency isn't valid and bitcoin comes before ethereum in the list", () => {
const bitcoinCurrency = getCryptoCurrencyById("bitcoin");
const currencies = [
getCryptoCurrencyById("bsc"),
bitcoinCurrency,
getCryptoCurrencyById("ethereum"),
getCryptoCurrencyById("polkadot"),
];
renderHook(() => usePickDefaultCurrency(currencies, getCryptoCurrencyById("stellar"), setCurrency));
expect(setCurrency).toHaveBeenCalledTimes(1);
expect(setCurrency).toHaveBeenCalledWith(bitcoinCurrency);
});
});
//# sourceMappingURL=usePickDefaultCurrency.test.js.map