@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
60 lines • 2.84 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @jest-environment jsdom
*/
require("../../../__tests__/test-helpers/dom-polyfill");
const react_1 = require("@testing-library/react");
const cryptoassets_1 = require("@ledgerhq/cryptoassets");
const _1 = require(".");
const account_1 = require("@ledgerhq/coin-framework/mocks/account");
const account_2 = require("../../../mock/account");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const BTC = (0, cryptoassets_1.getCryptoCurrencyById)("bitcoin");
const ETH = (0, cryptoassets_1.getCryptoCurrencyById)("ethereum");
const usdtToken = (0, cryptoassets_1.findTokenById)("ethereum/erc20/usd_tether__erc20_");
if (!usdtToken)
throw new Error("USDT token not found");
const USDT = usdtToken;
const selectedAccount = (0, account_2.genAccount)("mocked-account-selected", { currency: ETH });
const accounts = [
(0, account_2.genAccount)("mocked-account-1", { currency: BTC }),
(0, account_2.genAccount)("mocked-account-2", { currency: ETH }),
];
const subAccount = (0, account_1.genTokenAccount)(1, accounts[1], USDT);
describe("useToState", () => {
const defaultProps = { accounts, fromCurrencyAccount: selectedAccount };
it("should initialize a blank state", () => {
const { result } = (0, react_1.renderHook)(_1.useToState, { initialProps: defaultProps });
expect(result.current.toState).toMatchObject(_1.selectorStateDefaultValues);
});
it("should set the account", async () => {
const [currency, account, parentAccount] = [USDT, subAccount, accounts[1]];
const { result } = (0, react_1.renderHook)(_1.useToState, { initialProps: defaultProps });
(0, react_1.act)(() => result.current.setToAccount(currency, account, parentAccount));
expect(result.current.toState).toMatchObject({
account,
parentAccount,
currency,
});
});
it("should set the amount", () => {
const amount = new bignumber_js_1.default(10);
const { result } = (0, react_1.renderHook)(_1.useToState, { initialProps: defaultProps });
(0, react_1.act)(() => result.current.setToAmount(amount));
expect(result.current.toState.amount).toBe(amount);
});
it("should set the currency", () => {
const { result } = (0, react_1.renderHook)(_1.useToState, { initialProps: defaultProps });
(0, react_1.act)(() => result.current.setToCurrency(BTC));
expect(result.current.toState).toMatchObject({
account: accounts[0],
parentAccount: null,
currency: BTC,
});
});
});
//# sourceMappingURL=useToState.test.js.map