Skip to content

test(#1584): add dedicated tests for NewsletterSignup cooldown logic - #1648

Merged
hman38705 merged 1 commit into
solutions-plug:mainfrom
wendyamoni-creator:fix/1584-newsletter-cooldown-tests
Sep 27, 2026
Merged

hman38705 merged 1 commit into
solutions-plug:mainfrom
wendyamoni-creator:fix/1584-newsletter-cooldown-tests

Conversation

@wendyamoni-creator

Copy link
Copy Markdown
Contributor

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_after

  • Error shown and button disabled after a 429 response
  • Cooldown duration uses the server-provided retry_after value
  • Falls back to DEFAULT_RATE_LIMIT_COOLDOWN_SECS (30 s) when retry_after is absent
  • Button stays disabled during a 429 lockout even after editing the email field (isServerRateLimited guard)
  • Button label ticks down (Wait (3s) → Wait (2s) → re-enabled) via real setInterval

AC2 — Non-429 failure → short CLIENT_SUBMIT_COOLDOWN_SECS (3 s)

  • Generic network error shows the error message and starts a 3 s cooldown
  • { success: false } API response also starts a 3 s cooldown
  • Cooldown expires, button re-enables and shows the original label
  • 500 error does not set isServerRateLimited → editing the email immediately re-enables the button

AC3 — Same-email resubmit blocked / unblocked by editing

  • Form submit during active cooldown shows please wait error and skips the API call
  • Changing to a different email immediately re-enables the button
  • Button stays disabled while cooldown is active and email is unchanged
  • After changing email, a fresh submission can succeed end-to-end

Additional coverage

Rendering, successful submission + onSuccess callback, client-side validation (empty / malformed), button label transitions (Wait (Ns) → default → Subscribed).

Timer strategy

All tests run with real timers throughout. The component's setInterval is 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

PASS src/components/__tests__/NewsletterSignup.test.tsx

Tests: 23 passed, 23 total

No regressions in the broader suite (pre-existing failures are unrelated issues in other files).

…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.
@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@hman38705
hman38705 merged commit 58786a2 into solutions-plug:main Sep 27, 2026
15 of 62 checks passed
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.

NewsletterSignup's client-side rate-limit/cooldown logic has no dedicated test coverage

2 participants