From 40c6d7d04d4a4ac5c1981a73b9f8c91572b1072d Mon Sep 17 00:00:00 2001 From: goga-m Date: Wed, 7 Oct 2020 18:25:12 +0300 Subject: [PATCH 1/3] feat: require password for protected actions in `Welcome` --- src/domains/profile/pages/Welcome/Welcome.tsx | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/domains/profile/pages/Welcome/Welcome.tsx b/src/domains/profile/pages/Welcome/Welcome.tsx index b68ae73e86..e312df1981 100644 --- a/src/domains/profile/pages/Welcome/Welcome.tsx +++ b/src/domains/profile/pages/Welcome/Welcome.tsx @@ -25,6 +25,7 @@ export const Welcome = () => { const [deletingProfileId, setDeletingProfileId] = useState(); const [selectedProfile, setSelectedProfile] = useState(); + const [requestedAction, setRequestedAction] = useState(); const profileCardActions = [ { label: t("COMMON.SETTINGS"), value: "setting" }, @@ -43,10 +44,32 @@ export const Welcome = () => { const closeSignInModal = () => { setSelectedProfile(undefined); + setRequestedAction(undefined); }; - const handleProfileCardAction = (profile: Profile, action: any) => { + const handleClick = (profile: Profile) => { + if (profile.usesPassword()) { + setSelectedProfile(profile); + setRequestedAction({ label: "Homepage", value: "home" }); + } else { + navigateToProfile(profile.id()); + } + }; + + const handleProfileAction = (profile: Profile, action: any) => { + if (profile.usesPassword()) { + setRequestedAction(action); + setSelectedProfile(profile); + } else { + handleRequestedAction(profile, action); + } + }; + + const handleRequestedAction = (profile: Profile, action: any) => { switch (action?.value) { + case "home": + navigateToProfile(profile.id()); + break; case "setting": navigateToProfile(profile.id(), "settings"); break; @@ -54,14 +77,8 @@ export const Welcome = () => { setDeletingProfileId(profile.id()); break; } - }; - const handleClick = (profile: Profile) => { - if (profile.usesPassword()) { - setSelectedProfile(profile); - } else { - navigateToProfile(profile.id()); - } + closeSignInModal(); }; return ( @@ -96,7 +113,7 @@ export const Welcome = () => { key={index} profile={profile} actions={profileCardActions} - onSelect={(action: any) => handleProfileCardAction(profile, action)} + onSelect={(action: any) => handleProfileAction(profile, action)} /> ))} @@ -137,13 +154,13 @@ export const Welcome = () => { onDelete={closeDeleteProfileModal} /> - {selectedProfile && ( + {selectedProfile && requestedAction && ( navigateToProfile(selectedProfile.id())} + onSuccess={() => handleRequestedAction(selectedProfile, requestedAction)} /> )} From a30c062ac869fade87f4eef38191807fc46d4487 Mon Sep 17 00:00:00 2001 From: goga-m Date: Wed, 7 Oct 2020 18:45:41 +0300 Subject: [PATCH 2/3] test: add coverage --- .../profile/pages/Welcome/Welcome.test.tsx | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/domains/profile/pages/Welcome/Welcome.test.tsx b/src/domains/profile/pages/Welcome/Welcome.test.tsx index cbc0d401af..cd68ac8a86 100644 --- a/src/domains/profile/pages/Welcome/Welcome.test.tsx +++ b/src/domains/profile/pages/Welcome/Welcome.test.tsx @@ -103,6 +103,56 @@ describe("Welcome", () => { expect(asFragment()).toMatchSnapshot(); }); + it("should navigate to profile settings with correct password", async () => { + const { + asFragment, + container, + findByTestId, + getByTestId, + getByText, + history, + getAllByTestId, + } = renderWithRouter(); + + expect(container).toBeTruthy(); + + const profile = env.profiles().findById("cba050f1-880f-45f0-9af9-cfe48f406052"); + + expect(getByText(translations.PAGE_WELCOME.HAS_PROFILES)).toBeInTheDocument(); + + expect(() => getByTestId("modal__inner")).toThrow(/Unable to find an element by/); + + const profileCardMenu = getAllByTestId("dropdown__toggle")[1]; + + act(() => { + fireEvent.click(profileCardMenu); + }); + + const settingsOption = getByTestId("dropdown__option--0"); + expect(settingsOption).toBeTruthy(); + expect(settingsOption).toHaveTextContent(commonTranslations.SETTINGS); + + act(() => { + fireEvent.click(settingsOption); + }); + + await waitFor(() => expect(getByTestId("modal__inner")).toBeInTheDocument()); + + await act(async () => { + fireEvent.input(getByTestId("SignIn__input--password"), { target: { value: "password" } }); + }); + + // wait for formState.isValid to be updated + await findByTestId("SignIn__submit-button"); + + await act(async () => { + fireEvent.click(getByTestId("SignIn__submit-button")); + }); + + expect(history.location.pathname).toEqual(`/profiles/${profile.id()}/settings`); + expect(asFragment()).toMatchSnapshot(); + }); + it("should navigate to profile settings from profile card menu", () => { const { container, getByText, asFragment, history, getByTestId, getAllByTestId } = renderWithRouter( , From 56cb29bf37dc4733638e1988523c38f4e5b06ccb Mon Sep 17 00:00:00 2001 From: goga-m Date: Wed, 7 Oct 2020 18:46:33 +0300 Subject: [PATCH 3/3] chore: update snapshots --- .../__snapshots__/Welcome.test.tsx.snap | 386 +++++++++++------- 1 file changed, 249 insertions(+), 137 deletions(-) diff --git a/src/domains/profile/pages/Welcome/__snapshots__/Welcome.test.tsx.snap b/src/domains/profile/pages/Welcome/__snapshots__/Welcome.test.tsx.snap index 523e659365..dd4f6a78a7 100644 --- a/src/domains/profile/pages/Welcome/__snapshots__/Welcome.test.tsx.snap +++ b/src/domains/profile/pages/Welcome/__snapshots__/Welcome.test.tsx.snap @@ -808,191 +808,303 @@ exports[`Welcome should navigate to profile dashboard with correct password 1`] + +`; + +exports[`Welcome should navigate to profile settings from profile card menu 1`] = ` +
-
-
- +
+ +
-

- Sign In -

+

+ Welcome to the +
+ ARK Desktop Wallet +

- Sign in to access your profile. + + welcome-banner.svg +
+

+ Select Profile +

+

+ Choose from an existing Profile below, sign in via MarketSquare or create a new Profile to get started. +

- Jane Doe" - title="Jane Doe" - /> - - JA - -
-
-

- Name -

-

+

+
+ John Doe" + title="John Doe" + /> + + JO + +
+
+

+ Name +

+

+ + John Doe + +

+
+
+
+
+

+ Total balance +

+ + 91.43089801 BTC + +
+
+
+
+
- - Jane Doe - -

+
+ + settings.svg + +
+
+
-

- Total balance -

- - N/A - -
-
-
-
-
-
-
-
- +
+
+ +
-
- +
@@ -1000,7 +1112,7 @@ exports[`Welcome should navigate to profile dashboard with correct password 1`]
`; -exports[`Welcome should navigate to profile settings from profile card menu 1`] = ` +exports[`Welcome should navigate to profile settings with correct password 1`] = `