-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/chronology/ui/CuneiformConverter/CuneiformConverterForm.sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
textarea.form-control.assurbanipal | ||
font-size: 150% | ||
font-family: Assurbanipal, Junicode, serif !important | ||
textarea.form-control.neo-babylonian | ||
font-size: 150% | ||
font-family: Neo-Babylonian,'Adobe Blank', Junicode, serif !important |
59 changes: 59 additions & 0 deletions
59
src/chronology/ui/CuneiformConverter/CuneiformConverterForm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react' | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react' | ||
import CuneiformConverterForm from 'chronology/ui/CuneiformConverter/CuneiformConverterForm' | ||
import SignService from 'signs/application/SignService' | ||
|
||
jest.mock('signs/application/SignService') | ||
const signServiceMock = new (SignService as jest.Mock< | ||
jest.Mocked<SignService> | ||
>)() | ||
|
||
describe('CuneiformConverterForm', () => { | ||
beforeEach(() => { | ||
Object.defineProperty(window.navigator, 'clipboard', { | ||
value: { | ||
writeText: jest.fn().mockResolvedValue(true), | ||
}, | ||
writable: true, | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('renders form, options, and scenario panel correctly', () => { | ||
render(<CuneiformConverterForm signService={signServiceMock} />) | ||
expect(screen.getByLabelText('Text to Convert')).toBeInTheDocument() | ||
expect(screen.getByLabelText('Select Font')).toBeInTheDocument() | ||
expect(screen.getByLabelText('Text to Convert')).toBeInTheDocument() | ||
}) | ||
it('handles input change', () => { | ||
render(<CuneiformConverterForm signService={signServiceMock} />) | ||
const inputTextArea = screen.getByLabelText('Text to Convert') | ||
fireEvent.change(inputTextArea, { target: { value: 'test text' } }) | ||
expect(inputTextArea).toHaveValue('test text') | ||
}) | ||
it('handles font change', () => { | ||
render(<CuneiformConverterForm signService={signServiceMock} />) | ||
const fontSelector = screen.getByLabelText('Select Font') | ||
fireEvent.change(fontSelector, { target: { value: 'Neo-Babylonian' } }) | ||
expect(fontSelector).toHaveValue('Neo-Babylonian') | ||
}) | ||
it('converts text correctly', async () => { | ||
signServiceMock.getUnicodeFromAtf.mockResolvedValueOnce([ | ||
{ unicode: [73979] }, | ||
]) | ||
render(<CuneiformConverterForm signService={signServiceMock} />) | ||
|
||
const inputTextArea = screen.getByLabelText('Text to Convert') | ||
fireEvent.change(inputTextArea, { target: { value: 'test text' } }) | ||
|
||
const convertButton = screen.getByText('Convert') | ||
fireEvent.click(convertButton) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByLabelText('Converted Text')).toHaveValue('𒃻') | ||
}) | ||
}) | ||
}) |
106 changes: 106 additions & 0 deletions
106
src/chronology/ui/CuneiformConverter/CuneiformConverterForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import React, { useState } from 'react' | ||
import { Form, Button } from 'react-bootstrap' | ||
import Bluebird from 'bluebird' | ||
import SignService from 'signs/application/SignService' | ||
import replaceTransliteration from 'fragmentarium/domain/replaceTransliteration' | ||
import { displayUnicode } from 'signs/ui/search/SignsSearch' | ||
import './CuneiformConverterForm.sass' | ||
|
||
function CuneiformConverterForm({ | ||
signService, | ||
}: { | ||
signService: SignService | ||
}): JSX.Element { | ||
const [content, setContent] = useState('') | ||
const [convertedContent, setConvertedContent] = useState('') | ||
const [selectedFont, setSelectedFont] = useState('Assurbanipal') | ||
|
||
const handleChange = (event) => { | ||
setContent(event.target.value) | ||
} | ||
|
||
const handleConvert = () => { | ||
const lines = content.split('\n') | ||
const replacedLines = lines.map((line) => replaceTransliteration(line)) | ||
|
||
Promise.all( | ||
replacedLines | ||
.filter((line) => line.trim() !== '') | ||
.map((line) => query(line)) | ||
) | ||
.then((results) => { | ||
const convertedText = results | ||
.map((result) => | ||
result | ||
.map((entry) => | ||
entry.unicode[0] === 9999 ? ' ' : displayUnicode(entry.unicode) | ||
) | ||
.join('') | ||
) | ||
.join('\n') | ||
|
||
setConvertedContent(convertedText) | ||
}) | ||
.catch((error) => { | ||
console.error('Query Error:', error) | ||
}) | ||
} | ||
|
||
const query = (content) => { | ||
return Bluebird.resolve(signService.getUnicodeFromAtf(content)) | ||
} | ||
|
||
const handleKeyDown = (event) => { | ||
if (event.key === 'Enter' && !event.shiftKey) { | ||
event.preventDefault() | ||
handleConvert() | ||
} | ||
} | ||
|
||
const handleFontChange = (event) => { | ||
setSelectedFont(event.target.value) | ||
} | ||
|
||
return ( | ||
<> | ||
<Form.Label htmlFor="inputText">Text to Convert</Form.Label> | ||
<Form.Control | ||
as="textarea" | ||
id="inputText" | ||
aria-describedby="textHelpBlock" | ||
value={content} | ||
onChange={handleChange} | ||
onKeyDown={handleKeyDown} | ||
/> | ||
<Form.Text id="textHelpBlock" muted> | ||
Enter the text you want to convert to Unicode. | ||
</Form.Text> | ||
<Form.Label htmlFor="fontSelector">Select Font</Form.Label> | ||
<select | ||
id="fontSelector" | ||
className="form-select" | ||
value={selectedFont} | ||
onChange={handleFontChange} | ||
> | ||
<option value="Assurbanipal">Neo-Assyrian</option> | ||
<option value="Neo-Babylonian">Neo-Babylonian</option> | ||
</select> | ||
<Button onClick={handleConvert}>Convert</Button> | ||
<br></br> | ||
<Form.Label htmlFor="outputText">Converted Text</Form.Label> | ||
<Form.Control | ||
as="textarea" | ||
id="outputText" | ||
className={`${selectedFont.toLowerCase().replace(/\s/g, '-')}`} | ||
aria-describedby="outputHelpBlock" | ||
value={convertedContent} | ||
readOnly | ||
/> | ||
<Form.Text id="outputHelpBlock" muted> | ||
This is the converted Unicode text. | ||
</Form.Text> | ||
</> | ||
) | ||
} | ||
|
||
export default CuneiformConverterForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters