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