Repository navigation
test(#1584): add dedicated tests for NewsletterSignup cooldown logic - #1648
Merged
hman38705 merged 1 commit intoSep 27, 2026
Conversation
…ooldown logic
Covers all three acceptance criteria:
AC1 — 429 → server-side cooldown with retry_after:
- Error shown, button disabled after a 429 response
- Cooldown uses server-provided retry_after value
- Falls back to DEFAULT_RATE_LIMIT_COOLDOWN_SECS (30 s) when retry_after absent
- Button stays disabled during 429 lockout even after editing email (isServerRateLimited guard)
- Countdown ticks down and re-enables button at zero (real-timer test, 10 s timeout)
AC2 — non-429 failure → short CLIENT_SUBMIT_COOLDOWN_SECS (3 s):
- Generic network error shows message and starts 3 s cooldown
- { success: false } response starts 3 s cooldown
- Cooldown expires, button re-enables and shows original label (real-timer test)
- 500 error does NOT set isServerRateLimited → editing email immediately re-enables button
AC3 — same-email resubmit blocked / unblocked by editing:
- Blocked: form submit during active cooldown shows 'please wait' and skips API call
- Unblocked: changing to a different email immediately re-enables button
- Guard works: button stays disabled while cooldown active and email unchanged
- Fresh success after changing email under client cooldown
Also covers: rendering, successful submission, client-side validation,
button label transitions (Wait (Ns) → default → Subscribed).
Timer strategy: all tests run with real timers throughout (setInterval
is started with real timers so fake-timer advancement won't affect existing
intervals). The two countdown-duration tests use 10 s Jest timeouts.
|
@wendyamoni-creator 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.
Summary
Closes #1584.
Adds
frontend/src/components/__tests__/NewsletterSignup.test.tsx— a dedicated test file for the component's cooldown/rate-limit state machine, isolated from the LandingPage suites. 23 tests, all passing.Coverage by acceptance criterion
AC1 — 429 response → server-side cooldown with
retry_afterretry_aftervalueDEFAULT_RATE_LIMIT_COOLDOWN_SECS(30 s) whenretry_afteris absentisServerRateLimitedguard)Wait (3s)→Wait (2s)→ re-enabled) via realsetIntervalAC2 — Non-429 failure → short
CLIENT_SUBMIT_COOLDOWN_SECS(3 s){ success: false }API response also starts a 3 s cooldownisServerRateLimited→ editing the email immediately re-enables the buttonAC3 — Same-email resubmit blocked / unblocked by editing
please waiterror and skips the API callAdditional coverage
Rendering, successful submission +
onSuccesscallback, client-side validation (empty / malformed), button label transitions (Wait (Ns)→ default →Subscribed).Timer strategy
All tests run with real timers throughout. The component's
setIntervalis always started with real timers, so switching to fake timers after the fact does not advance existing intervals. The two countdown-duration tests (3 s) use a 10 s Jest timeout.Test results
No regressions in the broader suite (pre-existing failures are unrelated issues in other files).