From 95bb5ca4e4cfd1bdc4ecb69c44416cf037bba24d Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 16 Jan 2023 11:35:01 +0000 Subject: [PATCH] Merge pull request #11002 from overleaf/msm-fix-email-suggestion [web] Fix clearing suggestions in email input GitOrigin-RevId: c821114e2112bf066f4ee5f01304321db983bc4e --- .../features/settings/components/emails/add-email/input.tsx | 4 +++- .../settings/components/emails/add-email-input.test.tsx | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx b/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx index d1852c4cec..3eecbf71f6 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx @@ -148,7 +148,9 @@ function Input({ onChange, handleAddNewEmail }: InputProps) { ) useEffect(() => { - if (suggestion && inputValue && !suggestion.startsWith(inputValue)) { + if (!inputValue) { + setSuggestion(null) + } else if (suggestion && !suggestion.startsWith(inputValue)) { setSuggestion(null) } }, [suggestion, inputValue]) diff --git a/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx b/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx index c9f1ec18df..491a940c6c 100644 --- a/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx +++ b/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx @@ -146,11 +146,11 @@ describe('', function () { ).to.equal(true) }) - it('should clear the suggestion when the potential domain match is completely deleted', function () { + it('should clear the suggestion when the potential domain match is completely deleted', async function () { + await screen.findByText('user@domain.edu') fireEvent.change(screen.getByRole('textbox'), { - target: { value: 'user@' }, + target: { value: '' }, }) - expect(onChangeStub.calledWith('user@')).to.equal(true) expect(screen.queryByText('user@domain.edu')).to.be.null })