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 { ...@@ -273,6 +273,13 @@ export default {
this.toggleIssueState(); this.toggleIssueState();
} }
}, },
handleEnter() {
if (this.hasDrafts) {
this.handleSaveDraft();
} else {
this.handleSave();
}
},
toggleIssueState() { toggleIssueState() {
if (this.isIssue) { if (this.isIssue) {
// We want to invoke the close/reopen logic in the issue header // We want to invoke the close/reopen logic in the issue header
...@@ -395,8 +402,8 @@ export default { ...@@ -395,8 +402,8 @@ export default {
:aria-label="$options.i18n.comment" :aria-label="$options.i18n.comment"
:placeholder="$options.i18n.bodyPlaceholder" :placeholder="$options.i18n.bodyPlaceholder"
@keydown.up="editCurrentUserLastNote()" @keydown.up="editCurrentUserLastNote()"
@keydown.meta.enter="handleSave()" @keydown.meta.enter="handleEnter()"
@keydown.ctrl.enter="handleSave()" @keydown.ctrl.enter="handleEnter()"
></textarea> ></textarea>
</template> </template>
</markdown-field> </markdown-field>
......
...@@ -328,20 +328,45 @@ describe('issue_comment_form component', () => { ...@@ -328,20 +328,45 @@ describe('issue_comment_form component', () => {
mountComponent({ mountFunction: mount }); mountComponent({ mountFunction: mount });
}); });
it('should save note when cmd+enter is pressed', () => { describe('when no draft exists', () => {
jest.spyOn(wrapper.vm, 'handleSave'); 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', () => { describe('when a draft exists', () => {
jest.spyOn(wrapper.vm, 'handleSave'); 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