test: add demo page smoke tests (Tier 5)#419
test: add demo page smoke tests (Tier 5)#419gabitoesmiapodo wants to merge 3 commits intotest/componentsfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds Tier 5 smoke tests to ensure the home page, 404 page, and several demo components render without crashing by mocking Web3/wagmi dependencies at the module level.
Changes:
- Added smoke test for the Home page rendering its main sections.
- Added smoke tests for multiple demo components (ConnectWallet, EnsName, HashHandling, SignMessage, SwitchNetwork, TransactionButton, TokenDropdown, TokenInput).
- Added smoke test for the NotFound404 page.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/components/pageComponents/home/index.test.tsx | Smoke test that Home renders Welcome + Examples (mocked). |
| src/components/pageComponents/home/Examples/demos/TransactionButton/index.test.tsx | Smoke test for TransactionButton demo with Web3 status + ConnectWalletButton mocked. |
| src/components/pageComponents/home/Examples/demos/TokenInput/index.test.tsx | Smoke test for TokenInput demo using QueryClientProvider and mocked token hooks. |
| src/components/pageComponents/home/Examples/demos/TokenDropdown/index.test.tsx | Smoke test for TokenDropdown demo with shared TokenDropdown mocked. |
| src/components/pageComponents/home/Examples/demos/SwitchNetwork/index.test.tsx | Smoke test for SwitchNetwork demo showing Connect Wallet fallback. |
| src/components/pageComponents/home/Examples/demos/SignMessage/index.test.tsx | Smoke test for SignMessage demo showing Connect Wallet fallback. |
| src/components/pageComponents/home/Examples/demos/HashHandling/index.test.tsx | Smoke test for HashHandling demo with hash detection mocked. |
| src/components/pageComponents/home/Examples/demos/EnsName/index.test.tsx | Smoke test for EnsName demo with wagmi useEnsName mocked. |
| src/components/pageComponents/home/Examples/demos/ConnectWallet/index.test.tsx | Smoke test for ConnectWallet demo with ConnectWalletButton mocked. |
| src/components/pageComponents/NotFound404.test.tsx | Smoke test for NotFound404 rendering title and Home button with router navigation mocked. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| vi.mock('@/src/utils/hash', () => ({ | ||
| detectHash: vi.fn(() => Promise.resolve(null)), | ||
| })) |
There was a problem hiding this comment.
The mock for @/src/utils/hash exports a named detectHash, but the code under test (HashInput) imports the module's default export (import detectHash from ...). If HashInput ever invokes detectHash during this smoke test, it will be undefined and throw. Update the mock to provide a default export (and optionally keep any named exports if needed).
| vi.mock('@/src/utils/hash', () => ({ | |
| detectHash: vi.fn(() => Promise.resolve(null)), | |
| })) | |
| vi.mock('@/src/utils/hash', () => { | |
| const mockDetectHash = vi.fn(() => Promise.resolve(null)) | |
| return { | |
| default: mockDetectHash, | |
| detectHash: mockDetectHash, | |
| } | |
| }) |
There was a problem hiding this comment.
Fixed: mock factory now returns both default and named detectHash exports via a shared mock function.
2ecd9f4 to
b65a318
Compare
88ed222 to
27b5511
Compare
b65a318 to
03b8d50
Compare
27b5511 to
5d4e886
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| vi.mock('@/src/hooks/useWeb3Status', () => ({ | ||
| useWeb3Status: vi.fn(() => ({ | ||
| isWalletConnected: false, | ||
| isWalletSynced: false, | ||
| walletChainId: undefined, | ||
| appChainId: 11155420, | ||
| switchChain: vi.fn(), | ||
| })), | ||
| })) |
There was a problem hiding this comment.
Consider using the existing createMockWeb3Status helper from src/test-utils.tsx for the useWeb3Status mock return value. It provides a complete, stable shape for the hook and reduces the risk of future runtime failures if WalletStatusVerifier (or other code on this render path) starts reading additional fields.
There was a problem hiding this comment.
Fixed: switched to createMockWeb3Status({ appChainId: 11155420 }) from @/src/test-utils.
| vi.mock('@/src/components/sharedComponents/TokenInput/useTokenInput', () => ({ | ||
| useTokenInput: vi.fn(() => ({ | ||
| value: '', | ||
| token: undefined, | ||
| error: undefined, | ||
| onChange: vi.fn(), | ||
| onTokenSelect: vi.fn(), | ||
| })), | ||
| })) |
There was a problem hiding this comment.
useTokenInput is mocked with a shape that doesn't match the real hook return (it should provide amount/setAmount, balance, selectedToken, etc.). TokenInput destructures these fields and passes amount (a bigint) into BigNumberInput, so the current mock will cause runtime errors during render (e.g., formatUnits on undefined). Update the mock to return the full useTokenInput shape with sensible defaults (e.g., amount: 0n, balance: 0n, isLoadingBalance: false, and stub setter fns).
There was a problem hiding this comment.
Fixed: mock now returns the full useTokenInput shape — amount, setAmount, amountError, setAmountError, balance, balanceError, isLoadingBalance, selectedToken, setTokenSelected.
| import { ChakraProvider, createSystem, defaultConfig } from '@chakra-ui/react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { Home } from './index' | ||
|
|
||
| const system = createSystem(defaultConfig) |
There was a problem hiding this comment.
Test setup is duplicating the Chakra createSystem(defaultConfig) + ChakraProvider wrapper that already exists in src/test-utils.tsx as renderWithProviders. Using the shared helper here would reduce repeated setup across the growing test suite and keep provider configuration consistent.
There was a problem hiding this comment.
Fixed: replaced the inline ChakraProvider wrapper with renderWithProviders from @/src/test-utils.
03b8d50 to
82f2f21
Compare
5d4e886 to
5c9aa29
Compare
628a91a to
7b00d3b
Compare
Smoke tests for all demo page components to verify they render without crashing. Mocks external Web3 deps at module level. New test files: - home/index.test.tsx: Home renders Welcome + Examples sections - NotFound404.test.tsx: 404 page with mocked useNavigate - demos/ConnectWallet/index.test.tsx: mocked ConnectWalletButton - demos/EnsName/index.test.tsx: mocked useEnsName - demos/HashHandling/index.test.tsx: mocked useWeb3Status + detectHash - demos/SignMessage/index.test.tsx: shows fallback when wallet absent - demos/SwitchNetwork/index.test.tsx: shows fallback when wallet absent - demos/TransactionButton/index.test.tsx: shows fallback when wallet absent - demos/TokenDropdown/index.test.tsx: mocked BaseTokenDropdown - demos/TokenInput/index.test.tsx: mocked useTokenLists + useTokenSearch Also adds .env.test and src/test-utils.tsx (shared test utilities).
The module exports detectHash as a default export; the mock only provided a named export so HashInput would receive undefined and throw on invocation. Added both default and named exports to the mock factory.
- home/index.test.tsx: use renderWithProviders from test-utils - TransactionButton demo: use createMockWeb3Status for complete hook shape - TokenInput demo: fix useTokenInput mock to match the real hook return (amount/setAmount/amountError/balance/isLoadingBalance/selectedToken/setTokenSelected) and use renderWithProviders + createMockWeb3Status helpers
657ada0 to
b0fe779
Compare
Summary
Test plan
pnpm testpasses on this branchwithSuspenseAndRetrywrapped inQueryClientProviderin test setup