Skip to content

Write tests for AddressDisplay truncation copy-to-clipboard and clipboard fallback #604

Description

@k-deejah

Problem

src/components/AddressDisplay.tsx has three distinct testable behaviors with zero coverage: the address is truncated by default using truncateAddress() from src/lib/utils.ts, the copy button calls navigator.clipboard.writeText, and the button aria-label changes to "Copied!" after a successful copy.

The known bug where the copy operation silently fails in non-HTTPS contexts also has no regression test. Without a test that mocks a rejected clipboard promise, any fix to the fallback behavior can be reverted without detection. A third untested behavior: the 2-second reset timeout that changes the aria-label back from "Copied!" to the default — if the timeout is accidentally removed, the label stays "Copied!" forever.

Solution

Write React Testing Library + @testing-library/user-event tests for AddressDisplay. Mock navigator.clipboard using vi.stubGlobal. Test:

  • Truncated address is displayed by default (not the full 56-char Stellar address)
  • Clicking the copy button calls navigator.clipboard.writeText with the full address
  • The copy button aria-label changes to "Copied!" immediately after click
  • The aria-label resets back after 2 seconds (use vi.useFakeTimers)
  • When clipboard.writeText rejects, the fallback document.execCommand is attempted
  • No error is thrown when clipboard is unavailable

Acceptance Criteria

  • Truncated address renders by default
  • Copy button calls clipboard API with the full untruncated address
  • aria-label updates to "Copied!" immediately after successful copy
  • aria-label resets after 2 seconds using fake timers
  • Clipboard rejection triggers the execCommand fallback path
  • All tests pass with npm test

Note for Contributors: If you're assigned to this issue, write a clear and detailed description for your pull request. Explain what was changed, why it was needed, how it was implemented, and include any relevant testing or screenshots where applicable.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programtestsTest coverage, test setup, or test infrastructure

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions