-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Extract WalletInfo logic from AccountCenter, use madProps and wr…
…ite tests
- Loading branch information
1 parent
928a6dc
commit 1d35758
Showing
9 changed files
with
466 additions
and
202 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
src/components/common/ConnectWallet/__tests__/AccountCenter.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,47 @@ | ||
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 { act, waitFor } from '@testing-library/react' | ||
|
||
const mockWallet = { | ||
address: '0x1234567890123456789012345678901234567890', | ||
chainId: '5', | ||
label: '', | ||
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} />) | ||
|
||
const openButton = getByTestId('open-account-center') | ||
|
||
act(() => { | ||
openButton.click() | ||
}) | ||
|
||
const disconnectButton = getByText('Disconnect') | ||
|
||
expect(disconnectButton).toBeInTheDocument() | ||
|
||
act(() => { | ||
disconnectButton.click() | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(disconnectButton).not.toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.