diff --git a/src/app/screens/Accounts/GenerateMnemonic/new.test.tsx b/src/app/screens/Accounts/GenerateMnemonic/new.test.tsx new file mode 100644 index 0000000000..fbd31d1e73 --- /dev/null +++ b/src/app/screens/Accounts/GenerateMnemonic/new.test.tsx @@ -0,0 +1,51 @@ +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { I18nextProvider } from "react-i18next"; +import { MemoryRouter } from "react-router-dom"; +import i18n from "~/../tests/unit/helpers/i18n"; +import api from "~/common/lib/api"; + +import MnemonicExplanation from "./new"; + +jest.mock("~/common/lib/api", () => ({ + __esModule: true, + default: { + getAccount: jest.fn(), + }, +})); + +jest.mock("~/app/utils", () => { + const actual = jest.requireActual("~/app/utils"); + + return { + ...actual, + useTheme: jest.fn(() => "light"), + }; +}); + +describe("MnemonicExplanation", () => { + beforeEach(() => { + jest.mocked(api.getAccount).mockResolvedValue({ + hasMnemonic: false, + } as Awaited>); + }); + + test("disables Next until a setup option is selected", async () => { + const user = userEvent.setup(); + + render( + + + + + + ); + + const nextButton = await screen.findByRole("button", { name: "Next" }); + expect(nextButton).toBeDisabled(); + + await user.click(screen.getByRole("button", { name: /Create Master Key/ })); + + expect(nextButton).toBeEnabled(); + }); +}); diff --git a/src/app/screens/Accounts/GenerateMnemonic/new.tsx b/src/app/screens/Accounts/GenerateMnemonic/new.tsx index 8221691a8a..5a99856d7d 100644 --- a/src/app/screens/Accounts/GenerateMnemonic/new.tsx +++ b/src/app/screens/Accounts/GenerateMnemonic/new.tsx @@ -23,7 +23,9 @@ function MnemonicExplanation() { }); const { t: tCommon } = useTranslation("common"); - const [selectedCard, setSelectedCard] = useState("backup"); + const [selectedCard, setSelectedCard] = useState< + "backup" | "import" | "importNostr" | null + >(null); const [hasMnemonic, setHasMnemonic] = useState(false); useEffect(() => { @@ -86,6 +88,7 @@ function MnemonicExplanation() { label={tCommon("actions.next")} primary flex + disabled={!selectedCard} onClick={() => { if (selectedCard === "backup") { hasMnemonic