Skip to content

Add component tests for CopyButton clipboard states and analytics #262

Description

@AnkanMisra

Summary

The shared copy button is used across the web UI for copyable values and code snippets. It handles clipboard access, temporary success feedback, optional analytics, accessible labels, repeated clicks, and cleanup on unmount, but it has no direct component tests.

Current behavior

On a successful clipboard write, the button changes from its normal label to a copied label for 1.6 seconds and optionally records an analytics event. Clipboard failures are intentionally silent. A pending reset timer is cleared on repeated clicks and when the component unmounts.

Desired behavior

Add focused component tests for the existing behavior using the web test DOM setup, a mocked clipboard, deterministic timers, and a mocked analytics sink. Do not change the visual design or runtime behavior.

Key interfaces

  • CopyButton props — value, visible labels, accessible label override, CSS class, analytics event, and analytics properties.
  • Browser clipboard writeText() — success and rejection paths.
  • Temporary copied state — activation, reset, repeated-click timer replacement, and unmount cleanup.
  • Browser analytics capture — success-only delivery with the supplied event and properties.

Acceptance criteria

  • The default accessible label includes the normal label and a bounded preview of the copied value.
  • A custom accessible label and custom CSS class are preserved.
  • A successful click writes the exact value and displays the configured copied label.
  • The label returns to its original value after the existing timeout.
  • Repeated successful clicks replace the pending reset instead of creating competing visible-state changes.
  • Analytics is emitted once per successful copy with the supplied event and properties.
  • A rejected clipboard write does not show copied state and does not emit analytics.
  • Unmounting with a pending timer does not produce a state update or leaked timer.
  • cd web && bun run test:unit && bun run typecheck passes.

Out of scope

  • Redesigning the button, icons, animation, or timing.
  • Adding toast notifications for clipboard failures.
  • Changing the analytics event vocabulary.
  • Browser end-to-end testing.

Blocked by

None — can start immediately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptTypeScript codeenhancementNew feature or requestgood first issueGood for newcomersgssoc:approvedApproved for GSSoC contributionlevel:beginnerSmall, well-scoped work suitable for newer contributors.type:accessibilityAccessibility, keyboard, screen-reader, or inclusive UX work.type:testingTests, coverage, fixtures, or validation-only work.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions