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 3, 2024
1 parent 9d2f7ea commit bb35966
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 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,43 @@
import { WalletClient } from "@umami/state";
import { SessionTypes } from "@walletconnect/types";

Check warning on line 1 in apps/web/src/components/Menu/AppsMenu/AppsMenu.test.tsx

View workflow job for this annotation

GitHub Actions / test

'SessionTypes' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 1 in apps/web/src/components/Menu/AppsMenu/AppsMenu.test.tsx

View workflow job for this annotation

GitHub Actions / test

'SessionTypes' is defined but never used
import { before } from "lodash";

Check warning on line 2 in apps/web/src/components/Menu/AppsMenu/AppsMenu.test.tsx

View workflow job for this annotation

GitHub Actions / test

'before' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 2 in apps/web/src/components/Menu/AppsMenu/AppsMenu.test.tsx

View workflow job for this annotation

GitHub Actions / test

'before' is defined but never used

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

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";

Check warning on line 23 in apps/web/src/components/Menu/AppsMenu/AppsMenu.test.tsx

View workflow job for this annotation

GitHub Actions / test

`@umami/state` import should occur before import of `@walletconnect/types`

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 +53,26 @@ 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(() => ({}));
const mockPair = jest.spyOn(walletKit, "pair").mockResolvedValue();

Check warning on line 63 in apps/web/src/components/Menu/AppsMenu/AppsMenu.test.tsx

View workflow job for this annotation

GitHub Actions / test

'mockPair' is assigned a value but never used. Allowed unused vars must match /^_/u

// 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 });
});
});

0 comments on commit bb35966

Please sign in to comment.