Skip to content

Write tests for ContractEventFeed initial load polling live toggle and error states #602

Description

@k-deejah

Problem

src/components/ContractEventFeed.tsx fetches events on mount, supports live polling via setInterval, handles error and empty states, and exposes a Live/Paused toggle. None of this is tested.

The stale closure polling bug (load not in dependency array — tracked separately) makes this component especially risky to modify without tests — there is no safety net to verify correct polling behavior after a fix. Three specific untested behaviors: (1) the initial fetch fires on mount with the correct contractId; (2) the Live/Paused toggle stops and restarts the polling interval; (3) when contractId changes, the component fetches for the new ID, not the old one.

Solution

Write React Testing Library tests using vi.useFakeTimers() for polling control. Test:

  • Initial fetch is called on mount with the correct contractId prop
  • Events render in a list after a successful fetch
  • Empty state renders when fetch returns an empty array
  • Error message renders when fetch returns an error
  • Polling calls getEvents at the configured pollInterval using fake timers
  • Toggling the Live button pauses polling (no further calls after toggle)
  • Changing contractId prop triggers a new fetch for the new ID

Acceptance Criteria

  • Initial fetch fires with the correct contractId
  • Event list renders returned events
  • Empty state renders when no events exist
  • Error state renders error message
  • Polling fires at correct interval with fake timers
  • Live toggle stops polling when switched to Paused
  • Changing contractId fetches for the new contract
  • All tests pass with npm test

Note for Contributors: If you're assigned to this issue, write a clear and detailed description for your pull request. Explain what was changed, why it was needed, how it was implemented, and include any relevant testing or screenshots where applicable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programtestsTest coverage, test setup, or test infrastructure

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions