Skip to content

Commit

Permalink
Fix converter cuneiform (#486)
Browse files Browse the repository at this point in the history
* * Wrapped css into class

* fixed upper case

* * Added button for copy text

* copies converted text to clipboard - Test
  • Loading branch information
Vas9ka authored Jun 24, 2024
1 parent f10724f commit a56edc2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 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('𒃻')
})
})
})
13 changes: 10 additions & 3 deletions src/chronology/ui/CuneiformConverter/CuneiformConverterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ function CuneiformConverterForm({
handleConvert()
}
}
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(convertedContent)
} catch (err) {
console.error('Failed to copy text: ', err)
}
}

const handleFontChange = (event) => {
setSelectedFont(event.target.value)
Expand Down Expand Up @@ -110,9 +117,9 @@ function CuneiformConverterForm({
value={convertedContent}
readOnly
/>
<Form.Text id="outputHelpBlock" muted>
This is the converted Unicode text.
</Form.Text>
<Button onClick={copyToClipboard} variant="primary" className="mt-2">
Copy
</Button>
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ exports[`CuneiformConverterForm renders form, options, and scenario panel correc
id="outputText"
readonly=""
/>
<small
class="form-text text-muted"
id="outputHelpBlock"
<button
class="mt-2 btn btn-primary"
type="button"
>
This is the converted Unicode text.
</small>
Copy
</button>
</div>
</div>
`;

0 comments on commit a56edc2

Please sign in to comment.