aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Tip
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-12-15 17:12:03 -0300
committerSebastian <sebasjm@gmail.com>2022-12-15 17:12:03 -0300
commitf1f8f818dbe631fbeeba64af9dfcae1aa7842615 (patch)
tree856d3b443556ce271c3e9fdab6aed7ae7728ab65 /packages/taler-wallet-webextension/src/cta/Tip
parentf93bd51499ed34844b666bf6d333227adf4368bf (diff)
downloadwallet-core-f1f8f818dbe631fbeeba64af9dfcae1aa7842615.tar.xz
pretty
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Tip')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Tip/index.ts2
-rw-r--r--packages/taler-wallet-webextension/src/cta/Tip/state.ts10
-rw-r--r--packages/taler-wallet-webextension/src/cta/Tip/test.ts218
3 files changed, 127 insertions, 103 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Tip/index.ts b/packages/taler-wallet-webextension/src/cta/Tip/index.ts
index a29a3eadb..62e0688be 100644
--- a/packages/taler-wallet-webextension/src/cta/Tip/index.ts
+++ b/packages/taler-wallet-webextension/src/cta/Tip/index.ts
@@ -24,7 +24,7 @@ import {
AcceptedView,
IgnoredView,
LoadingUriView,
- ReadyView
+ ReadyView,
} from "./views.js";
export interface Props {
diff --git a/packages/taler-wallet-webextension/src/cta/Tip/state.ts b/packages/taler-wallet-webextension/src/cta/Tip/state.ts
index 0ca213b01..e83755119 100644
--- a/packages/taler-wallet-webextension/src/cta/Tip/state.ts
+++ b/packages/taler-wallet-webextension/src/cta/Tip/state.ts
@@ -20,10 +20,12 @@ import { useBackendContext } from "../../context/backend.js";
import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js";
import { Props, State } from "./index.js";
-export function useComponentState(
- { talerTipUri, onCancel, onSuccess }: Props,
-): State {
- const api = useBackendContext()
+export function useComponentState({
+ talerTipUri,
+ onCancel,
+ onSuccess,
+}: Props): State {
+ const api = useBackendContext();
const tipInfo = useAsyncAsHook(async () => {
if (!talerTipUri) throw Error("ERROR_NO-URI-FOR-TIP");
const tip = await api.wallet.call(WalletApiOperation.PrepareTip, {
diff --git a/packages/taler-wallet-webextension/src/cta/Tip/test.ts b/packages/taler-wallet-webextension/src/cta/Tip/test.ts
index 21ed95218..5688d82a9 100644
--- a/packages/taler-wallet-webextension/src/cta/Tip/test.ts
+++ b/packages/taler-wallet-webextension/src/cta/Tip/test.ts
@@ -36,23 +36,28 @@ describe("Tip CTA states", () => {
talerTipUri: undefined,
onCancel: nullFunction,
onSuccess: nullFunction,
- }
-
- const hookBehavior = await tests.hookBehaveLikeThis(useComponentState, props, [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- ({ status, error }) => {
- expect(status).equals("loading-uri");
- if (!error) expect.fail();
- if (!error.hasError) expect.fail();
- if (error.operational) expect.fail();
- expect(error.message).eq("ERROR_NO-URI-FOR-TIP");
- },
- ], TestingContext)
-
- expect(hookBehavior).deep.equal({ result: "ok" })
+ };
+
+ const hookBehavior = await tests.hookBehaveLikeThis(
+ useComponentState,
+ props,
+ [
+ ({ status, error }) => {
+ expect(status).equals("loading");
+ expect(error).undefined;
+ },
+ ({ status, error }) => {
+ expect(status).equals("loading-uri");
+ if (!error) expect.fail();
+ if (!error.hasError) expect.fail();
+ if (error.operational) expect.fail();
+ expect(error.message).eq("ERROR_NO-URI-FOR-TIP");
+ },
+ ],
+ TestingContext,
+ );
+
+ expect(hookBehavior).deep.equal({ result: "ok" });
expect(handler.getCallingQueueState()).eq("empty");
});
@@ -75,50 +80,58 @@ describe("Tip CTA states", () => {
talerTipUri: "taler://tip/asd",
onCancel: nullFunction,
onSuccess: nullFunction,
- }
-
- const hookBehavior = await tests.hookBehaveLikeThis(useComponentState, props, [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- (state) => {
- if (state.status !== "ready") {
- expect(state).eq({ status: "ready" });
- return;
- }
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
- if (state.accept.onClick === undefined) expect.fail();
-
- handler.addWalletCallResponse(WalletApiOperation.AcceptTip);
- state.accept.onClick();
-
- handler.addWalletCallResponse(WalletApiOperation.PrepareTip, undefined, {
- accepted: true,
- exchangeBaseUrl: "exchange url",
- merchantBaseUrl: "merchant url",
- tipAmountEffective: "EUR:1",
- walletTipId: "tip_id",
- expirationTimestamp: {
- t_s: 1,
- },
- tipAmountRaw: "",
- });
-
- },
- (state) => {
- if (state.status !== "accepted") expect.fail()
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
- },
- ], TestingContext)
-
- expect(hookBehavior).deep.equal({ result: "ok" })
+ };
+
+ const hookBehavior = await tests.hookBehaveLikeThis(
+ useComponentState,
+ props,
+ [
+ ({ status, error }) => {
+ expect(status).equals("loading");
+ expect(error).undefined;
+ },
+ (state) => {
+ if (state.status !== "ready") {
+ expect(state).eq({ status: "ready" });
+ return;
+ }
+ if (state.error) expect.fail();
+ expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
+ expect(state.merchantBaseUrl).eq("merchant url");
+ expect(state.exchangeBaseUrl).eq("exchange url");
+ if (state.accept.onClick === undefined) expect.fail();
+
+ handler.addWalletCallResponse(WalletApiOperation.AcceptTip);
+ state.accept.onClick();
+
+ handler.addWalletCallResponse(
+ WalletApiOperation.PrepareTip,
+ undefined,
+ {
+ accepted: true,
+ exchangeBaseUrl: "exchange url",
+ merchantBaseUrl: "merchant url",
+ tipAmountEffective: "EUR:1",
+ walletTipId: "tip_id",
+ expirationTimestamp: {
+ t_s: 1,
+ },
+ tipAmountRaw: "",
+ },
+ );
+ },
+ (state) => {
+ if (state.status !== "accepted") expect.fail();
+ if (state.error) expect.fail();
+ expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
+ expect(state.merchantBaseUrl).eq("merchant url");
+ expect(state.exchangeBaseUrl).eq("exchange url");
+ },
+ ],
+ TestingContext,
+ );
+
+ expect(hookBehavior).deep.equal({ result: "ok" });
expect(handler.getCallingQueueState()).eq("empty");
});
@@ -140,25 +153,30 @@ describe("Tip CTA states", () => {
talerTipUri: "taler://tip/asd",
onCancel: nullFunction,
onSuccess: nullFunction,
- }
-
- const hookBehavior = await tests.hookBehaveLikeThis(useComponentState, props, [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- (state) => {
- if (state.status !== "ready") expect.fail();
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
-
- //FIXME: add ignore button
- },
- ], TestingContext)
-
- expect(hookBehavior).deep.equal({ result: "ok" })
+ };
+
+ const hookBehavior = await tests.hookBehaveLikeThis(
+ useComponentState,
+ props,
+ [
+ ({ status, error }) => {
+ expect(status).equals("loading");
+ expect(error).undefined;
+ },
+ (state) => {
+ if (state.status !== "ready") expect.fail();
+ if (state.error) expect.fail();
+ expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
+ expect(state.merchantBaseUrl).eq("merchant url");
+ expect(state.exchangeBaseUrl).eq("exchange url");
+
+ //FIXME: add ignore button
+ },
+ ],
+ TestingContext,
+ );
+
+ expect(hookBehavior).deep.equal({ result: "ok" });
expect(handler.getCallingQueueState()).eq("empty");
});
@@ -181,24 +199,28 @@ describe("Tip CTA states", () => {
talerTipUri: "taler://tip/asd",
onCancel: nullFunction,
onSuccess: nullFunction,
- }
-
- const hookBehavior = await tests.hookBehaveLikeThis(useComponentState, props, [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- (state) => {
- if (state.status !== "accepted") expect.fail();
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
- },
- ], TestingContext)
-
- expect(hookBehavior).deep.equal({ result: "ok" })
+ };
+
+ const hookBehavior = await tests.hookBehaveLikeThis(
+ useComponentState,
+ props,
+ [
+ ({ status, error }) => {
+ expect(status).equals("loading");
+ expect(error).undefined;
+ },
+ (state) => {
+ if (state.status !== "accepted") expect.fail();
+ if (state.error) expect.fail();
+ expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
+ expect(state.merchantBaseUrl).eq("merchant url");
+ expect(state.exchangeBaseUrl).eq("exchange url");
+ },
+ ],
+ TestingContext,
+ );
+
+ expect(hookBehavior).deep.equal({ result: "ok" });
expect(handler.getCallingQueueState()).eq("empty");
-
});
});