Test: Implement Component: Live Currency Converter Rate Polling - #524
Open
AdaBliss wants to merge 1 commit into
Open
Test: Implement Component: Live Currency Converter Rate Polling#524AdaBliss wants to merge 1 commit into
AdaBliss wants to merge 1 commit into
Conversation
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).
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?
useCurrencyConverterpolls withrefetchInterval: 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).currencyRateServiceis mocked and Jest fake timers drive the clock, so the suite is deterministic and never issues a network request.Rate polling
USD.interval - 1ms, proving the boundary rather than just "eventually refetches".20.000000 XLMto40.000000 XLMwhen the rate halves.Happy path rendering
Error handling
Edge cases
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.refetchIntervalfrom the hook fails 5 of them, so they cannot pass vacuously.main.npx eslinton the new file - clean.npx tsc --noEmit- no errors from this change.Test-only change; no production code was modified.
Note for the maintainer
maincurrently fails the CIType CheckandBuild Verificationsteps for an unrelated reason:components/mobile/MobileFooter.tsxlanded with its string quotes stripped (line 1 is a backtick-quoteduse client, and imports readimport React from react), which tripsTS1160: Unterminated template literal. It came in with #318 and is present onmainindependently 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.