Commit f2a5454d authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'svedova-fix-history-entry-bug' into 'master'

Fix adding or updating vulnerability history comments

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