Skip to content

test: cover CopyButton clipboard states#310

Open
saurabhhhcodes wants to merge 2 commits into
AnkanMisra:mainfrom
saurabhhhcodes:test/copy-button-262
Open

test: cover CopyButton clipboard states#310
saurabhhhcodes wants to merge 2 commits into
AnkanMisra:mainfrom
saurabhhhcodes:test/copy-button-262

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add component tests for CopyButton accessibility, custom props, clipboard success/failure, analytics, copied-state reset, repeated clicks, and unmount cleanup.
  • Use a deterministic local timer scheduler and mocked browser clipboard/analytics APIs.

Validation

  • cd web && bun test src/components/copy-button.test.tsx
  • cd web && bun run typecheck
  • git diff --check

Fixes #262

Note

Add unit tests for CopyButton clipboard states

Adds a test suite in copy-button.test.tsx covering the full CopyButton lifecycle: 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 custom installDeterministicTimers and installClipboard helpers for full control over async behavior without real timers or clipboard APIs.

Macroscope summarized 028dcc3.

Summary by CodeRabbit

  • Tests
    • Added comprehensive coverage for the copy button’s accessibility labels, custom properties, clipboard behavior, copied-state messaging, reset timing, analytics events, error handling, and cleanup.

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3170d6cd-5fbf-4a41-901b-bff5366e559d

📥 Commits

Reviewing files that changed from the base of the PR and between a65d772 and 028dcc3.

📒 Files selected for processing (1)
  • web/src/components/copy-button.test.tsx

📝 Walkthrough

Walkthrough

Adds component tests covering CopyButton accessibility, clipboard success and failure states, analytics emission, timer resets, repeated clicks, and cleanup on unmount.

Changes

CopyButton component tests

Layer / File(s) Summary
Test harness and accessibility coverage
web/src/components/copy-button.test.tsx
Adds deterministic timer and clipboard mocks, resets test globals, and verifies bounded accessible labels and preserved custom props.
Copy lifecycle, analytics, and cleanup
web/src/components/copy-button.test.tsx
Tests successful copies, copied-label resets, analytics payloads, repeated-click timer replacement, rejected writes, and unmount cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ankanmisra

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes summary and validation, but it omits most required template sections like type, affected areas, checklist, and notes. Fill out the full template, especially Type Of Change, Affected Areas, Contributor Checklist, Verification details, and Notes For Reviewers.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the new CopyButton test coverage.
Linked Issues check ✅ Passed The tests cover the linked issue's required CopyButton states, analytics, timer reset behavior, failure path, and unmount cleanup.
Out of Scope Changes check ✅ Passed The change appears focused on a single test file and does not introduce unrelated runtime or UI changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added TypeScript TypeScript code type:testing Tests, coverage, fixtures, or validation-only work. labels Jul 15, 2026

@AnkanMisra AnkanMisra left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread web/src/components/copy-button.test.tsx Outdated
function installDeterministicTimers(): void {
nextTimerId = 1;
pendingTimers = new Map();
window.setTimeout = ((callback: TimerHandler) => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@AnkanMisra AnkanMisra added enhancement New feature or request good first issue Good for newcomers labels Jul 15, 2026
@AnkanMisra AnkanMisra added level:beginner Small, well-scoped work suitable for newer contributors. type:accessibility Accessibility, keyboard, screen-reader, or inclusive UX work. gssoc:approved Approved for GSSoC contribution labels Jul 15, 2026
@saurabhhhcodes

Copy link
Copy Markdown
Contributor Author

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.

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

Labels

enhancement New feature or request good first issue Good for newcomers gssoc:approved Approved for GSSoC contribution level:beginner Small, well-scoped work suitable for newer contributors. type:accessibility Accessibility, keyboard, screen-reader, or inclusive UX work. type:testing Tests, coverage, fixtures, or validation-only work. TypeScript TypeScript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add component tests for CopyButton clipboard states and analytics

2 participants