diff options
author | Sebastian <sebasjm@gmail.com> | 2023-04-21 10:47:47 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-04-21 10:47:47 -0300 |
commit | f470f167e32d8f7775ad994f09afb1d353b0b300 (patch) | |
tree | 3a1f2a040bb09d6639c81436b90b416fb8044f91 /packages/anastasis-webui/src/pages/home/AddingProviderScreen | |
parent | 6dcc488a2c8fd681941e5d3b62bb04af7669888e (diff) | |
download | wallet-core-f470f167e32d8f7775ad994f09afb1d353b0b300.tar.gz wallet-core-f470f167e32d8f7775ad994f09afb1d353b0b300.tar.bz2 wallet-core-f470f167e32d8f7775ad994f09afb1d353b0b300.zip |
integrate anastasis to the web-utils testing api
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/AddingProviderScreen')
3 files changed, 46 insertions, 36 deletions
diff --git a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts index 009ab20a2..f80f1c464 100644 --- a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts +++ b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts @@ -25,7 +25,11 @@ interface Props { notifications?: Notification[]; } -export default function useComponentState({ providerType, onCancel, notifications = [] }: Props): State { +export default function useComponentState({ + providerType, + onCancel, + notifications = [], +}: Props): State { const reducer = useAnastasisContext(); const [providerURL, setProviderURL] = useState(""); @@ -39,9 +43,9 @@ export default function useComponentState({ providerType, onCancel, notification const allAuthProviders = !reducer || - !reducer.currentReducerState || - reducer.currentReducerState.reducer_type === "error" || - !reducer.currentReducerState.authentication_providers + !reducer.currentReducerState || + reducer.currentReducerState.reducer_type === "error" || + !reducer.currentReducerState.authentication_providers ? {} : reducer.currentReducerState.authentication_providers; @@ -58,7 +62,12 @@ export default function useComponentState({ providerType, onCancel, notification prev[p.status].push({ ...p, url }); return prev; }, - { "not-contacted": [], disabled: [], error: [], ok: [] } as AuthProvByStatusMap, + { + "not-contacted": [], + disabled: [], + error: [], + ok: [], + } as AuthProvByStatusMap, ); const authProviders = authProvidersByStatus["ok"].map((p) => p.url); @@ -98,10 +107,10 @@ export default function useComponentState({ providerType, onCancel, notification const addProvider = async (provider_url: string): Promise<void> => { await reducer.transition("add_provider", { provider_url }); onCancel(); - } + }; const deleteProvider = async (provider_url: string): Promise<void> => { reducer.transition("delete_provider", { provider_url }); - } + }; let errors = !providerURL ? "Add provider URL" : undefined; let url: string | undefined; @@ -110,7 +119,7 @@ export default function useComponentState({ providerType, onCancel, notification } catch { errors = "Check the URL"; } - const _url = url + const _url = url; if (!!error && !errors) { errors = error; @@ -130,21 +139,19 @@ export default function useComponentState({ providerType, onCancel, notification setProviderURL: async (s: string) => setProviderURL(s), errors, error, - notifications - } + notifications, + }; if (!providerLabel) { return { status: "without-type", - ...commonState - } + ...commonState, + }; } else { return { status: "with-type", providerLabel, - ...commonState - } + ...commonState, + }; } - } - diff --git a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/stories.tsx b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/stories.tsx index 268189ed8..6ce22e56c 100644 --- a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/stories.tsx +++ b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/stories.tsx @@ -20,7 +20,7 @@ */ import { AuthenticationProviderStatusOk } from "@gnu-taler/anastasis-core"; -import { createExampleWithoutAnastasis } from "../../../utils/index.jsx"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { WithoutProviderType, WithProviderType } from "./views.jsx"; export default { @@ -34,7 +34,7 @@ export default { }, }; -export const NewProvider = createExampleWithoutAnastasis(WithoutProviderType, { +export const NewProvider = tests.createExample(WithoutProviderType, { authProvidersByStatus: { ok: [ { @@ -57,7 +57,7 @@ export const NewProvider = createExampleWithoutAnastasis(WithoutProviderType, { notifications: [], }); -export const NewProviderWithoutProviderList = createExampleWithoutAnastasis( +export const NewProviderWithoutProviderList = tests.createExample( WithoutProviderType, { authProvidersByStatus: { @@ -70,7 +70,7 @@ export const NewProviderWithoutProviderList = createExampleWithoutAnastasis( }, ); -export const NewSmsProvider = createExampleWithoutAnastasis(WithProviderType, { +export const NewSmsProvider = tests.createExample(WithProviderType, { authProvidersByStatus: { ok: [], "not-contacted": [], @@ -81,7 +81,7 @@ export const NewSmsProvider = createExampleWithoutAnastasis(WithProviderType, { notifications: [], }); -export const NewIBANProvider = createExampleWithoutAnastasis(WithProviderType, { +export const NewIBANProvider = tests.createExample(WithProviderType, { authProvidersByStatus: { ok: [], "not-contacted": [], diff --git a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/test.ts b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/test.ts index d051d7c0b..8d0e69111 100644 --- a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/test.ts +++ b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/test.ts @@ -20,23 +20,26 @@ */ import { expect } from "chai"; -import { mountHook } from "../../../test-utils.js"; import useComponentState from "./state.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; describe("AddingProviderScreen states", () => { - it("should have status 'no-balance' when balance is empty", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState({ onCancel: async () => { null } }), - ); - - { - const { status } = getLastResultOrThrow(); - expect(status).equal("no-reducer"); - } - - await assertNoPendingUpdate(); - + it("should not load more if has reach the end", async () => { + const hookBehavior = await tests.hookBehaveLikeThis( + () => { + return useComponentState({ + providerType: "email", + async onCancel() {}, + }); + }, + {}, + [ + ({ status }) => { + expect(status).eq("no-reducer"); + }, + ], + ); + + expect(hookBehavior).deep.eq({ result: "ok" }); }); - }); |