@@ -2,6 +2,7 @@ import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react'
22import { render , screen } from '@testing-library/react'
33import { createElement , type ReactNode } from 'react'
44import { beforeEach , describe , expect , it , vi } from 'vitest'
5+ import type { Web3Status } from '@/src/hooks/useWeb3Status'
56import TransactionButton from './TransactionButton'
67
78const mockSwitchChain = vi . fn ( )
@@ -43,6 +44,21 @@ vi.mock('wagmi', () => ({
4344const { useWalletStatus } = await import ( '@/src/hooks/useWalletStatus' )
4445const mockedUseWalletStatus = vi . mocked ( useWalletStatus )
4546
47+ const mockWeb3Status = {
48+ readOnlyClient : undefined ,
49+ appChainId : 1 ,
50+ address : '0xdeadbeef' ,
51+ balance : undefined ,
52+ connectingWallet : false ,
53+ switchingChain : false ,
54+ isWalletConnected : true ,
55+ walletClient : undefined ,
56+ isWalletSynced : true ,
57+ walletChainId : 1 ,
58+ switchChain : vi . fn ( ) ,
59+ disconnect : vi . fn ( ) ,
60+ } as unknown as Web3Status
61+
4662const system = createSystem ( defaultConfig )
4763
4864const renderWithChakra = ( ui : ReactNode ) =>
@@ -61,7 +77,7 @@ describe('TransactionButton', () => {
6177 targetChain : { id : 1 , name : 'Ethereum' } as ReturnType < typeof useWalletStatus > [ 'targetChain' ] ,
6278 targetChainId : 1 ,
6379 switchChain : mockSwitchChain ,
64- web3Status : undefined as unknown as ReturnType < typeof useWalletStatus > [ 'web3Status' ] ,
80+ web3Status : mockWeb3Status ,
6581 } )
6682
6783 renderWithChakra ( < TransactionButton transaction = { mockTransaction } > Send</ TransactionButton > )
@@ -78,7 +94,7 @@ describe('TransactionButton', () => {
7894 targetChain : { id : 1 , name : 'Ethereum' } as ReturnType < typeof useWalletStatus > [ 'targetChain' ] ,
7995 targetChainId : 1 ,
8096 switchChain : mockSwitchChain ,
81- web3Status : undefined as unknown as ReturnType < typeof useWalletStatus > [ 'web3Status' ] ,
97+ web3Status : mockWeb3Status ,
8298 } )
8399
84100 renderWithChakra (
@@ -104,7 +120,7 @@ describe('TransactionButton', () => {
104120 > [ 'targetChain' ] ,
105121 targetChainId : 10 ,
106122 switchChain : mockSwitchChain ,
107- web3Status : undefined as unknown as ReturnType < typeof useWalletStatus > [ 'web3Status' ] ,
123+ web3Status : mockWeb3Status ,
108124 } )
109125
110126 renderWithChakra ( < TransactionButton transaction = { mockTransaction } > Send</ TransactionButton > )
@@ -124,7 +140,7 @@ describe('TransactionButton', () => {
124140 > [ 'targetChain' ] ,
125141 targetChainId : 10 ,
126142 switchChain : mockSwitchChain ,
127- web3Status : undefined as unknown as ReturnType < typeof useWalletStatus > [ 'web3Status' ] ,
143+ web3Status : mockWeb3Status ,
128144 } )
129145
130146 renderWithChakra (
@@ -148,7 +164,7 @@ describe('TransactionButton', () => {
148164 targetChain : { id : 1 , name : 'Ethereum' } as ReturnType < typeof useWalletStatus > [ 'targetChain' ] ,
149165 targetChainId : 1 ,
150166 switchChain : mockSwitchChain ,
151- web3Status : undefined as unknown as ReturnType < typeof useWalletStatus > [ 'web3Status' ] ,
167+ web3Status : mockWeb3Status ,
152168 } )
153169
154170 renderWithChakra ( < TransactionButton transaction = { mockTransaction } > Send ETH</ TransactionButton > )
0 commit comments