Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/app/screens/Accounts/GenerateMnemonic/new.test.tsx
Original file line number Diff line number Diff line change
@@ -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<ReturnType<typeof api.getAccount>>);
});

test("disables Next until a setup option is selected", async () => {
const user = userEvent.setup();

render(
<I18nextProvider i18n={i18n}>
<MemoryRouter>
<MnemonicExplanation />
</MemoryRouter>
</I18nextProvider>
);

const nextButton = await screen.findByRole("button", { name: "Next" });
expect(nextButton).toBeDisabled();

await user.click(screen.getByRole("button", { name: /Create Master Key/ }));

expect(nextButton).toBeEnabled();
});
});
5 changes: 4 additions & 1 deletion src/app/screens/Accounts/GenerateMnemonic/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -86,6 +88,7 @@ function MnemonicExplanation() {
label={tCommon("actions.next")}
primary
flex
disabled={!selectedCard}
onClick={() => {
if (selectedCard === "backup") {
hasMnemonic
Expand Down