Skip to content

Add tests for the ToastProvider context, auto-dismiss, and useToast guard #17

@mikewheeleer

Description

@mikewheeleer

Test the ToastProvider context, auto-dismiss timer, and useToast guard

Description

src/components/ToastProvider.tsx provides app-wide toasts (used by the layout) with a 4s auto-dismiss and a useToast hook that throws outside the provider — none of which is tested. The role="alert" vs role="status" distinction for error/info toasts is a meaningful a11y behaviour worth locking down. This issue adds coverage.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-frontend only.
  • Render a consumer that calls push, assert the message appears, error toasts use role="alert" and info toasts role="status", and the toast disappears after advancing fake timers by 4000 ms.
  • Assert useToast() throws the documented error when rendered outside <ToastProvider>.
  • Use jest.useFakeTimers() and act for the timer assertions.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/testing-18-toastprovider
  • Implement changes
    • Write comprehensive tests in: create src/components/__tests__/ToastProvider.test.tsx.
    • Add documentation: none beyond test descriptions.
    • Validate the live region container (aria-live="polite") is present.
  • Test and commit

Test and commit

  • Run npm run lint, npm run typecheck, and npm test.
  • Cover edge cases: multiple stacked toasts, default level (info), and the outside-provider throw.
  • Include the npm test output and coverage for the component.

Example commit message

test(components): cover ToastProvider dismiss timer and useToast guard

Guidelines

  • Minimum 95 percent test coverage for ToastProvider.tsx.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions