Skip to content

Commit

Permalink
copies converted text to clipboard - Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Vas9ka committed Jun 24, 2024
1 parent 900e4c6 commit 77f3ade
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,27 @@ describe('CuneiformConverterForm', () => {
expect(screen.getByLabelText('Converted Text')).toHaveValue('𒃻')
})
})

it('copies converted text to clipboard', async () => {
signServiceMock.getUnicodeFromAtf.mockResolvedValueOnce([
{ unicode: [73979] },
])

const inputTextArea = screen.getByLabelText('input-atf')
fireEvent.change(inputTextArea, { target: { value: 'test text' } })

const convertButton = screen.getByText('Convert')
fireEvent.click(convertButton)

await waitFor(() => {
expect(screen.getByLabelText('Converted Text')).toHaveValue('𒃻')
})

const copyButton = screen.getByText('Copy')
fireEvent.click(copyButton)

await waitFor(() => {
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('𒃻')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ function CuneiformConverterForm({
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(convertedContent)
alert('Text copied to clipboard!')
} catch (err) {
console.error('Failed to copy text: ', err)
alert('Failed to copy text')
}
}

Expand Down

0 comments on commit 77f3ade

Please sign in to comment.