From f22f75b752f741969484f4e2a49a7087b57b2df6 Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Fri, 22 Sep 2017 04:04:52 +0300 Subject: Fix rendering double note issue. --- spec/javascripts/notes/stores/actions_spec.js | 1 - spec/javascripts/notes/stores/mutation_spec.js | 30 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'spec/javascripts/notes') diff --git a/spec/javascripts/notes/stores/actions_spec.js b/spec/javascripts/notes/stores/actions_spec.js index 72d362acb2f..2b2219dcf0c 100644 --- a/spec/javascripts/notes/stores/actions_spec.js +++ b/spec/javascripts/notes/stores/actions_spec.js @@ -1,4 +1,3 @@ - import * as actions from '~/notes/stores/actions'; import testAction from './helpers'; import { discussionMock, notesDataMock, userDataMock, issueDataMock, individualNote } from '../mock_data'; diff --git a/spec/javascripts/notes/stores/mutation_spec.js b/spec/javascripts/notes/stores/mutation_spec.js index a38f29c1e39..1e22e03e178 100644 --- a/spec/javascripts/notes/stores/mutation_spec.js +++ b/spec/javascripts/notes/stores/mutation_spec.js @@ -3,19 +3,31 @@ import { note, discussionMock, notesDataMock, userDataMock, issueDataMock, indiv describe('Mutation Notes Store', () => { describe('ADD_NEW_NOTE', () => { - it('should add a new note to an array of notes', () => { - const state = { notes: [] }; + let state; + let noteData; + + beforeEach(() => { + state = { notes: [] }; + noteData = { + expanded: true, + id: note.discussion_id, + individual_note: true, + notes: [note], + reply_id: note.discussion_id, + }; mutations.ADD_NEW_NOTE(state, note); + }); + it('should add a new note to an array of notes', () => { expect(state).toEqual({ - notes: [{ - expanded: true, - id: note.discussion_id, - individual_note: true, - notes: [note], - reply_id: note.discussion_id, - }], + notes: [noteData], }); + expect(state.notes.length).toBe(1); + }); + + it('should not add the same note to the notes array', () => { + mutations.ADD_NEW_NOTE(state, note); + expect(state.notes.length).toBe(1); }); }); -- cgit v1.2.1