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( , 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)} /> )} 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`] = `