-
Notifications
You must be signed in to change notification settings - Fork 4
test: add utility and env test coverage (Tier 1) #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gabitoesmiapodo
wants to merge
20
commits into
feat/ai-integration
Choose a base branch
from
test/utils
base: feat/ai-integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1a9a0aa
test: add utility and env test coverage (Tier 1)
gabitoesmiapodo 7edb47f
test: address review feedback on Tier 1 test suite
gabitoesmiapodo 55510e5
test: enhance BigNumberInput and HashInput coverage (Tier 2)
gabitoesmiapodo 33e3ca3
test: address review feedback on Tier 2 test suite
gabitoesmiapodo 40e06d3
test: address review feedback on Tier 1 test suite (round 2)
gabitoesmiapodo 543f5f4
test: import ComponentProps from react instead of using React namespace
gabitoesmiapodo 2b605b6
test: add hook test coverage (Tier 3)
gabitoesmiapodo d6ced76
test: address review feedback on Tier 3 hook test suite
gabitoesmiapodo 7bda650
test: add component test coverage (Tier 4)
gabitoesmiapodo 7b00d3b
test: address review feedback on Tier 4 component tests
gabitoesmiapodo 09e9de1
test: add demo page smoke tests (Tier 5)
gabitoesmiapodo 4fe5f28
test: fix detectHash mock in HashHandling smoke test
gabitoesmiapodo b0fe779
test: address review feedback on Tier 5 demo smoke tests
gabitoesmiapodo a412c4f
test: fix redundant cases in isNativeToken test suite
gabitoesmiapodo 990a656
chore: ignore .worktrees directory
gabitoesmiapodo ff358c9
Merge pull request #416 from BootNodeDev/test/enhance-existing
gabitoesmiapodo 5861213
refactor(tests): use Address type from viem instead of template literal
gabitoesmiapodo 11fb2a4
Merge pull request #417 from BootNodeDev/test/hooks
gabitoesmiapodo 9d1aff7
Merge pull request #418 from BootNodeDev/test/components
gabitoesmiapodo cb38783
Merge pull request #419 from BootNodeDev/test/demo-smoke
gabitoesmiapodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 @@ | ||
| # Test environment variables for Vitest | ||
| PUBLIC_APP_NAME=dAppBooster Test | ||
| PUBLIC_NATIVE_TOKEN_ADDRESS=0x0000000000000000000000000000000000000000 | ||
| PUBLIC_WALLETCONNECT_PROJECT_ID=test-project-id | ||
| PUBLIC_SUBGRAPHS_API_KEY=test-api-key | ||
| PUBLIC_SUBGRAPHS_CHAINS_RESOURCE_IDS=1:test:test-resource-id | ||
| PUBLIC_SUBGRAPHS_ENVIRONMENT=production |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -43,3 +43,4 @@ yarn-debug.log* | |
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| lerna-debug.log* | ||
| .worktrees | ||
This file contains hidden or 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
This file contains hidden or 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,22 @@ | ||
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import NotFound404 from './NotFound404' | ||
|
|
||
| const system = createSystem(defaultConfig) | ||
|
|
||
| vi.mock('@tanstack/react-router', () => ({ | ||
| useNavigate: vi.fn(() => vi.fn()), | ||
| })) | ||
|
|
||
| describe('NotFound404', () => { | ||
| it('renders 404 title and message', () => { | ||
| render( | ||
| <ChakraProvider value={system}> | ||
| <NotFound404 /> | ||
| </ChakraProvider>, | ||
| ) | ||
| expect(screen.getByText('404 - Not Found')).toBeDefined() | ||
| expect(screen.getByRole('button', { name: 'Home' })).toBeDefined() | ||
| }) | ||
| }) |
17 changes: 17 additions & 0 deletions
17
src/components/pageComponents/home/Examples/demos/ConnectWallet/index.test.tsx
This file contains hidden or 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,17 @@ | ||
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import connectWallet from './index' | ||
|
|
||
| const system = createSystem(defaultConfig) | ||
|
|
||
| vi.mock('@/src/providers/Web3Provider', () => ({ | ||
| ConnectWalletButton: () => <button type="button">Connect Wallet</button>, | ||
| })) | ||
|
|
||
| describe('ConnectWallet demo', () => { | ||
| it('renders the connect wallet button', () => { | ||
| render(<ChakraProvider value={system}>{connectWallet.demo}</ChakraProvider>) | ||
| expect(screen.getByRole('button', { name: 'Connect Wallet' })).toBeDefined() | ||
| }) | ||
| }) |
20 changes: 20 additions & 0 deletions
20
src/components/pageComponents/home/Examples/demos/EnsName/index.test.tsx
This file contains hidden or 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,20 @@ | ||
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import ensName from './index' | ||
|
|
||
| const system = createSystem(defaultConfig) | ||
|
|
||
| vi.mock('wagmi', () => ({ | ||
| useEnsName: vi.fn(() => ({ data: undefined, error: undefined, status: 'pending' })), | ||
| })) | ||
|
|
||
| describe('EnsName demo', () => { | ||
| it('renders the ENS name search interface', () => { | ||
| render(<ChakraProvider value={system}>{ensName.demo}</ChakraProvider>) | ||
| expect(screen.getByText('Find ENS name')).toBeDefined() | ||
| expect( | ||
| screen.getByPlaceholderText('Enter an address or select one from the dropdown'), | ||
| ).toBeDefined() | ||
| }) | ||
| }) |
28 changes: 28 additions & 0 deletions
28
src/components/pageComponents/home/Examples/demos/HashHandling/index.test.tsx
This file contains hidden or 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,28 @@ | ||
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import hashHandling from './index' | ||
|
|
||
| const system = createSystem(defaultConfig) | ||
|
|
||
| vi.mock('@/src/hooks/useWeb3Status', () => ({ | ||
| useWeb3Status: vi.fn(() => ({ | ||
| isWalletConnected: false, | ||
| walletChainId: undefined, | ||
| })), | ||
| })) | ||
|
|
||
| vi.mock('@/src/utils/hash', () => { | ||
| const mockFn = vi.fn(() => Promise.resolve(null)) | ||
| return { | ||
| default: mockFn, | ||
| detectHash: mockFn, | ||
| } | ||
| }) | ||
|
|
||
| describe('HashHandling demo', () => { | ||
| it('renders the hash input field', () => { | ||
| render(<ChakraProvider value={system}>{hashHandling.demo}</ChakraProvider>) | ||
| expect(screen.getByPlaceholderText(/address|hash/i)).toBeDefined() | ||
| }) | ||
| }) |
27 changes: 27 additions & 0 deletions
27
src/components/pageComponents/home/Examples/demos/SignMessage/index.test.tsx
This file contains hidden or 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,27 @@ | ||
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import signMessage from './index' | ||
|
|
||
| const system = createSystem(defaultConfig) | ||
|
|
||
| vi.mock('@/src/hooks/useWeb3Status', () => ({ | ||
| useWeb3Status: vi.fn(() => ({ | ||
| isWalletConnected: false, | ||
| isWalletSynced: false, | ||
| walletChainId: undefined, | ||
| appChainId: 11155420, | ||
| switchChain: vi.fn(), | ||
| })), | ||
| })) | ||
|
|
||
| vi.mock('@/src/providers/Web3Provider', () => ({ | ||
| ConnectWalletButton: () => <button type="button">Connect Wallet</button>, | ||
| })) | ||
|
|
||
| describe('SignMessage demo', () => { | ||
| it('renders connect wallet fallback when wallet not connected', () => { | ||
| render(<ChakraProvider value={system}>{signMessage.demo}</ChakraProvider>) | ||
| expect(screen.getByRole('button', { name: 'Connect Wallet' })).toBeDefined() | ||
| }) | ||
| }) |
23 changes: 23 additions & 0 deletions
23
src/components/pageComponents/home/Examples/demos/SwitchNetwork/index.test.tsx
This file contains hidden or 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,23 @@ | ||
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import switchNetwork from './index' | ||
|
|
||
| const system = createSystem(defaultConfig) | ||
|
|
||
| vi.mock('@/src/hooks/useWeb3Status', () => ({ | ||
| useWeb3Status: vi.fn(() => ({ | ||
| isWalletConnected: false, | ||
| })), | ||
| })) | ||
|
|
||
| vi.mock('@/src/providers/Web3Provider', () => ({ | ||
| ConnectWalletButton: () => <button type="button">Connect Wallet</button>, | ||
| })) | ||
|
|
||
| describe('SwitchNetwork demo', () => { | ||
| it('renders connect wallet button when wallet not connected', () => { | ||
| render(<ChakraProvider value={system}>{switchNetwork.demo}</ChakraProvider>) | ||
| expect(screen.getByRole('button', { name: 'Connect Wallet' })).toBeDefined() | ||
| }) | ||
| }) |
20 changes: 20 additions & 0 deletions
20
src/components/pageComponents/home/Examples/demos/TokenDropdown/index.test.tsx
This file contains hidden or 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,20 @@ | ||
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import tokenDropdown from './index' | ||
|
|
||
| const system = createSystem(defaultConfig) | ||
|
|
||
| // Mock the shared component to avoid its deep dependency chain | ||
| // (TokenSelect uses withSuspenseAndRetry, useTokenLists, useTokens, etc.) | ||
| vi.mock('@/src/components/sharedComponents/TokenDropdown', () => ({ | ||
| default: () => <div data-testid="token-dropdown-mock">Token Dropdown</div>, | ||
| })) | ||
|
|
||
| describe('TokenDropdown demo', () => { | ||
| it('renders the token dropdown container', () => { | ||
| render(<ChakraProvider value={system}>{tokenDropdown.demo}</ChakraProvider>) | ||
| expect(screen.getByText('Search and select a token')).toBeDefined() | ||
| expect(screen.getByTestId('token-dropdown-mock')).toBeDefined() | ||
| }) | ||
| }) |
49 changes: 49 additions & 0 deletions
49
src/components/pageComponents/home/Examples/demos/TokenInput/index.test.tsx
This file contains hidden or 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,49 @@ | ||
| import { createMockWeb3Status, renderWithProviders } from '@/src/test-utils' | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
| import { screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import tokenInput from './index' | ||
|
|
||
| vi.mock('@/src/hooks/useWeb3Status', () => ({ | ||
| useWeb3Status: vi.fn(() => createMockWeb3Status()), | ||
| })) | ||
|
|
||
| vi.mock('@/src/hooks/useTokenLists', () => ({ | ||
| useTokenLists: vi.fn(() => ({ | ||
| tokens: [], | ||
| tokensByChainId: {}, | ||
| tokensByAddress: {}, | ||
| tokensBySymbol: {}, | ||
| })), | ||
| })) | ||
|
|
||
| vi.mock('@/src/hooks/useTokenSearch', () => ({ | ||
| useTokenSearch: vi.fn(() => ({ | ||
| searchResult: [], | ||
| })), | ||
| })) | ||
|
|
||
| vi.mock('@/src/components/sharedComponents/TokenInput/useTokenInput', () => ({ | ||
| useTokenInput: vi.fn(() => ({ | ||
| amount: 0n, | ||
| setAmount: vi.fn(), | ||
| amountError: null, | ||
| setAmountError: vi.fn(), | ||
| balance: 0n, | ||
| balanceError: null, | ||
| isLoadingBalance: false, | ||
| selectedToken: undefined, | ||
| setTokenSelected: vi.fn(), | ||
| })), | ||
| })) | ||
|
|
||
| describe('TokenInput demo', () => { | ||
| it('renders the token input container', () => { | ||
| const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }) | ||
| renderWithProviders( | ||
| <QueryClientProvider client={queryClient}>{tokenInput.demo}</QueryClientProvider>, | ||
| ) | ||
| // The mode dropdown should be visible | ||
| expect(screen.getByText('Single token')).toBeDefined() | ||
| }) | ||
| }) |
19 changes: 19 additions & 0 deletions
19
src/components/pageComponents/home/Examples/demos/TransactionButton/index.test.tsx
This file contains hidden or 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,19 @@ | ||
| import { createMockWeb3Status, renderWithProviders } from '@/src/test-utils' | ||
| import { screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import transactionButton from './index' | ||
|
|
||
| vi.mock('@/src/hooks/useWeb3Status', () => ({ | ||
| useWeb3Status: vi.fn(() => createMockWeb3Status({ appChainId: 11155420 })), | ||
| })) | ||
|
|
||
| vi.mock('@/src/providers/Web3Provider', () => ({ | ||
| ConnectWalletButton: () => <button type="button">Connect Wallet</button>, | ||
| })) | ||
|
|
||
| describe('TransactionButton demo', () => { | ||
| it('renders connect wallet fallback when wallet not connected', () => { | ||
| renderWithProviders(transactionButton.demo) | ||
| expect(screen.getByRole('button', { name: 'Connect Wallet' })).toBeDefined() | ||
| }) | ||
| }) |
This file contains hidden or 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,21 @@ | ||
| import { renderWithProviders } from '@/src/test-utils' | ||
| import { screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { Home } from './index' | ||
|
|
||
| // Mock sub-components that pull in Web3 dependencies to keep this a pure structural test | ||
| vi.mock('@/src/components/pageComponents/home/Examples', () => ({ | ||
| default: () => <section data-testid="examples">Examples</section>, | ||
| })) | ||
|
|
||
| vi.mock('@/src/components/pageComponents/home/Welcome', () => ({ | ||
| default: () => <section data-testid="welcome">Welcome</section>, | ||
| })) | ||
|
|
||
| describe('Home', () => { | ||
| it('renders Welcome and Examples sections', () => { | ||
| renderWithProviders(<Home />) | ||
| expect(screen.getByTestId('welcome')).toBeDefined() | ||
| expect(screen.getByTestId('examples')).toBeDefined() | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️