From d72a61b41d1aaf6b0ed9041b32fa411e8907d4f8 Mon Sep 17 00:00:00 2001 From: Heinrich Lee Yu Date: Wed, 6 Mar 2019 14:39:53 +0800 Subject: [PATCH] Handle transformed notes from polling response Transforms notes when the note was transformed in some other tab --- app/assets/javascripts/notes/stores/mutations.js | 4 ++++ spec/javascripts/notes/stores/mutation_spec.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js index ae6f8b7790a..fa44ef2d057 100644 --- a/app/assets/javascripts/notes/stores/mutations.js +++ b/app/assets/javascripts/notes/stores/mutations.js @@ -193,6 +193,10 @@ export default { const noteObj = utils.findNoteObjectById(state.discussions, note.discussion_id); if (noteObj.individual_note) { + if (note.type === constants.DISCUSSION_NOTE) { + noteObj.individual_note = false; + } + noteObj.notes.splice(0, 1, note); } else { const comment = utils.findNoteObjectById(noteObj.notes, note.id); diff --git a/spec/javascripts/notes/stores/mutation_spec.js b/spec/javascripts/notes/stores/mutation_spec.js index aa08bf59a7f..4a640d589fb 100644 --- a/spec/javascripts/notes/stores/mutation_spec.js +++ b/spec/javascripts/notes/stores/mutation_spec.js @@ -1,5 +1,6 @@ import Vue from 'vue'; import mutations from '~/notes/stores/mutations'; +import { DISCUSSION_NOTE } from '~/notes/constants'; import { note, discussionMock, @@ -326,6 +327,18 @@ describe('Notes Store mutations', () => { expect(state.discussions[0].notes[0].note).toEqual('Foo'); }); + + it('transforms an individual note to discussion', () => { + const state = { + discussions: [individualNote], + }; + + const transformedNote = { ...individualNote.notes[0], type: DISCUSSION_NOTE }; + + mutations.UPDATE_NOTE(state, transformedNote); + + expect(state.discussions[0].individual_note).toEqual(false); + }); }); describe('CLOSE_ISSUE', () => {