Skip to content

Add component tests for the wallet flow (WalletContext persistence and useWallet connect/disconnect/sign) #213

@greatest0fallt1me

Description

@greatest0fallt1me

Description

The wallet layer is entirely untested: context/WalletContext.tsx persists {address, name, connected} to localStorage under predictify_wallet_state and reconnects on mount, and hooks/useWallet.hook.ts wraps @creit.tech/stellar-wallets-kit for connectWallet, disconnectWallet, and signTransaction, yet a repo-wide search finds no tests for either. Given wallet state is the core of the app's identity, this issue adds unit tests with the kit mocked.

Requirements and context

  • Add context/__tests__/WalletContext.test.tsx covering: hydration from localStorage on mount, persistence on connect, key removal on disconnect, and that useWalletContext throws outside a provider.
  • Add hooks/__tests__/useWallet.test.tsx mocking getKit() from constants/wallet-kits.constant.ts to cover connectWallet success/failure, disconnectWallet, signTransaction success and the "No wallet connected" guard, and the isConnecting/error state.
  • Non-functional: tests must mock localStorage and the kit (no real wallet); assert the returned discriminated {success, ...} shapes; deterministic with no real async wallet calls.
  • Follow the existing Jest + React Testing Library conventions and jest.setup.js.

Acceptance criteria

  • context/__tests__/WalletContext.test.tsx verifies hydrate/persist/clear and the provider guard.
  • hooks/__tests__/useWallet.test.tsx covers connect success/failure, disconnect, and sign success/guard.
  • The wallet kit is mocked; no real network/wallet interaction occurs.
  • Returned {success, address|signedTxXdr|error} shapes are asserted.
  • error and isConnecting state transitions are asserted.
  • Combined coverage for WalletContext.tsx and useWallet.hook.ts reaches >=90% lines.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/wallet-tests.

2. Implement changes — add context/__tests__/WalletContext.test.tsx and hooks/__tests__/useWallet.test.tsx; mock constants/wallet-kits.constant.ts.

3. Write/extend tests — Jest + React Testing Library + renderHook from @testing-library/react with pnpm; mock localStorage and getKit. Mirror the style of lib/__tests__/scroll-position-store.test.ts.

4. Test and commit

pnpm install
pnpm test
pnpm test:coverage
pnpm lint

Example commit message

test(wallet): cover WalletContext persistence and useWallet connect/disconnect/sign

Guidelines

  • Raise wallet coverage from 0% to >=90% line coverage for the two files.
  • Note that collectCoverageFrom in jest.config.js currently omits context/ and hooks/; mention extending it so wallet coverage is reported.
  • Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions