From fb6aff76d2152d95caa2ba6cb0d91cb01e0687fe Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 6 Jun 2022 00:09:25 -0300 Subject: prettier --- .../src/wallet/CreateManualWithdraw.test.ts | 137 +++---- .../src/wallet/DepositPage.test.ts | 400 +++++++++++---------- 2 files changed, 283 insertions(+), 254 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet') diff --git a/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.test.ts b/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.test.ts index 7a9a5314b..3cfd6930d 100644 --- a/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.test.ts +++ b/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.test.ts @@ -25,15 +25,13 @@ import { SelectFieldHandler, TextFieldHandler } from "../mui/handlers.js"; import { mountHook } from "../test-utils.js"; import { useComponentState } from "./CreateManualWithdraw.js"; - const exchangeListWithARSandUSD = { - "url1": "USD", - "url2": "ARS", - "url3": "ARS", + url1: "USD", + url2: "ARS", + url3: "ARS", }; -const exchangeListEmpty = { -}; +const exchangeListEmpty = {}; describe("CreateManualWithdraw states", () => { it("should set noExchangeFound when exchange list is empty", () => { @@ -41,9 +39,9 @@ describe("CreateManualWithdraw states", () => { useComponentState(exchangeListEmpty, undefined, undefined), ); - const { noExchangeFound } = getLastResultOrThrow() + const { noExchangeFound } = getLastResultOrThrow(); - expect(noExchangeFound).equal(true) + expect(noExchangeFound).equal(true); }); it("should set noExchangeFound when exchange list doesn't include selected currency", () => { @@ -51,20 +49,19 @@ describe("CreateManualWithdraw states", () => { useComponentState(exchangeListWithARSandUSD, undefined, "COL"), ); - const { noExchangeFound } = getLastResultOrThrow() + const { noExchangeFound } = getLastResultOrThrow(); - expect(noExchangeFound).equal(true) + expect(noExchangeFound).equal(true); }); - it("should select the first exchange from the list", () => { const { getLastResultOrThrow } = mountHook(() => useComponentState(exchangeListWithARSandUSD, undefined, undefined), ); - const { exchange } = getLastResultOrThrow() + const { exchange } = getLastResultOrThrow(); - expect(exchange.value).equal("url1") + expect(exchange.value).equal("url1"); }); it("should select the first exchange with the selected currency", () => { @@ -72,9 +69,9 @@ describe("CreateManualWithdraw states", () => { useComponentState(exchangeListWithARSandUSD, undefined, "ARS"), ); - const { exchange } = getLastResultOrThrow() + const { exchange } = getLastResultOrThrow(); - expect(exchange.value).equal("url2") + expect(exchange.value).equal("url2"); }); it("should change the exchange when currency change", async () => { @@ -82,22 +79,20 @@ describe("CreateManualWithdraw states", () => { useComponentState(exchangeListWithARSandUSD, undefined, "ARS"), ); - { - const { exchange, currency } = getLastResultOrThrow() + const { exchange, currency } = getLastResultOrThrow(); - expect(exchange.value).equal("url2") + expect(exchange.value).equal("url2"); if (currency.onChange === undefined) expect.fail(); - currency.onChange("USD") + currency.onChange("USD"); } - await waitNextUpdate() + await waitNextUpdate(); { - const { exchange } = getLastResultOrThrow() - expect(exchange.value).equal("url1") + const { exchange } = getLastResultOrThrow(); + expect(exchange.value).equal("url1"); } - }); it("should change the currency when exchange change", async () => { @@ -106,22 +101,22 @@ describe("CreateManualWithdraw states", () => { ); { - const { exchange, currency } = getLastResultOrThrow() + const { exchange, currency } = getLastResultOrThrow(); - expect(exchange.value).equal("url2") - expect(currency.value).equal("ARS") + expect(exchange.value).equal("url2"); + expect(currency.value).equal("ARS"); if (exchange.onChange === undefined) expect.fail(); - exchange.onChange("url1") + exchange.onChange("url1"); } - await waitNextUpdate() + await waitNextUpdate(); { - const { exchange, currency } = getLastResultOrThrow() + const { exchange, currency } = getLastResultOrThrow(); - expect(exchange.value).equal("url1") - expect(currency.value).equal("USD") + expect(exchange.value).equal("url1"); + expect(currency.value).equal("USD"); } }); @@ -131,21 +126,23 @@ describe("CreateManualWithdraw states", () => { ); { - const { amount, parsedAmount } = getLastResultOrThrow() + const { amount, parsedAmount } = getLastResultOrThrow(); - expect(parsedAmount).equal(undefined) + expect(parsedAmount).equal(undefined); - amount.onInput("12") + amount.onInput("12"); } - await waitNextUpdate() + await waitNextUpdate(); { - const { parsedAmount } = getLastResultOrThrow() + const { parsedAmount } = getLastResultOrThrow(); expect(parsedAmount).deep.equals({ - value: 12, fraction: 0, currency: "ARS" - }) + value: 12, + fraction: 0, + currency: "ARS", + }); } }); @@ -154,67 +151,79 @@ describe("CreateManualWithdraw states", () => { useComponentState(exchangeListWithARSandUSD, undefined, "ARS"), ); - await defaultTestForInputText(waitNextUpdate, () => getLastResultOrThrow().amount) - }) + await defaultTestForInputText( + waitNextUpdate, + () => getLastResultOrThrow().amount, + ); + }); it("should have an exchange selector ", async () => { const { getLastResultOrThrow, waitNextUpdate } = mountHook(() => useComponentState(exchangeListWithARSandUSD, undefined, "ARS"), ); - await defaultTestForInputSelect(waitNextUpdate, () => getLastResultOrThrow().exchange) - }) + await defaultTestForInputSelect( + waitNextUpdate, + () => getLastResultOrThrow().exchange, + ); + }); it("should have a currency selector ", async () => { const { getLastResultOrThrow, waitNextUpdate } = mountHook(() => useComponentState(exchangeListWithARSandUSD, undefined, "ARS"), ); - await defaultTestForInputSelect(waitNextUpdate, () => getLastResultOrThrow().currency) - }) - + await defaultTestForInputSelect( + waitNextUpdate, + () => getLastResultOrThrow().currency, + ); + }); }); - -async function defaultTestForInputText(awaiter: () => Promise, getField: () => TextFieldHandler): Promise { - let nextValue = '' +async function defaultTestForInputText( + awaiter: () => Promise, + getField: () => TextFieldHandler, +): Promise { + let nextValue = ""; { - const field = getField() + const field = getField(); const initialValue = field.value; - nextValue = `${initialValue} something else` - field.onInput(nextValue) + nextValue = `${initialValue} something else`; + field.onInput(nextValue); } - await awaiter() + await awaiter(); { - const field = getField() - expect(field.value).equal(nextValue) + const field = getField(); + expect(field.value).equal(nextValue); } } - -async function defaultTestForInputSelect(awaiter: () => Promise, getField: () => SelectFieldHandler): Promise { - let nextValue = '' +async function defaultTestForInputSelect( + awaiter: () => Promise, + getField: () => SelectFieldHandler, +): Promise { + let nextValue = ""; { const field = getField(); const initialValue = field.value; - const keys = Object.keys(field.list) - const nextIdx = keys.indexOf(initialValue) + 1 + const keys = Object.keys(field.list); + const nextIdx = keys.indexOf(initialValue) + 1; if (keys.length < nextIdx) { - throw new Error('no enough values') + throw new Error("no enough values"); } - nextValue = keys[nextIdx] + nextValue = keys[nextIdx]; if (field.onChange === undefined) expect.fail(); - field.onChange(nextValue) + field.onChange(nextValue); } - await awaiter() + await awaiter(); { const field = getField(); - expect(field.value).equal(nextValue) + expect(field.value).equal(nextValue); } } diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts index 5fc55934d..cea5dd5ca 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts @@ -19,392 +19,412 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { Amounts, Balance, BalancesResponse, parsePaytoUri } from "@gnu-taler/taler-util"; +import { + Amounts, + Balance, + BalancesResponse, + parsePaytoUri, +} from "@gnu-taler/taler-util"; import { DepositGroupFees } from "@gnu-taler/taler-wallet-core/src/operations/deposits"; import { expect } from "chai"; import { mountHook } from "../test-utils.js"; import { useComponentState } from "./DepositPage.js"; import * as wxApi from "../wxApi.js"; - -const currency = "EUR" +const currency = "EUR"; const withoutFee = async (): Promise => ({ coin: Amounts.parseOrThrow(`${currency}:0`), wire: Amounts.parseOrThrow(`${currency}:0`), - refresh: Amounts.parseOrThrow(`${currency}:0`) -}) + refresh: Amounts.parseOrThrow(`${currency}:0`), +}); const withSomeFee = async (): Promise => ({ coin: Amounts.parseOrThrow(`${currency}:1`), wire: Amounts.parseOrThrow(`${currency}:1`), - refresh: Amounts.parseOrThrow(`${currency}:1`) -}) + refresh: Amounts.parseOrThrow(`${currency}:1`), +}); -const freeJustForIBAN = async (account: string): Promise => /IBAN/i.test(account) ? withoutFee() : withSomeFee() +const freeJustForIBAN = async (account: string): Promise => + /IBAN/i.test(account) ? withoutFee() : withSomeFee(); -const someBalance = [{ - available: 'EUR:10' -} as Balance] +const someBalance = [ + { + available: "EUR:10", + } as Balance, +]; const nullFunction: any = () => null; type VoidFunction = () => void; describe("DepositPage states", () => { it("should have status 'no-balance' when balance is empty", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(currency, nullFunction, nullFunction, { - getBalance: async () => ({ - balances: [{ available: `${currency}:0`, }] - } as Partial), - listKnownBankAccounts: async () => ({ accounts: [] }) - } as Partial as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(currency, nullFunction, nullFunction, { + getBalance: async () => + ({ + balances: [{ available: `${currency}:0` }], + } as Partial), + listKnownBankAccounts: async () => ({ accounts: [] }), + } as Partial as any), + ); { - const { status } = getLastResultOrThrow() - expect(status).equal("loading") + const { status } = getLastResultOrThrow(); + expect(status).equal("loading"); } - await waitNextUpdate() + await waitNextUpdate(); { - const { status } = getLastResultOrThrow() - expect(status).equal("no-balance") + const { status } = getLastResultOrThrow(); + expect(status).equal("no-balance"); } - await assertNoPendingUpdate() - + await assertNoPendingUpdate(); }); it("should have status 'no-accounts' when balance is not empty and accounts is empty", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(currency, nullFunction, nullFunction, { - getBalance: async () => ({ - balances: [{ available: `${currency}:1`, }] - } as Partial), - listKnownBankAccounts: async () => ({ accounts: [] }) - } as Partial as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(currency, nullFunction, nullFunction, { + getBalance: async () => + ({ + balances: [{ available: `${currency}:1` }], + } as Partial), + listKnownBankAccounts: async () => ({ accounts: [] }), + } as Partial as any), + ); { - const { status } = getLastResultOrThrow() - expect(status).equal("loading") + const { status } = getLastResultOrThrow(); + expect(status).equal("loading"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "no-accounts") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; } - await assertNoPendingUpdate() - + await assertNoPendingUpdate(); }); const ibanPayto = parsePaytoUri("payto://iban/ES8877998399652238")!; - const talerBankPayto = parsePaytoUri("payto://x-taler-bank/ES8877998399652238")!; + const talerBankPayto = parsePaytoUri( + "payto://x-taler-bank/ES8877998399652238", + )!; it("should have status 'ready' but unable to deposit ", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(currency, nullFunction, nullFunction, { - getBalance: async () => ({ - balances: [{ available: `${currency}:1`, }] - } as Partial), - listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }) - } as Partial as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(currency, nullFunction, nullFunction, { + getBalance: async () => + ({ + balances: [{ available: `${currency}:1` }], + } as Partial), + listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }), + } as Partial as any), + ); { - const { status } = getLastResultOrThrow() - expect(status).equal("loading") + const { status } = getLastResultOrThrow(); + expect(status).equal("loading"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("0") + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("0"); expect(r.depositHandler.onClick).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should not be able to deposit more than the balance ", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(currency, nullFunction, nullFunction, { - getBalance: async () => ({ - balances: [{ available: `${currency}:1`, }] - } as Partial), - listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }), - getFeeForDeposit: withoutFee - } as Partial as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(currency, nullFunction, nullFunction, { + getBalance: async () => + ({ + balances: [{ available: `${currency}:1` }], + } as Partial), + listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }), + getFeeForDeposit: withoutFee, + } as Partial as any), + ); { - const { status } = getLastResultOrThrow() - expect(status).equal("loading") + const { status } = getLastResultOrThrow(); + expect(status).equal("loading"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("0") + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("0"); expect(r.depositHandler.onClick).undefined; - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)) + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)); - r.amount.onInput("10") + r.amount.onInput("10"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("10") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)) + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("10"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)); expect(r.depositHandler.onClick).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should calculate the fee upon entering amount ", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(currency, nullFunction, nullFunction, { - getBalance: async () => ({ - balances: [{ available: `${currency}:1`, }] - } as Partial), - listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }), - getFeeForDeposit: withSomeFee - } as Partial as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(currency, nullFunction, nullFunction, { + getBalance: async () => + ({ + balances: [{ available: `${currency}:1` }], + } as Partial), + listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }), + getFeeForDeposit: withSomeFee, + } as Partial as any), + ); { - const { status } = getLastResultOrThrow() - expect(status).equal("loading") + const { status } = getLastResultOrThrow(); + expect(status).equal("loading"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("0") + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("0"); expect(r.depositHandler.onClick).undefined; - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)) + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)); - r.amount.onInput("10") + r.amount.onInput("10"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("10") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:7`)) + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("10"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:7`)); expect(r.depositHandler.onClick).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should calculate the fee upon selecting account ", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(currency, nullFunction, nullFunction, { - getBalance: async () => ({ - balances: [{ available: `${currency}:1`, }] - } as Partial), - listKnownBankAccounts: async () => ({ accounts: [ibanPayto, talerBankPayto] }), - getFeeForDeposit: freeJustForIBAN - } as Partial as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(currency, nullFunction, nullFunction, { + getBalance: async () => + ({ + balances: [{ available: `${currency}:1` }], + } as Partial), + listKnownBankAccounts: async () => ({ + accounts: [ibanPayto, talerBankPayto], + }), + getFeeForDeposit: freeJustForIBAN, + } as Partial as any), + ); { - const { status } = getLastResultOrThrow() - expect(status).equal("loading") + const { status } = getLastResultOrThrow(); + expect(status).equal("loading"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("0") + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("0"); expect(r.depositHandler.onClick).undefined; - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)) + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)); if (r.account.onChange === undefined) expect.fail(); - r.account.onChange("1") + r.account.onChange("1"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("1") - expect(r.amount.value).eq("0") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:0`)) + expect(r.account.value).eq("1"); + expect(r.amount.value).eq("0"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:0`)); expect(r.depositHandler.onClick).undefined; - r.amount.onInput("10") + r.amount.onInput("10"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("1") - expect(r.amount.value).eq("10") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:7`)) + expect(r.account.value).eq("1"); + expect(r.amount.value).eq("10"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:7`)); expect(r.depositHandler.onClick).undefined; if (r.account.onChange === undefined) expect.fail(); - r.account.onChange("0") + r.account.onChange("0"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("10") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:10`)) + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("10"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:10`)); expect(r.depositHandler.onClick).undefined; - } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); - it("should be able to deposit if has the enough balance ", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(currency, nullFunction, nullFunction, { - getBalance: async () => ({ - balances: [{ available: `${currency}:15`, }] - } as Partial), - listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }), - getFeeForDeposit: withSomeFee - } as Partial as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(currency, nullFunction, nullFunction, { + getBalance: async () => + ({ + balances: [{ available: `${currency}:15` }], + } as Partial), + listKnownBankAccounts: async () => ({ accounts: [ibanPayto] }), + getFeeForDeposit: withSomeFee, + } as Partial as any), + ); { - const { status } = getLastResultOrThrow() - expect(status).equal("loading") + const { status } = getLastResultOrThrow(); + expect(status).equal("loading"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("0") + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("0"); expect(r.depositHandler.onClick).undefined; - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)) + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`)); - r.amount.onInput("10") + r.amount.onInput("10"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("10") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:7`)) + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("10"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:7`)); expect(r.depositHandler.onClick).not.undefined; - r.amount.onInput("13") + r.amount.onInput("13"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("13") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:10`)) + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("13"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:10`)); expect(r.depositHandler.onClick).not.undefined; - r.amount.onInput("15") + r.amount.onInput("15"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("15") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:12`)) + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("15"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:12`)); expect(r.depositHandler.onClick).not.undefined; - r.amount.onInput("17") + r.amount.onInput("17"); } - await waitNextUpdate() + await waitNextUpdate(); { - const r = getLastResultOrThrow() + const r = getLastResultOrThrow(); if (r.status !== "ready") expect.fail(); expect(r.cancelHandler.onClick).not.undefined; expect(r.currency).eq(currency); - expect(r.account.value).eq("0") - expect(r.amount.value).eq("17") - expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)) - expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:14`)) + expect(r.account.value).eq("0"); + expect(r.amount.value).eq("17"); + expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:3`)); + expect(r.totalToDeposit).deep.eq(Amounts.parseOrThrow(`${currency}:14`)); expect(r.depositHandler.onClick).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); - -}); \ No newline at end of file +}); -- cgit v1.2.3