diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-08-11 19:54:26 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-08-11 19:54:58 +0100 |
commit | cbddad5a2d22767d2dc7d7214f09e7b3ab8bf322 (patch) | |
tree | ac5273264188ae65ca3cd4958a7674886abb2f3c /spec/javascripts/notes/stores | |
parent | cedee0124020120f4dc74a5548038df715fb1213 (diff) | |
download | gitlab-ce-cbddad5a2d22767d2dc7d7214f09e7b3ab8bf322.tar.gz |
Adds tests for mutations and getters
Diffstat (limited to 'spec/javascripts/notes/stores')
-rw-r--r-- | spec/javascripts/notes/stores/getters_spec.js | 54 | ||||
-rw-r--r-- | spec/javascripts/notes/stores/mutation_spec.js | 136 |
2 files changed, 143 insertions, 47 deletions
diff --git a/spec/javascripts/notes/stores/getters_spec.js b/spec/javascripts/notes/stores/getters_spec.js index ad8fc97362a..48ee1bf9a52 100644 --- a/spec/javascripts/notes/stores/getters_spec.js +++ b/spec/javascripts/notes/stores/getters_spec.js @@ -1,70 +1,58 @@ -import { getters } from '~/notes/stores/getters'; +import * as getters from '~/notes/stores/getters'; +import { notesDataMock, userDataMock, issueDataMock, individualNote } from '../mock_data'; describe('Getters Notes Store', () => { - + let state; + beforeEach(() => { + state = { + notes: [individualNote], + targetNoteHash: 'hash', + lastFetchedAt: 'timestamp', + + notesData: notesDataMock, + userData: userDataMock, + issueData: issueDataMock, + }; + }); describe('notes', () => { it('should return all notes in the store', () => { - + expect(getters.notes(state)).toEqual([individualNote]); }); }); describe('targetNoteHash', () => { it('should return `targetNoteHash`', () => { - + expect(getters.targetNoteHash(state)).toEqual('hash'); }); }); describe('getNotesData', () => { it('should return all data in `notesData`', () => { - - }); - }); - - describe('getNotesDataByProp', () => { - it('should return the given prop', () => { - + expect(getters.getNotesData(state)).toEqual(notesDataMock); }); }); describe('getIssueData', () => { it('should return all data in `issueData`', () => { - - }); - }); - - describe('getIssueDataByProp', () => { - it('should return the given prop', () => { - + expect(getters.getIssueData(state)).toEqual(issueDataMock); }); }); describe('getUserData', () => { it('should return all data in `userData`', () => { - - }); - }); - - describe('getUserDataByProp', () => { - it('should return the given prop', () => { - + expect(getters.getUserData(state)).toEqual(userDataMock); }); }); describe('notesById', () => { it('should return the note for the given id', () => { - + expect(getters.notesById(state)).toEqual({ 1390: individualNote.notes[0] }); }); }); describe('getCurrentUserLastNote', () => { it('should return the last note of the current user', () => { - - }); - }); - - describe('getDiscussionLastNote', () => { - it('should return the last discussion note of the current user', () => { - + expect(getters.getCurrentUserLastNote(state)).toEqual(individualNote.notes[0]); }); }); }); diff --git a/spec/javascripts/notes/stores/mutation_spec.js b/spec/javascripts/notes/stores/mutation_spec.js index 0fdba840f2e..a38f29c1e39 100644 --- a/spec/javascripts/notes/stores/mutation_spec.js +++ b/spec/javascripts/notes/stores/mutation_spec.js @@ -1,99 +1,207 @@ -import { mutations } from '~/notes/stores/mutations'; +import mutations from '~/notes/stores/mutations'; +import { note, discussionMock, notesDataMock, userDataMock, issueDataMock, individualNote } from '../mock_data'; describe('Mutation Notes Store', () => { describe('ADD_NEW_NOTE', () => { it('should add a new note to an array of notes', () => { - + const state = { notes: [] }; + mutations.ADD_NEW_NOTE(state, note); + + expect(state).toEqual({ + notes: [{ + expanded: true, + id: note.discussion_id, + individual_note: true, + notes: [note], + reply_id: note.discussion_id, + }], + }); }); }); describe('ADD_NEW_REPLY_TO_DISCUSSION', () => { it('should add a reply to a specific discussion', () => { + const state = { notes: [discussionMock] }; + const newReply = Object.assign({}, note, { discussion_id: discussionMock.id }); + mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply); + expect(state.notes[0].notes.length).toEqual(4); }); }); describe('DELETE_NOTE', () => { - it('should delete an indivudal note', () => { - - }); + it('should delete a note ', () => { + const state = { notes: [discussionMock] }; + const toDelete = discussionMock.notes[0]; + const lengthBefore = discussionMock.notes.length; - it('should delete a note from a discussion', () => { + mutations.DELETE_NOTE(state, toDelete); + expect(state.notes[0].notes.length).toEqual(lengthBefore - 1); }); }); describe('REMOVE_PLACEHOLDER_NOTES', () => { it('should remove all placeholder notes in indivudal notes and discussion', () => { + const placeholderNote = Object.assign({}, individualNote, { isPlaceholderNote: true }); + const state = { notes: [placeholderNote] }; + mutations.REMOVE_PLACEHOLDER_NOTES(state); + expect(state.notes).toEqual([]); }); }); describe('SET_NOTES_DATA', () => { it('should set an object with notesData', () => { + const state = { + notesData: {}, + }; + mutations.SET_NOTES_DATA(state, notesDataMock); + expect(state.notesData).toEqual(notesDataMock); }); }); describe('SET_ISSUE_DATA', () => { it('should set the issue data', () => { + const state = { + issueData: {}, + }; + mutations.SET_ISSUE_DATA(state, issueDataMock); + expect(state.issueData).toEqual(issueDataMock); }); }); describe('SET_USER_DATA', () => { it('should set the user data', () => { + const state = { + userData: {}, + }; + mutations.SET_USER_DATA(state, userDataMock); + expect(state.userData).toEqual(userDataMock); }); }); - describe('SET_INITAL_NOTES', () => { + describe('SET_INITIAL_NOTES', () => { it('should set the initial notes received', () => { + const state = { + notes: [], + }; + mutations.SET_INITIAL_NOTES(state, [note]); + expect(state.notes).toEqual([note]); }); }); describe('SET_LAST_FETCHED_AT', () => { - it('should set timestamp', () => {}); + it('should set timestamp', () => { + const state = { + lastFetchedAt: [], + }; + + mutations.SET_LAST_FETCHED_AT(state, 'timestamp'); + expect(state.lastFetchedAt).toEqual('timestamp'); + }); }); describe('SET_TARGET_NOTE_HASH', () => { - it('should set the note hash', () => {}); + it('should set the note hash', () => { + const state = { + targetNoteHash: [], + }; + + mutations.SET_TARGET_NOTE_HASH(state, 'hash'); + expect(state.targetNoteHash).toEqual('hash'); + }); }); describe('SHOW_PLACEHOLDER_NOTE', () => { it('should set a placeholder note', () => { - + const state = { + notes: [], + }; + mutations.SHOW_PLACEHOLDER_NOTE(state, note); + expect(state.notes[0].isPlaceholderNote).toEqual(true); }); }); describe('TOGGLE_AWARD', () => { it('should add award if user has not reacted yet', () => { + const state = { + notes: [note], + userData: userDataMock, + }; + const data = { + note, + awardName: 'cartwheel', + }; + + mutations.TOGGLE_AWARD(state, data); + const lastIndex = state.notes[0].award_emoji.length - 1; + + expect(state.notes[0].award_emoji[lastIndex]).toEqual({ + name: 'cartwheel', + user: { id: userDataMock.id, name: userDataMock.name, username: userDataMock.username }, + }); }); it('should remove award if user already reacted', () => { - + const state = { + notes: [note], + userData: { + id: 1, + name: 'Administrator', + username: 'root', + }, + }; + + const data = { + note, + awardName: 'bath_tone3', + }; + mutations.TOGGLE_AWARD(state, data); + expect(state.notes[0].award_emoji.length).toEqual(2); }); }); describe('TOGGLE_DISCUSSION', () => { it('should open a closed discussion', () => { + const discussion = Object.assign({}, discussionMock, { expanded: false }); + + const state = { + notes: [discussion], + }; + mutations.TOGGLE_DISCUSSION(state, { discussionId: discussion.id }); + + expect(state.notes[0].expanded).toEqual(true); }); it('should close a opened discussion', () => { + const state = { + notes: [discussionMock], + }; + + mutations.TOGGLE_DISCUSSION(state, { discussionId: discussionMock.id }); + expect(state.notes[0].expanded).toEqual(false); }); }); describe('UPDATE_NOTE', () => { - it('should update an individual note', () => { + it('should update a note', () => { + const state = { + notes: [individualNote], + }; - }); + const updated = Object.assign({}, individualNote.notes[0], { note: 'Foo' }); - it('should update a note in a discussion', () => { + mutations.UPDATE_NOTE(state, updated); + expect(state.notes[0].notes[0].note).toEqual('Foo'); }); }); }); |