Skip to content

Commit

Permalink
Fixes Character Button to include new characters in combined Latin vo…
Browse files Browse the repository at this point in the history
…cabularies, fixed test.
  • Loading branch information
jermnelson committed Oct 12, 2020
1 parent a480f83 commit bcbaaa4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 5 additions & 5 deletions __tests__/feature/editing/editingLookup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,23 @@ describe('selecting a value from lookup', () => {
expect(input).toHaveValue('Fo')

// Click diacritic button
expect(screen.queryAllByText('Latin Extended')).toHaveLength(0)
expect(screen.queryAllByText('Latin')).toHaveLength(0)
const diacriticBtn = screen.getByTestId('Select diacritics for Instance of (lookup)')
fireEvent.click(diacriticBtn)

// Click a diacritic
await screen.findByText('Latin Extended')
fireEvent.change(screen.getByTestId('Select vocabulary'), { target: { value: 'latinextended' } })
await screen.findByText('Latin')
fireEvent.change(screen.getByTestId('Select vocabulary'), { target: { value: 'latin' } })
fireEvent.click(await screen.findByText('ọ'))
expect(input).toHaveValue('Foọ')

// press backspace while the focus is on the diacritic panel and make sure we are still on the edit page
fireEvent.keyDown(await screen.findByText('ọ'), { key: 'Backspace', code: 8, charCode: 8 })
expect(screen.queryAllByText('Latin Extended')).toHaveLength(1)
expect(screen.queryAllByText('Latin')).toHaveLength(1)

// Close it
fireEvent.click(diacriticBtn)
expect(screen.queryAllByText('Latin Extended')).toHaveLength(0)
expect(screen.queryAllByText('Latin')).toHaveLength(0)
})

it('allows paging', async () => {
Expand Down
9 changes: 7 additions & 2 deletions src/components/editor/diacritics/CharacterButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import PropTypes from 'prop-types'
const CharacterButton = (props) => {
const cleanCharacter = () => {
// For some reason, some combining characters are precombined with ◌ (U+25CC)
let cleanChars = ''
if (props.character.length > 1) {
for (let i = 0; i < props.character.length; i++) {
if (props.character.codePointAt(i) !== 9676) return props.character[i]
if (props.character.codePointAt(i) !== 9676) {
cleanChars += props.character[i]
}
}
} else {
cleanChars = props.character
}
return props.character
return cleanChars
}

const handleClick = (event) => {
Expand Down

0 comments on commit bcbaaa4

Please sign in to comment.