Merge pull request #16143 from overleaf/revert-15982-jel-dictionary-unlearn

Revert "[web] Only remove dictionary word from UI if unlearn request is successful"

GitOrigin-RevId: f95b3af48cf4de7e51fa1c06682c264e13dedaf9
This commit is contained in:
Jessica Lawshe 2023-12-06 09:18:53 -06:00 committed by Copybot
parent 3499ebe939
commit 4e51d6cd81
2 changed files with 5 additions and 13 deletions

View file

@ -23,17 +23,14 @@ export default function DictionaryModalContent({
const handleRemove = useCallback( const handleRemove = useCallback(
word => { word => {
ignoredWords.remove(word)
runAsync( runAsync(
postJSON('/spelling/unlearn', { postJSON('/spelling/unlearn', {
body: { body: {
word, word,
}, },
}) })
) ).catch(debugConsole.error)
.then(() => {
ignoredWords.remove(word)
})
.catch(debugConsole.error)
}, },
[runAsync] [runAsync]
) )

View file

@ -1,4 +1,4 @@
import { screen, fireEvent, waitFor } from '@testing-library/react' import { screen, fireEvent } from '@testing-library/react'
import { expect } from 'chai' import { expect } from 'chai'
import fetchMock from 'fetch-mock' import fetchMock from 'fetch-mock'
import DictionaryModal from '../../../../../frontend/js/features/dictionary/components/dictionary-modal' import DictionaryModal from '../../../../../frontend/js/features/dictionary/components/dictionary-modal'
@ -8,7 +8,6 @@ function setLearnedWords(words) {
window.metaAttributesCache.set('ol-learnedWords', words) window.metaAttributesCache.set('ol-learnedWords', words)
window.dispatchEvent(new CustomEvent('learnedWords:doreset')) window.dispatchEvent(new CustomEvent('learnedWords:doreset'))
} }
describe('<DictionaryModalContent />', function () { describe('<DictionaryModalContent />', function () {
beforeEach(function () { beforeEach(function () {
window.metaAttributesCache = window.metaAttributesCache || new Map() window.metaAttributesCache = window.metaAttributesCache || new Map()
@ -17,7 +16,6 @@ describe('<DictionaryModalContent />', function () {
afterEach(function () { afterEach(function () {
window.metaAttributesCache = new Map() window.metaAttributesCache = new Map()
fetchMock.reset() fetchMock.reset()
window.dispatchEvent(new CustomEvent('learnedWords:doreset'))
}) })
it('list words', async function () { it('list words', async function () {
@ -37,14 +35,12 @@ describe('<DictionaryModalContent />', function () {
fetchMock.post('/spelling/unlearn', 200) fetchMock.post('/spelling/unlearn', 200)
setLearnedWords(['Foo', 'bar']) setLearnedWords(['Foo', 'bar'])
renderWithEditorContext(<DictionaryModal show handleHide={() => {}} />) renderWithEditorContext(<DictionaryModal show handleHide={() => {}} />)
screen.getByText('Foo')
screen.getByText('bar') screen.getByText('bar')
const [firstButton] = screen.getAllByRole('button', { const [firstButton] = screen.getAllByRole('button', {
name: 'Remove from dictionary', name: 'Remove from dictionary',
}) })
fireEvent.click(firstButton) fireEvent.click(firstButton)
await fetchMock.flush() expect(screen.queryByText('bar')).to.not.exist
await waitFor(() => expect(screen.queryByText('bar')).to.not.exist)
screen.getByText('Foo') screen.getByText('Foo')
}) })
@ -52,13 +48,12 @@ describe('<DictionaryModalContent />', function () {
fetchMock.post('/spelling/unlearn', 500) fetchMock.post('/spelling/unlearn', 500)
setLearnedWords(['foo']) setLearnedWords(['foo'])
renderWithEditorContext(<DictionaryModal show handleHide={() => {}} />) renderWithEditorContext(<DictionaryModal show handleHide={() => {}} />)
screen.getByText('foo')
const [firstButton] = screen.getAllByRole('button', { const [firstButton] = screen.getAllByRole('button', {
name: 'Remove from dictionary', name: 'Remove from dictionary',
}) })
fireEvent.click(firstButton) fireEvent.click(firstButton)
await fetchMock.flush() await fetchMock.flush()
screen.getByText('Sorry, something went wrong') screen.getByText('Sorry, something went wrong')
screen.getByText('foo') screen.getByText('Your custom dictionary is empty.')
}) })
}) })