Commit d2990167 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'vs/replace-vue-emit-with-single-arg-note' into 'master'

Replace Vue.$emit with single arg in notes

See merge request gitlab-org/gitlab!67777
parents 6c24fa0b a3665cff
...@@ -115,11 +115,11 @@ export default { ...@@ -115,11 +115,11 @@ export default {
renderGFM() { renderGFM() {
$(this.$refs['note-body']).renderGFM(); $(this.$refs['note-body']).renderGFM();
}, },
handleFormUpdate(note, parentElement, callback, resolveDiscussion) { handleFormUpdate(noteText, parentElement, callback, resolveDiscussion) {
this.$emit('handleFormUpdate', note, parentElement, callback, resolveDiscussion); this.$emit('handleFormUpdate', { noteText, parentElement, callback, resolveDiscussion });
}, },
formCancelHandler(shouldConfirm, isDirty) { formCancelHandler(shouldConfirm, isDirty) {
this.$emit('cancelForm', shouldConfirm, isDirty); this.$emit('cancelForm', { shouldConfirm, isDirty });
}, },
applySuggestion({ suggestionId, flashContainer, callback = () => {}, message }) { applySuggestion({ suggestionId, flashContainer, callback = () => {}, message }) {
const { discussion_id: discussionId, id: noteId } = this.note; const { discussion_id: discussionId, id: noteId } = this.note;
......
...@@ -263,7 +263,7 @@ export default { ...@@ -263,7 +263,7 @@ export default {
this.$refs.noteBody.resetAutoSave(); this.$refs.noteBody.resetAutoSave();
this.$emit('updateSuccess'); this.$emit('updateSuccess');
}, },
formUpdateHandler(noteText, parentElement, callback, resolveDiscussion) { formUpdateHandler({ noteText, callback, resolveDiscussion }) {
const position = { const position = {
...this.note.position, ...this.note.position,
}; };
...@@ -329,7 +329,7 @@ export default { ...@@ -329,7 +329,7 @@ export default {
} }
}); });
}, },
formCancelHandler(shouldConfirm, isDirty) { formCancelHandler({ shouldConfirm, isDirty }) {
if (shouldConfirm && isDirty) { if (shouldConfirm && isDirty) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
if (!window.confirm(__('Are you sure you want to cancel editing this comment?'))) return; if (!window.confirm(__('Are you sure you want to cancel editing this comment?'))) return;
......
...@@ -258,7 +258,11 @@ describe('issue_note', () => { ...@@ -258,7 +258,11 @@ describe('issue_note', () => {
}, },
}); });
noteBodyComponent.vm.$emit('handleFormUpdate', noteBody, null, () => {}); noteBodyComponent.vm.$emit('handleFormUpdate', {
noteText: noteBody,
parentElement: null,
callback: () => {},
});
await waitForPromises(); await waitForPromises();
expect(alertSpy).not.toHaveBeenCalled(); expect(alertSpy).not.toHaveBeenCalled();
...@@ -287,14 +291,18 @@ describe('issue_note', () => { ...@@ -287,14 +291,18 @@ describe('issue_note', () => {
const noteBody = wrapper.findComponent(NoteBody); const noteBody = wrapper.findComponent(NoteBody);
noteBody.vm.resetAutoSave = () => {}; noteBody.vm.resetAutoSave = () => {};
noteBody.vm.$emit('handleFormUpdate', updatedText, null, () => {}); noteBody.vm.$emit('handleFormUpdate', {
noteText: updatedText,
parentElement: null,
callback: () => {},
});
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
let noteBodyProps = noteBody.props(); let noteBodyProps = noteBody.props();
expect(noteBodyProps.note.note_html).toBe(`<p>${updatedText}</p>\n`); expect(noteBodyProps.note.note_html).toBe(`<p>${updatedText}</p>\n`);
noteBody.vm.$emit('cancelForm'); noteBody.vm.$emit('cancelForm', {});
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
noteBodyProps = noteBody.props(); noteBodyProps = noteBody.props();
...@@ -305,7 +313,12 @@ describe('issue_note', () => { ...@@ -305,7 +313,12 @@ describe('issue_note', () => {
describe('formUpdateHandler', () => { describe('formUpdateHandler', () => {
const updateNote = jest.fn(); const updateNote = jest.fn();
const params = ['', null, jest.fn(), '']; const params = {
noteText: '',
parentElement: null,
callback: jest.fn(),
resolveDiscussion: false,
};
const updateActions = () => { const updateActions = () => {
store.hotUpdate({ store.hotUpdate({
...@@ -325,14 +338,14 @@ describe('issue_note', () => { ...@@ -325,14 +338,14 @@ describe('issue_note', () => {
it('responds to handleFormUpdate', () => { it('responds to handleFormUpdate', () => {
createWrapper(); createWrapper();
updateActions(); updateActions();
wrapper.findComponent(NoteBody).vm.$emit('handleFormUpdate', ...params); wrapper.findComponent(NoteBody).vm.$emit('handleFormUpdate', params);
expect(wrapper.emitted('handleUpdateNote')).toBeTruthy(); expect(wrapper.emitted('handleUpdateNote')).toBeTruthy();
}); });
it('does not stringify empty position', () => { it('does not stringify empty position', () => {
createWrapper(); createWrapper();
updateActions(); updateActions();
wrapper.findComponent(NoteBody).vm.$emit('handleFormUpdate', ...params); wrapper.findComponent(NoteBody).vm.$emit('handleFormUpdate', params);
expect(updateNote.mock.calls[0][1].note.note.position).toBeUndefined(); expect(updateNote.mock.calls[0][1].note.note.position).toBeUndefined();
}); });
...@@ -341,7 +354,7 @@ describe('issue_note', () => { ...@@ -341,7 +354,7 @@ describe('issue_note', () => {
const expectation = JSON.stringify(position); const expectation = JSON.stringify(position);
createWrapper({ note: { ...note, position } }); createWrapper({ note: { ...note, position } });
updateActions(); updateActions();
wrapper.findComponent(NoteBody).vm.$emit('handleFormUpdate', ...params); wrapper.findComponent(NoteBody).vm.$emit('handleFormUpdate', params);
expect(updateNote.mock.calls[0][1].note.note.position).toBe(expectation); expect(updateNote.mock.calls[0][1].note.note.position).toBe(expectation);
}); });
}); });
......
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