Commit e0919ad3 authored by Savas Vedova's avatar Savas Vedova

Fix adding or updating vulnerability history comments

Changelog: fixed
parent 6e1e1bf5
<script>
import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import HistoryComment from './history_comment.vue';
export default {
......@@ -33,14 +34,14 @@ export default {
},
},
methods: {
addComment(comment) {
this.notes.push(comment);
addComment({ response }) {
this.notes.push(convertObjectPropsToCamelCase(response));
},
updateComment({ response, comment }) {
const index = this.notes.indexOf(comment);
if (index > -1) {
this.notes.splice(index, 1, { ...comment, ...response });
this.notes.splice(index, 1, { ...comment, ...convertObjectPropsToCamelCase(response) });
}
},
removeComment(comment) {
......
import { shallowMount } from '@vue/test-utils';
import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue';
import HistoryEntry from 'ee/vulnerabilities/components/history_entry.vue';
import { convertObjectPropsToSnakeCase } from '~/lib/utils/common_utils';
describe('History Entry', () => {
let wrapper;
......@@ -81,23 +82,27 @@ describe('History Entry', () => {
expect(commentAt(1).props('comment')).toEqual(commentNoteClone);
});
it('adds a new comment correctly', () => {
it('adds a new comment correctly', async () => {
createWrapper(systemNote);
newComment().vm.$emit('onCommentAdded', commentNote);
return wrapper.vm.$nextTick().then(() => {
expect(newComment().exists()).toBe(false);
expect(existingComments()).toHaveLength(1);
expect(commentAt(0).props('comment')).toEqual(commentNote);
newComment().vm.$emit('onCommentAdded', {
response: convertObjectPropsToSnakeCase(commentNote),
});
await wrapper.vm.$nextTick();
expect(newComment().exists()).toBe(false);
expect(existingComments()).toHaveLength(1);
expect(commentAt(0).props('comment')).toEqual(commentNote);
});
it('updates an existing comment correctly', async () => {
const response = { note: 'new note' };
createWrapper(systemNote, commentNote);
await commentAt(0).vm.$emit('onCommentUpdated', { response, comment: commentNote });
commentAt(0).vm.$emit('onCommentUpdated', { response, comment: commentNote });
await wrapper.vm.$nextTick();
expect(commentAt(0).props('comment').note).toBe(response.note);
expect(commentAt(0).props('comment')).toEqual({ ...commentNote, note: response.note });
});
it('deletes an existing comment correctly', async () => {
......
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