Skip to content

Commit

Permalink
fix: Adjust disconnect wallet test
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Oct 25, 2023
1 parent 1d35758 commit 21ce7d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { render } from '@/tests/test-utils'
import { AccountCenter } from '@/components/common/ConnectWallet/AccountCenter'
import { type EIP1193Provider, type OnboardAPI } from '@web3-onboard/core'
import { type NextRouter } from 'next/router'
import { type EIP1193Provider } from '@web3-onboard/core'
import { act, waitFor } from '@testing-library/react'

const mockWallet = {
Expand All @@ -11,17 +10,6 @@ const mockWallet = {
provider: null as unknown as EIP1193Provider,
}

const mockRouter = {
query: {},
pathname: '',
} as NextRouter

const mockOnboard = {
connectWallet: jest.fn(),
disconnectWallet: jest.fn(),
setChain: jest.fn(),
} as unknown as OnboardAPI

describe('AccountCenter', () => {
it('should open and close the account center on click', async () => {
const { getByText, getByTestId } = render(<AccountCenter wallet={mockWallet} />)
Expand Down
17 changes: 14 additions & 3 deletions src/components/common/WalletInfo/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as mpcModule from '@/services/mpc/module'
import * as constants from '@/config/constants'
import * as mfaHelper from '@/components/settings/SignerAccountMFA/helper'
import { type Web3AuthMPCCoreKit } from '@web3auth/mpc-core-kit'
import { act } from '@testing-library/react'

const mockWallet = {
address: '0x1234567890123456789012345678901234567890',
Expand All @@ -19,9 +20,11 @@ const mockRouter = {
pathname: '',
} as NextRouter

const disconnectWalletMock = jest.fn()

const mockOnboard = {
connectWallet: jest.fn(),
disconnectWallet: jest.fn(),
disconnectWallet: disconnectWalletMock,
setChain: jest.fn(),
} as unknown as OnboardAPI

Expand Down Expand Up @@ -62,7 +65,7 @@ describe('WalletInfo', () => {
expect(getByText('Switch wallet')).toBeInTheDocument()
})

it('should display a Disconnect button', () => {
it('should disconnect the wallet when the button is clicked', () => {
const { getByText } = render(
<WalletInfo
wallet={mockWallet}
Expand All @@ -75,7 +78,15 @@ describe('WalletInfo', () => {
/>,
)

expect(getByText('Disconnect')).toBeInTheDocument()
const disconnectButton = getByText('Disconnect')

expect(disconnectButton).toBeInTheDocument()

act(() => {
disconnectButton.click()
})

expect(disconnectWalletMock).toHaveBeenCalled()
})

it('should display a Delete Account button on dev for social login', () => {
Expand Down

0 comments on commit 21ce7d2

Please sign in to comment.