Skip to content
Snippets Groups Projects
Commit 29c732ee authored by Jose Ivan Vargas Lopez's avatar Jose Ivan Vargas Lopez
Browse files

Merge branch '362947-fix-multiple-confirms-showing-on-diff-notes-cancel' into 'master'

Fix multiple modals showing when canceling comment in diff

See merge request gitlab-org/gitlab!88077
parents ace13735 7367d6ab
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,6 +3,7 @@ import { mapState, mapGetters, mapActions } from 'vuex';
import { s__, __ } from '~/locale';
import diffLineNoteFormMixin from '~/notes/mixins/diff_line_note_form';
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
import { ignoreWhilePending } from '~/lib/utils/ignore_while_pending';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import MultilineCommentForm from '~/notes/components/multiline_comment_form.vue';
import { commentLineOptions, formatLineRange } from '~/notes/components/multiline_comment_utils';
Loading
Loading
@@ -175,7 +176,10 @@ export default {
'saveDiffDiscussion',
'setSuggestPopoverDismissed',
]),
async handleCancelCommentForm(shouldConfirm, isDirty) {
handleCancelCommentForm: ignoreWhilePending(async function handleCancelCommentForm(
shouldConfirm,
isDirty,
) {
if (shouldConfirm && isDirty) {
const msg = s__('Notes|Are you sure you want to cancel creating this comment?');
 
Loading
Loading
@@ -195,7 +199,7 @@ export default {
this.$nextTick(() => {
this.resetAutoSave();
});
},
}),
handleSaveNote(note) {
return this.saveDiffDiscussion({ note, formData: this.formData }).then(() =>
this.handleCancelCommentForm(),
Loading
Loading
Loading
Loading
@@ -64,6 +64,16 @@ describe('DiffLineNoteForm', () => {
expect(confirmAction).toHaveBeenCalled();
});
 
it('should only ask for confirmation once', () => {
// Never resolve so we can test what happens when triggered while "confirmAction" is loading
confirmAction.mockImplementation(() => new Promise(() => {}));
findNoteForm().vm.$emit('cancelForm', true, true);
findNoteForm().vm.$emit('cancelForm', true, true);
expect(confirmAction).toHaveBeenCalledTimes(1);
});
it('should not ask for confirmation when one of the params false', () => {
confirmAction.mockResolvedValueOnce(false);
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment