2017-08-11 14:54:26 -04:00
|
|
|
import mutations from '~/notes/stores/mutations';
|
2018-06-21 08:22:40 -04:00
|
|
|
import {
|
|
|
|
note,
|
|
|
|
discussionMock,
|
|
|
|
notesDataMock,
|
|
|
|
userDataMock,
|
|
|
|
noteableDataMock,
|
|
|
|
individualNote,
|
|
|
|
} from '../mock_data';
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-02-27 19:10:43 -05:00
|
|
|
describe('Notes Store mutations', () => {
|
2017-08-04 11:51:35 -04:00
|
|
|
describe('ADD_NEW_NOTE', () => {
|
2017-09-21 21:04:52 -04:00
|
|
|
let state;
|
|
|
|
let noteData;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-06-21 08:22:40 -04:00
|
|
|
state = { discussions: [] };
|
2017-09-21 21:04:52 -04:00
|
|
|
noteData = {
|
|
|
|
expanded: true,
|
|
|
|
id: note.discussion_id,
|
|
|
|
individual_note: true,
|
|
|
|
notes: [note],
|
|
|
|
reply_id: note.discussion_id,
|
|
|
|
};
|
2017-08-11 14:54:26 -04:00
|
|
|
mutations.ADD_NEW_NOTE(state, note);
|
2017-09-21 21:04:52 -04:00
|
|
|
});
|
2017-08-11 14:54:26 -04:00
|
|
|
|
2017-09-21 21:04:52 -04:00
|
|
|
it('should add a new note to an array of notes', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
expect(state).toEqual({
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [noteData],
|
2017-08-11 14:54:26 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions.length).toBe(1);
|
2017-09-21 21:04:52 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not add the same note to the notes array', () => {
|
|
|
|
mutations.ADD_NEW_NOTE(state, note);
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions.length).toBe(1);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('ADD_NEW_REPLY_TO_DISCUSSION', () => {
|
|
|
|
it('should add a reply to a specific discussion', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
const state = { discussions: [discussionMock] };
|
2017-08-11 14:54:26 -04:00
|
|
|
const newReply = Object.assign({}, note, { discussion_id: discussionMock.id });
|
|
|
|
mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].notes.length).toEqual(4);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('DELETE_NOTE', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
it('should delete a note ', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
const state = { discussions: [discussionMock] };
|
2017-08-11 14:54:26 -04:00
|
|
|
const toDelete = discussionMock.notes[0];
|
|
|
|
const lengthBefore = discussionMock.notes.length;
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
mutations.DELETE_NOTE(state, toDelete);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].notes.length).toEqual(lengthBefore - 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('EXPAND_DISCUSSION', () => {
|
|
|
|
it('should expand a collapsed discussion', () => {
|
|
|
|
const discussion = Object.assign({}, discussionMock, { expanded: false });
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
discussions: [discussion],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.EXPAND_DISCUSSION(state, { discussionId: discussion.id });
|
|
|
|
|
|
|
|
expect(state.discussions[0].expanded).toEqual(true);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-10 07:05:06 -04:00
|
|
|
describe('COLLAPSE_DISCUSSION', () => {
|
|
|
|
it('should collpase an expanded discussion', () => {
|
|
|
|
const discussion = Object.assign({}, discussionMock, { expanded: true });
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
discussions: [discussion],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.COLLAPSE_DISCUSSION(state, { discussionId: discussion.id });
|
|
|
|
|
|
|
|
expect(state.discussions[0].expanded).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-04 11:51:35 -04:00
|
|
|
describe('REMOVE_PLACEHOLDER_NOTES', () => {
|
|
|
|
it('should remove all placeholder notes in indivudal notes and discussion', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const placeholderNote = Object.assign({}, individualNote, { isPlaceholderNote: true });
|
2018-06-21 08:22:40 -04:00
|
|
|
const state = { discussions: [placeholderNote] };
|
2017-08-11 14:54:26 -04:00
|
|
|
mutations.REMOVE_PLACEHOLDER_NOTES(state);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions).toEqual([]);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_NOTES_DATA', () => {
|
|
|
|
it('should set an object with notesData', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
|
|
|
notesData: {},
|
|
|
|
};
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
mutations.SET_NOTES_DATA(state, notesDataMock);
|
|
|
|
expect(state.notesData).toEqual(notesDataMock);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-30 17:44:41 -05:00
|
|
|
describe('SET_NOTEABLE_DATA', () => {
|
2017-08-04 11:51:35 -04:00
|
|
|
it('should set the issue data', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
2017-11-30 17:44:41 -05:00
|
|
|
noteableData: {},
|
2017-08-11 14:54:26 -04:00
|
|
|
};
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-11-30 17:44:41 -05:00
|
|
|
mutations.SET_NOTEABLE_DATA(state, noteableDataMock);
|
|
|
|
expect(state.noteableData).toEqual(noteableDataMock);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_USER_DATA', () => {
|
|
|
|
it('should set the user data', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
|
|
|
userData: {},
|
|
|
|
};
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
mutations.SET_USER_DATA(state, userDataMock);
|
|
|
|
expect(state.userData).toEqual(userDataMock);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('SET_INITIAL_DISCUSSIONS', () => {
|
2017-08-04 11:51:35 -04:00
|
|
|
it('should set the initial notes received', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [],
|
2017-08-11 14:54:26 -04:00
|
|
|
};
|
2018-03-10 13:17:01 -05:00
|
|
|
const legacyNote = {
|
|
|
|
id: 2,
|
|
|
|
individual_note: true,
|
2018-06-21 08:22:40 -04:00
|
|
|
notes: [
|
|
|
|
{
|
|
|
|
note: '1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
note: '2',
|
|
|
|
},
|
|
|
|
],
|
2018-03-10 13:17:01 -05:00
|
|
|
};
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
mutations.SET_INITIAL_DISCUSSIONS(state, [note, legacyNote]);
|
|
|
|
expect(state.discussions[0].id).toEqual(note.id);
|
|
|
|
expect(state.discussions[1].notes[0].note).toBe(legacyNote.notes[0].note);
|
|
|
|
expect(state.discussions[2].notes[0].note).toBe(legacyNote.notes[1].note);
|
|
|
|
expect(state.discussions.length).toEqual(3);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_LAST_FETCHED_AT', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
it('should set timestamp', () => {
|
|
|
|
const state = {
|
|
|
|
lastFetchedAt: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_LAST_FETCHED_AT(state, 'timestamp');
|
|
|
|
expect(state.lastFetchedAt).toEqual('timestamp');
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_TARGET_NOTE_HASH', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
it('should set the note hash', () => {
|
|
|
|
const state = {
|
|
|
|
targetNoteHash: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_TARGET_NOTE_HASH(state, 'hash');
|
|
|
|
expect(state.targetNoteHash).toEqual('hash');
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('SHOW_PLACEHOLDER_NOTE', () => {
|
|
|
|
it('should set a placeholder note', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [],
|
2017-08-11 14:54:26 -04:00
|
|
|
};
|
|
|
|
mutations.SHOW_PLACEHOLDER_NOTE(state, note);
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].isPlaceholderNote).toEqual(true);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_AWARD', () => {
|
|
|
|
it('should add award if user has not reacted yet', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [note],
|
2017-08-11 14:54:26 -04:00
|
|
|
userData: userDataMock,
|
|
|
|
};
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
const data = {
|
|
|
|
note,
|
|
|
|
awardName: 'cartwheel',
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_AWARD(state, data);
|
2018-06-21 08:22:40 -04:00
|
|
|
const lastIndex = state.discussions[0].award_emoji.length - 1;
|
2017-08-11 14:54:26 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].award_emoji[lastIndex]).toEqual({
|
2017-08-11 14:54:26 -04:00
|
|
|
name: 'cartwheel',
|
|
|
|
user: { id: userDataMock.id, name: userDataMock.name, username: userDataMock.username },
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove award if user already reacted', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [note],
|
2017-08-11 14:54:26 -04:00
|
|
|
userData: {
|
|
|
|
id: 1,
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
note,
|
|
|
|
awardName: 'bath_tone3',
|
|
|
|
};
|
|
|
|
mutations.TOGGLE_AWARD(state, data);
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].award_emoji.length).toEqual(2);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_DISCUSSION', () => {
|
|
|
|
it('should open a closed discussion', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const discussion = Object.assign({}, discussionMock, { expanded: false });
|
|
|
|
|
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [discussion],
|
2017-08-11 14:54:26 -04:00
|
|
|
};
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
mutations.TOGGLE_DISCUSSION(state, { discussionId: discussion.id });
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].expanded).toEqual(true);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should close a opened discussion', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [discussionMock],
|
2017-08-11 14:54:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_DISCUSSION(state, { discussionId: discussionMock.id });
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].expanded).toEqual(false);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('UPDATE_NOTE', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
it('should update a note', () => {
|
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [individualNote],
|
2017-08-11 14:54:26 -04:00
|
|
|
};
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
const updated = Object.assign({}, individualNote.notes[0], { note: 'Foo' });
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
mutations.UPDATE_NOTE(state, updated);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(state.discussions[0].notes[0].note).toEqual('Foo');
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
2018-03-12 13:08:05 -04:00
|
|
|
|
|
|
|
describe('CLOSE_ISSUE', () => {
|
|
|
|
it('should set issue as closed', () => {
|
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [],
|
2018-03-12 13:08:05 -04:00
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.CLOSE_ISSUE(state);
|
|
|
|
expect(state.noteableData.state).toEqual('closed');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('REOPEN_ISSUE', () => {
|
|
|
|
it('should set issue as closed', () => {
|
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [],
|
2018-03-12 13:08:05 -04:00
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.REOPEN_ISSUE(state);
|
|
|
|
expect(state.noteableData.state).toEqual('reopened');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_STATE_BUTTON_LOADING', () => {
|
|
|
|
it('should set isToggleStateButtonLoading as true', () => {
|
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [],
|
2018-03-12 13:08:05 -04:00
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_STATE_BUTTON_LOADING(state, true);
|
|
|
|
expect(state.isToggleStateButtonLoading).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set isToggleStateButtonLoading as false', () => {
|
|
|
|
const state = {
|
2018-06-21 08:22:40 -04:00
|
|
|
discussions: [],
|
2018-03-12 13:08:05 -04:00
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: true,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_STATE_BUTTON_LOADING(state, false);
|
|
|
|
expect(state.isToggleStateButtonLoading).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2018-06-29 03:22:07 -04:00
|
|
|
|
|
|
|
describe('SET_NOTES_FETCHING_STATE', () => {
|
|
|
|
it('should set the given state', () => {
|
|
|
|
const state = {
|
|
|
|
isNotesFetched: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_NOTES_FETCHED_STATE(state, true);
|
|
|
|
expect(state.isNotesFetched).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|