From 4e11ee5b0bf439b08aeb02c0111ccc3d2e5eda48 Mon Sep 17 00:00:00 2001 From: wheval Date: Mon, 29 Jun 2026 20:36:47 +0100 Subject: [PATCH] test(clipboard): add integration test for CopyField copying full unmasked wallet address - Assert clipboard receives the full 56-char Stellar address on button click - Assert copied value does not contain ellipsis shortening - Assert the input field displays the full value Closes accesslayerorg/accesslayer-client#476 --- .../__tests__/CopyField.clipboard.test.tsx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/components/common/__tests__/CopyField.clipboard.test.tsx diff --git a/src/components/common/__tests__/CopyField.clipboard.test.tsx b/src/components/common/__tests__/CopyField.clipboard.test.tsx new file mode 100644 index 0000000..4b17468 --- /dev/null +++ b/src/components/common/__tests__/CopyField.clipboard.test.tsx @@ -0,0 +1,43 @@ +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import CopyField from '../CopyField'; + +const FULL_ADDRESS = 'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWNA'; + +describe('CopyField — clipboard integration', () => { + beforeEach(() => { + Object.assign(navigator, { + clipboard: { + writeText: vi.fn().mockResolvedValue(undefined), + }, + }); + }); + + it('copies the full unmasked wallet address to the clipboard', async () => { + const user = userEvent.setup(); + render(); + + await user.click(screen.getByRole('button', { name: /copy wallet address/i })); + + expect(navigator.clipboard.writeText).toHaveBeenCalledOnce(); + expect(navigator.clipboard.writeText).toHaveBeenCalledWith(FULL_ADDRESS); + }); + + it('does not copy a shortened or ellipsis form of the address', async () => { + const user = userEvent.setup(); + render(); + + await user.click(screen.getByRole('button', { name: /copy wallet address/i })); + + const copied = (navigator.clipboard.writeText as ReturnType).mock.calls[0][0] as string; + expect(copied).not.toContain('...'); + expect(copied).toBe(FULL_ADDRESS); + }); + + it('passes the full value through the input display field', () => { + render(); + const input = screen.getByRole('textbox', { name: /wallet address/i }); + expect((input as HTMLInputElement).value).toBe(FULL_ADDRESS); + }); +});