-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
743c928
commit ef5238d
Showing
11 changed files
with
240 additions
and
15 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
apps/web/src/components/AccountSelectorModal/AccountSelectorModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { | ||
getAccountGroupLabel, | ||
mockLedgerAccount, | ||
mockMnemonicAccount, | ||
mockSocialAccount, | ||
} from "@umami/core"; | ||
import { type UmamiStore, accountsActions, addTestAccounts, makeStore } from "@umami/state"; | ||
|
||
import { AccountSelectorModal } from "./AccountSelectorModal"; | ||
import { DeriveMnemonicAccountModal } from "./DeriveMnemonicAccountModal"; | ||
import { | ||
act, | ||
dynamicModalContextMock, | ||
renderInModal, | ||
screen, | ||
userEvent, | ||
waitFor, | ||
} from "../../testUtils"; | ||
import { OnboardOptionsModal } from "../Onboarding/OnboardOptions"; | ||
|
||
let store: UmamiStore; | ||
|
||
beforeEach(() => { | ||
store = makeStore(); | ||
addTestAccounts(store, [mockMnemonicAccount(0), mockLedgerAccount(1), mockSocialAccount(2)]); | ||
}); | ||
|
||
describe("<AccountSelectorModal />", () => { | ||
it("renders account groups correctly", async () => { | ||
await renderInModal(<AccountSelectorModal />, store); | ||
|
||
await waitFor(() => | ||
expect(screen.getByText(`Seedphrase ${mockMnemonicAccount(0).seedFingerPrint}`)).toBeVisible() | ||
); | ||
expect(screen.getByText("Social Accounts")).toBeVisible(); | ||
expect(screen.getByText("Ledger Accounts")).toBeVisible(); | ||
}); | ||
|
||
it.each([ | ||
[ | ||
"mnemonic", | ||
mockMnemonicAccount(0), | ||
() => <DeriveMnemonicAccountModal account={mockMnemonicAccount(0)} />, | ||
], | ||
["ledger", mockLedgerAccount(1), () => <OnboardOptionsModal />], | ||
["social", mockSocialAccount(2), () => <OnboardOptionsModal />], | ||
])( | ||
"open appropriate modal when clicking 'Add %s Account' button", | ||
async (_, account, getModalComponent) => { | ||
const user = userEvent.setup(); | ||
const accountLabel = getAccountGroupLabel(account); | ||
const { openWith } = dynamicModalContextMock; | ||
await renderInModal(<AccountSelectorModal />, store); | ||
|
||
await act(() => user.click(screen.getByLabelText(`Add ${accountLabel} account`))); | ||
|
||
expect(openWith).toHaveBeenCalledWith(getModalComponent()); | ||
} | ||
); | ||
|
||
it("opens appropriate modal when clicking 'Add Account' button", async () => { | ||
const user = userEvent.setup(); | ||
const { openWith } = dynamicModalContextMock; | ||
await renderInModal(<AccountSelectorModal />, store); | ||
|
||
await act(() => user.click(screen.getByText("Add Account"))); | ||
|
||
expect(openWith).toHaveBeenCalledWith(<OnboardOptionsModal />); | ||
}); | ||
|
||
it("correctly handles account selection", async () => { | ||
const user = userEvent.setup(); | ||
const { onClose } = dynamicModalContextMock; | ||
await renderInModal(<AccountSelectorModal />, store); | ||
|
||
const accountTile = screen.getByText(mockMnemonicAccount(0).label); | ||
await act(() => user.click(accountTile)); | ||
|
||
expect(store.getState().accounts.current).toBe(mockMnemonicAccount(0).address.pkh); | ||
expect(onClose).toHaveBeenCalled(); | ||
}); | ||
|
||
describe("when account is not verified", () => { | ||
beforeEach(() => { | ||
store.dispatch(accountsActions.setCurrent(mockLedgerAccount(0).address.pkh)); | ||
store.dispatch( | ||
accountsActions.setIsVerified({ | ||
pkh: mockLedgerAccount(0).address.pkh, | ||
isVerified: false, | ||
}) | ||
); | ||
}); | ||
|
||
it("does not render 'Add Account' button", async () => { | ||
await renderInModal(<AccountSelectorModal />, store); | ||
|
||
expect(screen.queryByText("Add Account")).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...nents/AccountSelectorModal/DeriveMnemonicAccountModal/DeriveMnemonicAccountModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { mockMnemonicAccount } from "@umami/core"; | ||
import { type UmamiStore, addTestAccount, makeStore, useDeriveMnemonicAccount } from "@umami/state"; | ||
|
||
import { DeriveMnemonicAccountModal } from "./DeriveMnemonicAccountModal"; | ||
import { act, renderInModal, screen, userEvent, waitFor } from "../../../testUtils"; | ||
|
||
let store: UmamiStore; | ||
|
||
jest.mock("@umami/state", () => ({ | ||
...jest.requireActual("@umami/state"), | ||
useDeriveMnemonicAccount: jest.fn(), | ||
})); | ||
|
||
const mockDeriveMnemonicAccount = jest.fn(); | ||
|
||
beforeEach(() => { | ||
store = makeStore(); | ||
addTestAccount(store, mockMnemonicAccount(0)); | ||
|
||
jest.mocked(useDeriveMnemonicAccount).mockImplementation(() => mockDeriveMnemonicAccount); | ||
}); | ||
|
||
describe("<DeriveMnemonicAccountModal />", () => { | ||
it("renders the NameAccountModal with correct subtitle", async () => { | ||
const account = mockMnemonicAccount(0); | ||
await renderInModal(<DeriveMnemonicAccountModal account={account} />, store); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Name Your Account")).toBeVisible(); | ||
}); | ||
|
||
expect( | ||
screen.getByText(`Name the new account derived from seedphrase ${account.seedFingerPrint}`) | ||
).toBeVisible(); | ||
}); | ||
|
||
it("handles name submission and opens confirm password modal", async () => { | ||
const user = userEvent.setup(); | ||
|
||
const account = mockMnemonicAccount(0); | ||
await renderInModal(<DeriveMnemonicAccountModal account={account} />, store); | ||
await act(() => user.type(screen.getByLabelText("Account name"), "Test Account")); | ||
await act(() => user.click(screen.getByRole("button", { name: "Continue" }))); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId("master-password-modal")).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it("derives mnemonic account on password submission", async () => { | ||
const user = userEvent.setup(); | ||
|
||
const account = mockMnemonicAccount(0); | ||
await renderInModal(<DeriveMnemonicAccountModal account={account} />, store); | ||
|
||
await act(() => user.type(screen.getByLabelText("Account name"), "Test Account")); | ||
await act(() => user.click(screen.getByRole("button", { name: "Continue" }))); | ||
await act(() => user.type(screen.getByLabelText("Password"), "test-password")); | ||
await act(() => user.click(screen.getByRole("button", { name: "Submit" }))); | ||
|
||
expect(mockDeriveMnemonicAccount).toHaveBeenCalledWith({ | ||
fingerPrint: account.seedFingerPrint, | ||
password: "test-password", | ||
label: "Test Account", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
apps/web/src/components/MasterPasswordModal/MasterPasswordModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { MasterPasswordModal } from "./MasterPasswordModal"; | ||
import { renderInModal, screen, userEvent } from "../../testUtils"; | ||
|
||
const mockOnSubmit = jest.fn(); | ||
|
||
describe("<MasterPasswordModal />", () => { | ||
it("calls onSubmit with entered password when form is submitted", async () => { | ||
const user = userEvent.setup(); | ||
await renderInModal(<MasterPasswordModal onSubmit={mockOnSubmit} />); | ||
|
||
await user.type(screen.getByLabelText("Password"), "testpassword"); | ||
await user.click(screen.getByRole("button", { name: "Submit" })); | ||
|
||
expect(mockOnSubmit).toHaveBeenCalledWith({ password: "testpassword" }); | ||
}); | ||
|
||
it("shows validation error when submitting without a password", async () => { | ||
const user = userEvent.setup(); | ||
await renderInModal(<MasterPasswordModal onSubmit={mockOnSubmit} />); | ||
|
||
await user.click(screen.getByRole("button", { name: "Submit" })); | ||
|
||
expect(screen.getByText("Password is required")).toBeInTheDocument(); | ||
expect(mockOnSubmit).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
apps/web/src/components/NameAccountModal/NameAccountModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { NameAccountModal } from "./NameAccountModal"; | ||
import { act, renderInModal, screen, userEvent, waitFor } from "../../testUtils"; | ||
|
||
const mockOnSubmit = jest.fn(); | ||
|
||
describe("NameAccountModal", () => { | ||
it("renders with custom title and subtitle", async () => { | ||
await renderInModal( | ||
<NameAccountModal onSubmit={mockOnSubmit} subtitle="Custom Subtitle" title="Custom Title" /> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Custom Title")).toBeVisible(); | ||
}); | ||
expect(screen.getByText("Custom Subtitle")).toBeVisible(); | ||
}); | ||
|
||
it("calls onSubmit with form data when submitted", async () => { | ||
const user = userEvent.setup(); | ||
|
||
await renderInModal(<NameAccountModal onSubmit={mockOnSubmit} />); | ||
|
||
await act(() => user.type(screen.getByLabelText("Account name"), "Test Account")); | ||
await act(() => user.click(screen.getByRole("button", { name: "Continue" }))); | ||
|
||
expect(mockOnSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ef5238d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.