Commit f0071603 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Miguel Rincon

Handle enter action of MR comment form

parent 546267fd
......@@ -273,6 +273,13 @@ export default {
this.toggleIssueState();
}
},
handleEnter() {
if (this.hasDrafts) {
this.handleSaveDraft();
} else {
this.handleSave();
}
},
toggleIssueState() {
if (this.isIssue) {
// We want to invoke the close/reopen logic in the issue header
......@@ -395,8 +402,8 @@ export default {
:aria-label="$options.i18n.comment"
:placeholder="$options.i18n.bodyPlaceholder"
@keydown.up="editCurrentUserLastNote()"
@keydown.meta.enter="handleSave()"
@keydown.ctrl.enter="handleSave()"
@keydown.meta.enter="handleEnter()"
@keydown.ctrl.enter="handleEnter()"
></textarea>
</template>
</markdown-field>
......
......@@ -328,20 +328,45 @@ describe('issue_comment_form component', () => {
mountComponent({ mountFunction: mount });
});
it('should save note when cmd+enter is pressed', () => {
jest.spyOn(wrapper.vm, 'handleSave');
describe('when no draft exists', () => {
it('should save note when cmd+enter is pressed', () => {
jest.spyOn(wrapper.vm, 'handleSave');
findTextArea().trigger('keydown.enter', { metaKey: true });
findTextArea().trigger('keydown.enter', { metaKey: true });
expect(wrapper.vm.handleSave).toHaveBeenCalled();
expect(wrapper.vm.handleSave).toHaveBeenCalledWith();
});
it('should save note when ctrl+enter is pressed', () => {
jest.spyOn(wrapper.vm, 'handleSave');
findTextArea().trigger('keydown.enter', { ctrlKey: true });
expect(wrapper.vm.handleSave).toHaveBeenCalledWith();
});
});
it('should save note when ctrl+enter is pressed', () => {
jest.spyOn(wrapper.vm, 'handleSave');
describe('when a draft exists', () => {
beforeEach(() => {
store.registerModule('batchComments', batchComments());
store.state.batchComments.drafts = [{ note: 'A' }];
});
it('should save note draft when cmd+enter is pressed', () => {
jest.spyOn(wrapper.vm, 'handleSaveDraft');
findTextArea().trigger('keydown.enter', { metaKey: true });
expect(wrapper.vm.handleSaveDraft).toHaveBeenCalledWith();
});
it('should save note draft when ctrl+enter is pressed', () => {
jest.spyOn(wrapper.vm, 'handleSaveDraft');
findTextArea().trigger('keydown.enter', { ctrlKey: true });
findTextArea().trigger('keydown.enter', { ctrlKey: true });
expect(wrapper.vm.handleSave).toHaveBeenCalled();
expect(wrapper.vm.handleSaveDraft).toHaveBeenCalledWith();
});
});
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment