test: cover CopyButton clipboard states#310
Conversation
|
Someone is attempting to deploy a commit to the ankanmisra's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds component tests covering CopyButton accessibility, clipboard success and failure states, analytics emission, timer resets, repeated clicks, and cleanup on unmount. ChangesCopyButton component tests
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
AnkanMisra
left a comment
There was a problem hiding this comment.
Thanks for the focused coverage—most of issue #262 is well protected. One documented timing contract still needs an assertion before merge.
Verdict: request changes
Biggest risk: the copied-state duration can regress without this suite failing.
Tests: CI web lint/build is green; the supplied review also reports the full web suite, typecheck, and lint passing.
| function installDeterministicTimers(): void { | ||
| nextTimerId = 1; | ||
| pendingTimers = new Map(); | ||
| window.setTimeout = ((callback: TimerHandler) => { |
There was a problem hiding this comment.
[P2] Assert the 1.6-second reset delay
File: web/src/components/copy-button.test.tsx
Problem: The fake setTimeout discards its delay argument, and the reset test invokes the callback manually. A runtime change from 1600 ms to an incorrect value would therefore still pass.
Impact: The explicitly documented 1.6-second behavior in issue #262 is not protected against regression.
Fix: Record the delay supplied to setTimeout and assert that the scheduled reset uses 1600 ms.
|
Implemented the requested review fix in 028dcc3: the deterministic timer harness now records delays, and the reset test asserts the component schedules the documented 1600ms timeout. Revalidated the focused unit test, web typecheck, lint, and git diff --check. |
Summary
Validation
Fixes #262
Note
Add unit tests for CopyButton clipboard states
Adds a test suite in copy-button.test.tsx covering the full
CopyButtonlifecycle: accessible label synthesis and override, successful copy with analytics emission, scheduled label reset after 1600ms, timeout replacement on repeated clicks, failure path (no label change, no analytics), and timer cleanup on unmount. Uses custominstallDeterministicTimersandinstallClipboardhelpers for full control over async behavior without real timers or clipboard APIs.Macroscope summarized 028dcc3.
Summary by CodeRabbit