Skip to content

Commit

Permalink
fix: mocks for getActiveSessions
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Dec 4, 2024
1 parent 13c369d commit 2427dc2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
52 changes: 49 additions & 3 deletions apps/web/src/components/Menu/AppsMenu/AppsMenu.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
import { WalletClient } from "@umami/state";
jest.mock("@umami/state", () => ({
...jest.requireActual("@umami/state"),
walletKit: {
core: {},
metadata: {
name: "AppMenu test",
description: "Umami Wallet with WalletConnect",
url: "https://umamiwallet.com",
icons: ["https://umamiwallet.com/assets/favicon-32-45gq0g6M.png"],
},
getActiveSessions: jest.fn(),
pair: jest.fn(),
},
createWalletKit: jest.fn(),
}));

import { WalletClient, walletKit } from "@umami/state";

import { AppsMenu } from "./AppsMenu";
import { act, renderInDrawer, screen, userEvent } from "../../../testUtils";

describe("<AppsMenu />", () => {
it("calls addPeer on button click with the copied text", async () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("calls addPeer for Beacon on button click with the copied text", async () => {
const user = userEvent.setup();
const payload =
"btunoo2sZmmMB6k9Bef8tgYs7PsS6g6DFdUiDzVuwMxv7nGJN71eFCtGxGfq321pFy4eT2ckDWWzTdBhvje7VUzy2ZciQSe9rGMCF6Fpx5MCM3q2CWyUt4nhqSFigPhcUHaLAzAwcSTXbSRn9YZ8QJwwaWzdsNF6UW4PrWeCbABvHArBDpeLRNxJRjMpAVndoCCf9Vbu7YRXF2FcxWxUrcqfj1i3hr34M8zRTtP5QuVqita8MW5A6Ub3tB3bDvykqa8aYFvxbWr47USytTQjVqnnFUdBo8rm3cJyUq39hJwUdbvZEyoGUWnfuhFHYcbyZP86CPef1p7Eh1KUEwVKxLxQwNX84Eg1eBkZowRtNKcqqShMhKT7ZEELyfh1ji7NckRF8RJuwuco4dqBg6msuZjZqta4CsJvQw4A66RbePC8LxwKEb3Nhha8cygtbQVC4Scb7PaLY9qwQJjYL7n";
jest.spyOn(navigator.clipboard, "readText").mockResolvedValue(payload);
const mockAddPeer = jest.spyOn(WalletClient, "addPeer");
jest.spyOn(walletKit, "getActiveSessions").mockImplementation(() => ({}));

// make sure the mocks are correct
expect(walletKit.metadata.name).toEqual("AppMenu test");
expect(walletKit.getActiveSessions()).toEqual({});

const mockAddPeer = jest.spyOn(WalletClient, "addPeer").mockResolvedValue(undefined);

await renderInDrawer(<AppsMenu />);

Expand All @@ -25,4 +50,25 @@ describe("<AppsMenu />", () => {
version: "3",
});
});

it("handles WalletConenct request on button click with the copied text", async () => {
const user = userEvent.setup();
const payload =
"wc:c02d87d6f8c46a9192e1fd4627b5104d326ee6ec4dd9040482a277bdc53e2f10@2?expiryTimestamp=1733241891&relay-protocol=irn&symKey=d8b5f7b8a35b7e73126bfe4af89568811a87c4cfd49e3946c44026d55267ebd7";
jest.spyOn(navigator.clipboard, "readText").mockResolvedValue(payload);
jest.spyOn(walletKit, "getActiveSessions").mockImplementation(() => ({}));

// make sure the mocks are correct
expect(walletKit.metadata.name).toEqual("AppMenu test");
expect(walletKit.getActiveSessions()).toEqual({});

const mockAddPeer = jest.spyOn(WalletClient, "addPeer").mockResolvedValue(undefined);

await renderInDrawer(<AppsMenu />);

await act(() => user.click(screen.getByText("Connect")));

expect(mockAddPeer).not.toHaveBeenCalled();
expect(walletKit.pair).toHaveBeenCalledWith({ uri: payload });
});
});
13 changes: 13 additions & 0 deletions apps/web/src/components/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
addTestAccount,
makeStore,
useDownloadBackupFile,
walletKit,
} from "@umami/state";

import { AddressBookMenu } from "./AddressBookMenu/AddressBookMenu";
Expand All @@ -30,6 +31,17 @@ jest.mock("@chakra-ui/system", () => ({
jest.mock("@umami/state", () => ({
...jest.requireActual("@umami/state"),
useDownloadBackupFile: jest.fn(),
walletKit: {
core: {},
metadata: {
name: "AppMenu test",
description: "Umami Wallet with WalletConnect",
url: "https://umamiwallet.com",
icons: ["https://umamiwallet.com/assets/favicon-32-45gq0g6M.png"],
},
getActiveSessions: jest.fn(),
},
createWalletKit: jest.fn(),
}));

let store: UmamiStore;
Expand Down Expand Up @@ -71,6 +83,7 @@ describe("<Menu />", () => {
])("opens %label menu correctly", async (label, Component) => {
const user = userEvent.setup();
const { openWith } = dynamicDrawerContextMock;
jest.spyOn(walletKit, "getActiveSessions").mockImplementation(() => ({}));

await renderInDrawer(<Menu />, store);

Expand Down

1 comment on commit 2427dc2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 84%
83.88% (1764/2103) 79.35% (838/1056) 78.45% (448/571)
apps/web Coverage: 84%
83.88% (1764/2103) 79.35% (838/1056) 78.45% (448/571)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
81.91% (222/271) 71.22% (99/139) 81.96% (50/61)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.76% (818/965) 80.86% (186/230) 78.59% (301/383)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.