Skip to content

Commit 8375b96

Browse files
committed
test: add test
1 parent d87872e commit 8375b96

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import { MockStorage } from "~test/mocks/storage.js";
3+
import { TEST_CLIENT } from "~test/test-clients.js";
4+
import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
5+
import { createWalletAdapter } from "../../adapters/wallet-adapter.js";
6+
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
7+
import { webLocalStorage } from "../../utils/storage/webStorage.js";
8+
import { createWallet } from "../create-wallet.js";
9+
import { getInstalledWalletProviders } from "../injected/mipdStore.js";
10+
import { createConnectionManager } from "../manager/index.js";
11+
import { autoConnect } from "./autoConnect.js";
12+
import { autoConnectCore } from "./autoConnectCore.js";
13+
14+
vi.mock("../../utils/storage/webStorage.js");
15+
vi.mock("../create-wallet.js");
16+
vi.mock("../injected/mipdStore.js");
17+
vi.mock("./autoConnectCore.js");
18+
19+
describe("autoConnect", () => {
20+
const mockWallet = createWalletAdapter({
21+
adaptedAccount: TEST_ACCOUNT_A,
22+
client: TEST_CLIENT,
23+
chain: ethereum,
24+
onDisconnect: () => {},
25+
switchChain: () => {},
26+
});
27+
const mockStorage = new MockStorage();
28+
const mockWalletManager = createConnectionManager(mockStorage);
29+
30+
beforeEach(() => {
31+
vi.clearAllMocks();
32+
vi.mocked(getInstalledWalletProviders).mockReturnValue([]);
33+
vi.mocked(createWallet).mockReturnValue(mockWallet);
34+
vi.mocked(autoConnectCore).mockResolvedValue(true);
35+
});
36+
37+
it("should call autoConnectCore with correct parameters when wallets are provided", async () => {
38+
const result = await autoConnect({
39+
client: TEST_CLIENT,
40+
wallets: [mockWallet],
41+
walletManager: mockWalletManager,
42+
});
43+
44+
expect(autoConnectCore).toHaveBeenCalledWith({
45+
storage: webLocalStorage,
46+
props: {
47+
client: TEST_CLIENT,
48+
wallets: [mockWallet],
49+
walletManager: mockWalletManager,
50+
},
51+
createWalletFn: createWallet,
52+
getInstalledWallets: expect.any(Function),
53+
manager: mockWalletManager,
54+
});
55+
expect(result).toBe(true);
56+
});
57+
58+
it("should use default wallets when no wallets are provided", async () => {
59+
await autoConnect({
60+
wallets: [],
61+
walletManager: mockWalletManager,
62+
client: TEST_CLIENT,
63+
});
64+
65+
expect(autoConnectCore).toHaveBeenCalledWith(
66+
expect.objectContaining({
67+
props: {
68+
client: TEST_CLIENT,
69+
wallets: [],
70+
walletManager: mockWalletManager,
71+
},
72+
}),
73+
);
74+
});
75+
});

0 commit comments

Comments
 (0)