Skip to content

Test: Implement Component: Live Currency Converter Rate Polling - #524

Open
AdaBliss wants to merge 1 commit into
SwiftChainn:mainfrom
AdaBliss:test-comp-currency-converter
Open

Test: Implement Component: Live Currency Converter Rate Polling#524
AdaBliss wants to merge 1 commit into
SwiftChainn:mainfrom
AdaBliss:test-comp-currency-converter

Conversation

@AdaBliss

Copy link
Copy Markdown

closes #504

Summary

Adds component tests for the live currency converter widget, focused on the question the issue asks: does the XLM rate refetch actually fire at the correct intervals?

useCurrencyConverter polls with refetchInterval: 30_000. The existing hook test covers the rate calculation and error fallback but never advances time, so the polling behaviour itself was untested. These tests fake timers and assert the exact call counts at the interval boundaries.

Test coverage

features/deliveries/components/__tests__/CurrencyConverter.test.tsx (19 tests). currencyRateService is mocked and Jest fake timers drive the clock, so the suite is deterministic and never issues a network request.

Rate polling

  • Fetches exactly once on mount, for the default USD.
  • Does not refetch at interval - 1ms, proving the boundary rather than just "eventually refetches".
  • Refetches exactly once per interval (2 calls at 30s, 3 at 60s).
  • Sustains a steady cadence across four intervals (1 mount fetch + 4 refetches).
  • Renders the newest rate a poll returns: the estimate moves from 20.000000 XLM to 40.000000 XLM when the rate halves.
  • Stops polling on unmount, so a dismounted widget cannot keep hitting the endpoint.
  • Switches the polled currency after a selection change and keeps polling the new code.
  • Keeps polling after a failed request, so a transient outage recovers on the next tick instead of leaving the widget stuck.

Happy path rendering

  • Loading message until the first rate resolves, all supported fiat codes offered, live rate and last-updated timestamp, estimate recalculated as the amount is edited, amount field relabelled on currency change.

Error handling

  • Fallback message on failure with no stale estimate shown, and the retry button recovering once the endpoint returns.

Edge cases

  • Empty amount treated as zero rather than NaN, negative amount clamped to zero, no estimate rendered when the API reports a zero rate, and a sub-cent rate that does not lose precision.

Verification

  • npx jest features/deliveries/components/__tests__/CurrencyConverter.test.tsx - 19 tests passing.
  • The polling assertions are load-bearing: temporarily removing refetchInterval from the hook fails 5 of them, so they cannot pass vacuously.
  • Full suite: no new failures; the failing suites on this branch are exactly those already failing on main.
  • npx eslint on the new file - clean. npx tsc --noEmit - no errors from this change.

Test-only change; no production code was modified.

Note for the maintainer

main currently fails the CI Type Check and Build Verification steps for an unrelated reason: components/mobile/MobileFooter.tsx landed with its string quotes stripped (line 1 is a backtick-quoted use client, and imports read import React from react), which trips TS1160: Unterminated template literal. It came in with #318 and is present on main independently of this PR, so it will show red here and on every other open PR until it is fixed. I left it alone to keep this PR scoped to the issue; happy to open a separate fix PR if that would help.

Add component tests for the live currency converter, focused on when the
XLM rate refetch actually fires.

Timers are faked and currencyRateService is mocked, so the suite is
deterministic and never issues a network request.

Covers: single fetch on mount, no refetch before the 30s interval elapses,
exactly one refetch per interval, sustained polling across intervals,
polling switching to a newly selected fiat currency, polling stopping on
unmount, and recovery polling after a failed request. Adds happy-path
rendering, retry-on-error and amount edge cases (empty, negative, zero
rate, sub-cent rate).
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@AdaBliss Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Test] Component: Live Currency Converter Rate Polling

1 participant