From 21ce7d21e2bf880e5f07a3268ed15a9c6236179a Mon Sep 17 00:00:00 2001 From: Usame Algan Date: Wed, 25 Oct 2023 09:26:14 +0200 Subject: [PATCH] fix: Adjust disconnect wallet test --- .../__tests__/AccountCenter.test.tsx | 14 +------------- src/components/common/WalletInfo/index.test.tsx | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/components/common/ConnectWallet/__tests__/AccountCenter.test.tsx b/src/components/common/ConnectWallet/__tests__/AccountCenter.test.tsx index 000a4d6a05..382b7acb1d 100644 --- a/src/components/common/ConnectWallet/__tests__/AccountCenter.test.tsx +++ b/src/components/common/ConnectWallet/__tests__/AccountCenter.test.tsx @@ -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 = { @@ -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() diff --git a/src/components/common/WalletInfo/index.test.tsx b/src/components/common/WalletInfo/index.test.tsx index 8821659c21..c13a338bfc 100644 --- a/src/components/common/WalletInfo/index.test.tsx +++ b/src/components/common/WalletInfo/index.test.tsx @@ -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', @@ -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 @@ -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( { />, ) - 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', () => {