diff --git a/src/apps/golf/components/PermalinkDisplay.tsx b/src/apps/golf/components/PermalinkDisplay.tsx index b178537..382eecb 100644 --- a/src/apps/golf/components/PermalinkDisplay.tsx +++ b/src/apps/golf/components/PermalinkDisplay.tsx @@ -16,32 +16,9 @@ const PermalinkDisplay = ({ label, url, onCopy }: PermalinkDisplayProps) => { setCopyStatus('copying') try { - // Try modern Clipboard API first - if (navigator.clipboard && window.isSecureContext) { - await navigator.clipboard.writeText(url) - setCopyStatus('success') - onCopy?.() - } else { - // Fallback method for older browsers or non-secure contexts - const textArea = document.createElement('textarea') - textArea.value = url - textArea.style.position = 'fixed' - textArea.style.left = '-999999px' - textArea.style.top = '-999999px' - document.body.appendChild(textArea) - textArea.focus() - textArea.select() - - const successful = document.execCommand('copy') - document.body.removeChild(textArea) - - if (successful) { - setCopyStatus('success') - onCopy?.() - } else { - throw new Error('Fallback copy method failed') - } - } + await navigator.clipboard.writeText(url) + setCopyStatus('success') + onCopy?.() } catch (error) { console.error('Failed to copy permalink:', error) setCopyStatus('error') diff --git a/src/apps/golf/components/__tests__/PermalinkDisplay.test.tsx b/src/apps/golf/components/__tests__/PermalinkDisplay.test.tsx index a676f45..30c2c58 100644 --- a/src/apps/golf/components/__tests__/PermalinkDisplay.test.tsx +++ b/src/apps/golf/components/__tests__/PermalinkDisplay.test.tsx @@ -7,9 +7,6 @@ const mockClipboard = { writeText: vi.fn() } -// Mock document.execCommand -const mockExecCommand = vi.fn() - describe('PermalinkDisplay', () => { const defaultProps = { label: 'Share Room', @@ -31,12 +28,6 @@ describe('PermalinkDisplay', () => { value: true, writable: true }) - - // Mock document.execCommand - Object.defineProperty(document, 'execCommand', { - value: mockExecCommand, - writable: true - }) }) afterEach(() => { @@ -128,83 +119,6 @@ describe('PermalinkDisplay', () => { }) }) - describe('Copy Functionality - Fallback Method', () => { - it('attempts fallback method when clipboard API is not available', async () => { - // Simulate no clipboard API or insecure context - Object.defineProperty(navigator, 'clipboard', { - value: undefined, - writable: true - }) - Object.defineProperty(window, 'isSecureContext', { - value: false, - writable: true - }) - - mockExecCommand.mockReturnValue(true) - - render() - - const copyButton = screen.getByRole('button', { name: /copy share room/i }) - fireEvent.click(copyButton) - - // Should attempt to use execCommand - await waitFor(() => { - expect(mockExecCommand).toHaveBeenCalledWith('copy') - }) - - await waitFor(() => { - expect(copyButton).toHaveTextContent('Copied!') - }) - }) - - it('handles fallback method failure', async () => { - // Simulate no clipboard API or insecure context - Object.defineProperty(navigator, 'clipboard', { - value: undefined, - writable: true - }) - Object.defineProperty(window, 'isSecureContext', { - value: false, - writable: true - }) - - mockExecCommand.mockReturnValue(false) - - render() - - const copyButton = screen.getByRole('button', { name: /copy share room/i }) - fireEvent.click(copyButton) - - await waitFor(() => { - expect(copyButton).toHaveTextContent('Failed') - }) - }) - - it('calls onCopy callback when fallback succeeds', async () => { - // Simulate no clipboard API or insecure context - Object.defineProperty(navigator, 'clipboard', { - value: undefined, - writable: true - }) - Object.defineProperty(window, 'isSecureContext', { - value: false, - writable: true - }) - - const onCopy = vi.fn() - mockExecCommand.mockReturnValue(true) - - render() - - const copyButton = screen.getByRole('button', { name: /copy share room/i }) - fireEvent.click(copyButton) - - await waitFor(() => { - expect(onCopy).toHaveBeenCalled() - }) - }) - }) - describe('Button States and Interactions', () => { it('disables button while copying', async () => { mockClipboard.writeText.mockImplementation(() => new Promise(resolve => setTimeout(resolve, 100)))