-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] Test: Adds useSwitchActiveWalletChain test (#5835)
- Loading branch information
1 parent
a83fee6
commit 82667ca
Showing
3 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
packages/thirdweb/src/react/core/hooks/wallets/useSwitchActiveWalletChain.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import type { ReactNode } from "react"; | ||
import { optimism } from "thirdweb/chains"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { MockStorage } from "../../../../../test/src/mocks/storage.js"; | ||
import { TEST_CLIENT } from "../../../../../test/src/test-clients.js"; | ||
import { TEST_ACCOUNT_A } from "../../../../../test/src/test-wallets.js"; | ||
import { createWalletAdapter } from "../../../../adapters/wallet-adapter.js"; | ||
import { ethereum } from "../../../../chains/chain-definitions/ethereum.js"; | ||
import { createConnectionManager } from "../../../../wallets/manager/index.js"; | ||
import { ConnectionManagerCtx } from "../../providers/connection-manager.js"; | ||
import { useSetActiveWallet } from "./useSetActiveWallet.js"; | ||
import { useSwitchActiveWalletChain } from "./useSwitchActiveWalletChain.js"; | ||
|
||
const switchChain = vi.fn(); | ||
describe("useSwitchActiveWalletChain", () => { | ||
// Mock the connection manager | ||
const mockStorage = new MockStorage(); | ||
const manager = createConnectionManager(mockStorage); | ||
|
||
// Create a wrapper component with the mocked context | ||
const wrapper = ({ children }: { children: ReactNode }) => { | ||
return ( | ||
<ConnectionManagerCtx.Provider value={manager}> | ||
{children} | ||
</ConnectionManagerCtx.Provider> | ||
); | ||
}; | ||
|
||
const wallet = createWalletAdapter({ | ||
adaptedAccount: TEST_ACCOUNT_A, | ||
client: TEST_CLIENT, | ||
chain: ethereum, | ||
onDisconnect: () => {}, | ||
switchChain, | ||
}); | ||
|
||
it("should switch the active wallet chain", async () => { | ||
const { result } = renderHook(() => useSetActiveWallet(), { wrapper }); | ||
await result.current(wallet); | ||
const { result: switchChainResult } = renderHook( | ||
() => useSwitchActiveWalletChain(), | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
await switchChainResult.current(optimism); | ||
|
||
expect(switchChain).toHaveBeenCalledWith(optimism); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters