mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
Fixed a bug where escape would delete all typed content (#30452)
This commit is contained in:
parent
3af8d50bbe
commit
e2a7240e34
2 changed files with 33 additions and 2 deletions
|
|
@ -14,7 +14,7 @@ import type Textbox from 'components/textbox/textbox';
|
|||
|
||||
import mergeObjects from 'packages/mattermost-redux/test/merge_objects';
|
||||
import {renderWithContext, userEvent, screen} from 'tests/react_testing_utils';
|
||||
import {Locations, StoragePrefixes} from 'utils/constants';
|
||||
import Constants, {Locations, StoragePrefixes} from 'utils/constants';
|
||||
import {TestHelper} from 'utils/test_helper';
|
||||
|
||||
import type {PostDraft} from 'types/store/draft';
|
||||
|
|
@ -202,6 +202,37 @@ describe('components/avanced_text_editor/advanced_text_editor', () => {
|
|||
const textbox = screen.getByTestId('post_textbox');
|
||||
userEvent.type(textbox, 'something{esc}');
|
||||
expect(textbox).not.toHaveFocus();
|
||||
expect(mockedUpdateDraft).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ESC should blur the input and reset draft when in editing mode', () => {
|
||||
jest.useFakeTimers();
|
||||
const props = {
|
||||
...baseProps,
|
||||
isInEditMode: true,
|
||||
};
|
||||
renderWithContext(
|
||||
<AdvancedTextEditor
|
||||
{...props}
|
||||
/>,
|
||||
mergeObjects(initialState, {
|
||||
entities: {
|
||||
roles: {
|
||||
roles: {
|
||||
user_roles: {permissions: [Permissions.CREATE_POST]},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const textbox = screen.getByTestId('edit_textbox');
|
||||
userEvent.type(textbox, 'something{esc}');
|
||||
expect(textbox).not.toHaveFocus();
|
||||
|
||||
// save is called with a short delayed after pressing escape key
|
||||
jest.advanceTimersByTime(Constants.SAVE_DRAFT_TIMEOUT + 50);
|
||||
expect(mockedRemoveDraft).toHaveBeenCalled();
|
||||
expect(mockedUpdateDraft).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -173,9 +173,9 @@ const useKeyHandler = (
|
|||
}
|
||||
|
||||
if (Keyboard.isKeyPressed(e, KeyCodes.ESCAPE)) {
|
||||
onCancel?.();
|
||||
textboxRef.current?.blur();
|
||||
if (isInEditMode) {
|
||||
onCancel?.();
|
||||
dispatch(unsetEditingPost());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue