From ddc0fac7ddd9d26db6551aa2d424c75151ea9944 Mon Sep 17 00:00:00 2001 From: Paul Cramer Date: Sat, 27 Jul 2024 13:58:03 -0700 Subject: [PATCH] Add tests and changeset --- .changeset/afraid-dogs-vanish.md | 5 ++ .../WalletDropdownBaseName.test.tsx | 55 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .changeset/afraid-dogs-vanish.md create mode 100644 src/wallet/components/WalletDropdownBaseName.test.tsx diff --git a/.changeset/afraid-dogs-vanish.md b/.changeset/afraid-dogs-vanish.md new file mode 100644 index 00000000000..2de4d93d5f0 --- /dev/null +++ b/.changeset/afraid-dogs-vanish.md @@ -0,0 +1,5 @@ +--- +"@coinbase/onchainkit": patch +--- + +-**feat**: Implement WalletDropdownBaseName Sub-Component. By @cpcramer #913 diff --git a/src/wallet/components/WalletDropdownBaseName.test.tsx b/src/wallet/components/WalletDropdownBaseName.test.tsx new file mode 100644 index 00000000000..fc76ee8f0f8 --- /dev/null +++ b/src/wallet/components/WalletDropdownBaseName.test.tsx @@ -0,0 +1,55 @@ +import type { UseQueryResult } from '@tanstack/react-query'; +import { render, screen } from '@testing-library/react'; +import type { GetAccountReturnType } from '@wagmi/core'; +import { describe, expect, it, vi } from 'vitest'; +import { useAccount } from 'wagmi'; +import { useName } from '../../identity/hooks/useName'; +import { WalletDropdownBaseName } from './WalletDropdownBaseName'; + +vi.mock('wagmi', () => ({ + useAccount: vi.fn(), +})); + +vi.mock('../../identity/hooks/useName', () => ({ + useName: vi.fn(), +})); + +describe('WalletDropdownBaseName', () => { + it('should render "Claim a Basename" when no basename', () => { + (useAccount as vi.Mock<[], Partial>).mockReturnValue({ + address: '0x1234' as `0x${string}`, + isConnected: true, + }); + ( + useName as vi.Mock<[], Partial>> + ).mockReturnValue({ + data: null, + isLoading: false, + isError: false, + error: null, + }); + + render(); + expect(screen.getByText('Claim a Basename')).toBeInTheDocument(); + expect(screen.getByText('NEW')).toBeInTheDocument(); + }); + + it('should render "Go to profile" when basename exists', () => { + (useAccount as vi.Mock<[], Partial>).mockReturnValue({ + address: '0x1234' as `0x${string}`, + isConnected: true, + }); + ( + useName as vi.Mock<[], Partial>> + ).mockReturnValue({ + data: 'test.base', + isLoading: false, + isError: false, + error: null, + }); + + render(); + expect(screen.getByText('Go to profile')).toBeInTheDocument(); + expect(screen.queryByText('NEW')).not.toBeInTheDocument(); + }); +});