From 4e51d6cd81608a41e659c67974800fa946aebdbe Mon Sep 17 00:00:00 2001 From: Jessica Lawshe <5312836+lawshe@users.noreply.github.com> Date: Wed, 6 Dec 2023 09:18:53 -0600 Subject: [PATCH] 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 --- .../components/dictionary-modal-content.tsx | 7 ++----- .../components/dictionary-modal-content.test.jsx | 11 +++-------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx b/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx index c68e96b5af..cd0af3cd77 100644 --- a/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx +++ b/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx @@ -23,17 +23,14 @@ export default function DictionaryModalContent({ const handleRemove = useCallback( word => { + ignoredWords.remove(word) runAsync( postJSON('/spelling/unlearn', { body: { word, }, }) - ) - .then(() => { - ignoredWords.remove(word) - }) - .catch(debugConsole.error) + ).catch(debugConsole.error) }, [runAsync] ) diff --git a/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx b/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx index 11b549fdf0..072357dd83 100644 --- a/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx +++ b/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx @@ -1,4 +1,4 @@ -import { screen, fireEvent, waitFor } from '@testing-library/react' +import { screen, fireEvent } from '@testing-library/react' import { expect } from 'chai' import fetchMock from 'fetch-mock' import DictionaryModal from '../../../../../frontend/js/features/dictionary/components/dictionary-modal' @@ -8,7 +8,6 @@ function setLearnedWords(words) { window.metaAttributesCache.set('ol-learnedWords', words) window.dispatchEvent(new CustomEvent('learnedWords:doreset')) } - describe('', function () { beforeEach(function () { window.metaAttributesCache = window.metaAttributesCache || new Map() @@ -17,7 +16,6 @@ describe('', function () { afterEach(function () { window.metaAttributesCache = new Map() fetchMock.reset() - window.dispatchEvent(new CustomEvent('learnedWords:doreset')) }) it('list words', async function () { @@ -37,14 +35,12 @@ describe('', function () { fetchMock.post('/spelling/unlearn', 200) setLearnedWords(['Foo', 'bar']) renderWithEditorContext( {}} />) - screen.getByText('Foo') screen.getByText('bar') const [firstButton] = screen.getAllByRole('button', { name: 'Remove from dictionary', }) fireEvent.click(firstButton) - await fetchMock.flush() - await waitFor(() => expect(screen.queryByText('bar')).to.not.exist) + expect(screen.queryByText('bar')).to.not.exist screen.getByText('Foo') }) @@ -52,13 +48,12 @@ describe('', function () { fetchMock.post('/spelling/unlearn', 500) setLearnedWords(['foo']) renderWithEditorContext( {}} />) - screen.getByText('foo') const [firstButton] = screen.getAllByRole('button', { name: 'Remove from dictionary', }) fireEvent.click(firstButton) await fetchMock.flush() screen.getByText('Sorry, something went wrong') - screen.getByText('foo') + screen.getByText('Your custom dictionary is empty.') }) })