Commit d0fe524e authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'vs/change-vue-emit-to-single-arg-in-history-comment' into 'master'

Change vue emit to single arg in history comment

See merge request gitlab-org/gitlab!66998
parents 2a83584c f473fe3e
...@@ -105,7 +105,7 @@ export default { ...@@ -105,7 +105,7 @@ export default {
axios({ method, url, data }) axios({ method, url, data })
.then(({ data: responseData }) => { .then(({ data: responseData }) => {
this.isEditingComment = false; this.isEditingComment = false;
this.$emit(emitName, responseData, this.comment); this.$emit(emitName, { response: responseData, comment: this.comment });
}) })
.catch(() => { .catch(() => {
createFlash({ createFlash({
......
...@@ -36,11 +36,11 @@ export default { ...@@ -36,11 +36,11 @@ export default {
addComment(comment) { addComment(comment) {
this.notes.push(comment); this.notes.push(comment);
}, },
updateComment(data, comment) { updateComment({ response, comment }) {
const index = this.notes.indexOf(comment); const index = this.notes.indexOf(comment);
if (index > -1) { if (index > -1) {
this.notes.splice(index, 1, { ...comment, ...data }); this.notes.splice(index, 1, { ...comment, ...response });
} }
}, },
removeComment(comment) { removeComment(comment) {
......
...@@ -115,8 +115,9 @@ describe('History Comment', () => { ...@@ -115,8 +115,9 @@ describe('History Comment', () => {
}) })
.then(() => { .then(() => {
expect(mockAxios.history.post).toHaveLength(1); expect(mockAxios.history.post).toHaveLength(1);
expect(wrapper.emitted().onCommentAdded).toBeTruthy(); expect(wrapper.emitted().onCommentAdded[0]).toEqual([
expect(wrapper.emitted().onCommentAdded[0][0]).toEqual(comment); { response: comment, comment: undefined },
]);
}); });
}); });
...@@ -239,9 +240,9 @@ describe('History Comment', () => { ...@@ -239,9 +240,9 @@ describe('History Comment', () => {
}) })
.then(() => { .then(() => {
expect(mockAxios.history.put).toHaveLength(1); expect(mockAxios.history.put).toHaveLength(1);
expect(wrapper.emitted().onCommentUpdated).toBeTruthy(); expect(wrapper.emitted().onCommentUpdated[0]).toEqual([
expect(wrapper.emitted().onCommentUpdated[0][0]).toEqual(responseData); { response: responseData, comment },
expect(wrapper.emitted().onCommentUpdated[0][1]).toEqual(comment); ]);
}); });
}); });
......
...@@ -39,9 +39,9 @@ describe('History Entry', () => { ...@@ -39,9 +39,9 @@ describe('History Entry', () => {
}); });
}; };
const eventItem = () => wrapper.find(EventItem); const eventItem = () => wrapper.findComponent(EventItem);
const newComment = () => wrapper.find({ ref: 'newComment' }); const newComment = () => wrapper.findComponent({ ref: 'newComment' });
const existingComments = () => wrapper.findAll({ ref: 'existingComment' }); const existingComments = () => wrapper.findAllComponents({ ref: 'existingComment' });
const commentAt = (index) => existingComments().at(index); const commentAt = (index) => existingComments().at(index);
afterEach(() => wrapper.destroy()); afterEach(() => wrapper.destroy());
...@@ -92,23 +92,19 @@ describe('History Entry', () => { ...@@ -92,23 +92,19 @@ describe('History Entry', () => {
}); });
}); });
it('updates an existing comment correctly', () => { it('updates an existing comment correctly', async () => {
const note = 'new note'; const response = { note: 'new note' };
createWrapper(systemNote, commentNote); createWrapper(systemNote, commentNote);
commentAt(0).vm.$emit('onCommentUpdated', { note }, commentNote); await commentAt(0).vm.$emit('onCommentUpdated', { response, comment: commentNote });
return wrapper.vm.$nextTick().then(() => { expect(commentAt(0).props('comment').note).toBe(response.note);
expect(commentAt(0).props('comment').note).toBe(note);
});
}); });
it('deletes an existing comment correctly', () => { it('deletes an existing comment correctly', async () => {
createWrapper(systemNote, commentNote); createWrapper(systemNote, commentNote);
commentAt(0).vm.$emit('onCommentDeleted', commentNote); await commentAt(0).vm.$emit('onCommentDeleted', commentNote);
return wrapper.vm.$nextTick().then(() => {
expect(newComment().exists()).toBe(true); expect(newComment().exists()).toBe(true);
expect(existingComments()).toHaveLength(0); expect(existingComments()).toHaveLength(0);
}); });
});
}); });
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