2018-11-20 20:47:30 +05:30
|
|
|
import Vue from 'vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import mutations from '~/notes/stores/mutations';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { DISCUSSION_NOTE, ASC, DESC } from '~/notes/constants';
|
2018-11-08 19:23:39 +05:30
|
|
|
import {
|
|
|
|
note,
|
|
|
|
discussionMock,
|
|
|
|
notesDataMock,
|
|
|
|
userDataMock,
|
|
|
|
noteableDataMock,
|
|
|
|
individualNote,
|
2020-04-08 14:13:33 +05:30
|
|
|
notesWithDescriptionChanges,
|
2018-11-08 19:23:39 +05:30
|
|
|
} from '../mock_data';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
const RESOLVED_NOTE = { resolvable: true, resolved: true };
|
|
|
|
const UNRESOLVED_NOTE = { resolvable: true, resolved: false };
|
|
|
|
const SYSTEM_NOTE = { resolvable: false, resolved: false };
|
|
|
|
const WEIRD_NOTE = { resolvable: false, resolved: true };
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('Notes Store mutations', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('ADD_NEW_NOTE', () => {
|
|
|
|
let state;
|
|
|
|
let noteData;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-04-22 19:07:51 +05:30
|
|
|
state = {
|
|
|
|
discussions: [],
|
|
|
|
discussionSortOrder: ASC,
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
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', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(state).toEqual(expect.objectContaining({ discussions: [noteData] }));
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions.length).toBe(1);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should not add the same note to the notes array', () => {
|
|
|
|
mutations.ADD_NEW_NOTE(state, note);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions.length).toBe(1);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('ADD_NEW_REPLY_TO_DISCUSSION', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const newReply = { ...note, discussion_id: discussionMock.id };
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = { discussions: [{ ...discussionMock }] };
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should add a reply to a specific discussion', () => {
|
2019-12-21 20:55:43 +05:30
|
|
|
mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply);
|
|
|
|
|
|
|
|
expect(state.discussions[0].notes.length).toEqual(4);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not add the note if it already exists in the discussion', () => {
|
|
|
|
mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply);
|
2018-03-17 18:26:18 +05:30
|
|
|
mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply);
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].notes.length).toEqual(4);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('DELETE_NOTE', () => {
|
|
|
|
it('should delete a note ', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const state = { discussions: [discussionMock] };
|
2018-03-17 18:26:18 +05:30
|
|
|
const toDelete = discussionMock.notes[0];
|
|
|
|
const lengthBefore = discussionMock.notes.length;
|
|
|
|
|
|
|
|
mutations.DELETE_NOTE(state, toDelete);
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].notes.length).toEqual(lengthBefore - 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('EXPAND_DISCUSSION', () => {
|
|
|
|
it('should expand a collapsed discussion', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = { ...discussionMock, expanded: false };
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
const state = {
|
|
|
|
discussions: [discussion],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.EXPAND_DISCUSSION(state, { discussionId: discussion.id });
|
|
|
|
|
|
|
|
expect(state.discussions[0].expanded).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('COLLAPSE_DISCUSSION', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should collapse an expanded discussion', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = { ...discussionMock, expanded: true };
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
const state = {
|
|
|
|
discussions: [discussion],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.COLLAPSE_DISCUSSION(state, { discussionId: discussion.id });
|
|
|
|
|
|
|
|
expect(state.discussions[0].expanded).toEqual(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('REMOVE_PLACEHOLDER_NOTES', () => {
|
|
|
|
it('should remove all placeholder notes in indivudal notes and discussion', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const placeholderNote = { ...individualNote, isPlaceholderNote: true };
|
2018-11-08 19:23:39 +05:30
|
|
|
const state = { discussions: [placeholderNote] };
|
2018-03-17 18:26:18 +05:30
|
|
|
mutations.REMOVE_PLACEHOLDER_NOTES(state);
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions).toEqual([]);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_NOTES_DATA', () => {
|
|
|
|
it('should set an object with notesData', () => {
|
|
|
|
const state = {
|
|
|
|
notesData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_NOTES_DATA(state, notesDataMock);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(state.notesData).toEqual(notesDataMock);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_NOTEABLE_DATA', () => {
|
|
|
|
it('should set the issue data', () => {
|
|
|
|
const state = {
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_NOTEABLE_DATA(state, noteableDataMock);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(state.noteableData).toEqual(noteableDataMock);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_USER_DATA', () => {
|
|
|
|
it('should set the user data', () => {
|
|
|
|
const state = {
|
|
|
|
userData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_USER_DATA(state, userDataMock);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(state.userData).toEqual(userDataMock);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('SET_INITIAL_DISCUSSIONS', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should set the initial notes received', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [],
|
2018-03-17 18:26:18 +05:30
|
|
|
};
|
2018-03-27 19:54:05 +05:30
|
|
|
const legacyNote = {
|
|
|
|
id: 2,
|
|
|
|
individual_note: true,
|
2018-11-08 19:23:39 +05:30
|
|
|
notes: [
|
|
|
|
{
|
|
|
|
note: '1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
note: '2',
|
|
|
|
},
|
|
|
|
],
|
2018-03-27 19:54:05 +05:30
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
mutations.SET_INITIAL_DISCUSSIONS(state, [note, legacyNote]);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
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);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
it('adds truncated_diff_lines if discussion is a diffFile', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_INITIAL_DISCUSSIONS(state, [
|
|
|
|
{
|
|
|
|
...note,
|
|
|
|
diff_file: {
|
|
|
|
file_hash: 'a',
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
truncated_diff_lines: [{ text: '+a', rich_text: '+<span>a</span>' }],
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(state.discussions[0].truncated_diff_lines).toEqual([{ rich_text: '<span>a</span>' }]);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('adds empty truncated_diff_lines when not in discussion', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_INITIAL_DISCUSSIONS(state, [
|
|
|
|
{
|
|
|
|
...note,
|
|
|
|
diff_file: {
|
|
|
|
file_hash: 'a',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(state.discussions[0].truncated_diff_lines).toEqual([]);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_LAST_FETCHED_AT', () => {
|
|
|
|
it('should set timestamp', () => {
|
|
|
|
const state = {
|
|
|
|
lastFetchedAt: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_LAST_FETCHED_AT(state, 'timestamp');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(state.lastFetchedAt).toEqual('timestamp');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_TARGET_NOTE_HASH', () => {
|
|
|
|
it('should set the note hash', () => {
|
|
|
|
const state = {
|
|
|
|
targetNoteHash: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_TARGET_NOTE_HASH(state, 'hash');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(state.targetNoteHash).toEqual('hash');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SHOW_PLACEHOLDER_NOTE', () => {
|
|
|
|
it('should set a placeholder note', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [],
|
2018-03-17 18:26:18 +05:30
|
|
|
};
|
|
|
|
mutations.SHOW_PLACEHOLDER_NOTE(state, note);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].isPlaceholderNote).toEqual(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_AWARD', () => {
|
|
|
|
it('should add award if user has not reacted yet', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [note],
|
2018-03-17 18:26:18 +05:30
|
|
|
userData: userDataMock,
|
|
|
|
};
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
note,
|
|
|
|
awardName: 'cartwheel',
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_AWARD(state, data);
|
2018-11-08 19:23:39 +05:30
|
|
|
const lastIndex = state.discussions[0].award_emoji.length - 1;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].award_emoji[lastIndex]).toEqual({
|
2018-03-17 18:26:18 +05:30
|
|
|
name: 'cartwheel',
|
|
|
|
user: { id: userDataMock.id, name: userDataMock.name, username: userDataMock.username },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove award if user already reacted', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [note],
|
2018-03-17 18:26:18 +05:30
|
|
|
userData: {
|
|
|
|
id: 1,
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
note,
|
|
|
|
awardName: 'bath_tone3',
|
|
|
|
};
|
|
|
|
mutations.TOGGLE_AWARD(state, data);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].award_emoji.length).toEqual(2);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_DISCUSSION', () => {
|
|
|
|
it('should open a closed discussion', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = { ...discussionMock, expanded: false };
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [discussion],
|
2018-03-17 18:26:18 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_DISCUSSION(state, { discussionId: discussion.id });
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].expanded).toEqual(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should close a opened discussion', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [discussionMock],
|
2018-03-17 18:26:18 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_DISCUSSION(state, { discussionId: discussionMock.id });
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].expanded).toEqual(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
it('forces a discussions expanded state', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [{ ...discussionMock, expanded: false }],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_DISCUSSION(state, { discussionId: discussionMock.id, forceExpanded: true });
|
|
|
|
|
|
|
|
expect(state.discussions[0].expanded).toEqual(true);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('SET_EXPAND_DISCUSSIONS', () => {
|
|
|
|
it('should succeed when discussions are null', () => {
|
|
|
|
const state = {};
|
|
|
|
|
|
|
|
mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds: null, expanded: true });
|
|
|
|
|
|
|
|
expect(state).toEqual({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should succeed when discussions are empty', () => {
|
|
|
|
const state = {};
|
|
|
|
|
|
|
|
mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds: [], expanded: true });
|
|
|
|
|
|
|
|
expect(state).toEqual({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should open all closed discussions', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion1 = { ...discussionMock, id: 0, expanded: false };
|
|
|
|
const discussion2 = { ...discussionMock, id: 1, expanded: true };
|
2020-04-22 19:07:51 +05:30
|
|
|
const discussionIds = [discussion1.id, discussion2.id];
|
|
|
|
|
|
|
|
const state = { discussions: [discussion1, discussion2] };
|
|
|
|
|
|
|
|
mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds, expanded: true });
|
|
|
|
|
|
|
|
state.discussions.forEach(discussion => {
|
|
|
|
expect(discussion.expanded).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should close all opened discussions', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion1 = { ...discussionMock, id: 0, expanded: false };
|
|
|
|
const discussion2 = { ...discussionMock, id: 1, expanded: true };
|
2020-04-22 19:07:51 +05:30
|
|
|
const discussionIds = [discussion1.id, discussion2.id];
|
|
|
|
|
|
|
|
const state = { discussions: [discussion1, discussion2] };
|
|
|
|
|
|
|
|
mutations.SET_EXPAND_DISCUSSIONS(state, { discussionIds, expanded: false });
|
|
|
|
|
|
|
|
state.discussions.forEach(discussion => {
|
|
|
|
expect(discussion.expanded).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('UPDATE_NOTE', () => {
|
|
|
|
it('should update a note', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [individualNote],
|
2018-03-17 18:26:18 +05:30
|
|
|
};
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const updated = { ...individualNote.notes[0], note: 'Foo' };
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
mutations.UPDATE_NOTE(state, updated);
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.discussions[0].notes[0].note).toEqual('Foo');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
describe('CLOSE_ISSUE', () => {
|
|
|
|
it('should set issue as closed', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [],
|
2018-03-27 19:54:05 +05:30
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.CLOSE_ISSUE(state);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(state.noteableData.state).toEqual('closed');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('REOPEN_ISSUE', () => {
|
|
|
|
it('should set issue as closed', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [],
|
2018-03-27 19:54:05 +05:30
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.REOPEN_ISSUE(state);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(state.noteableData.state).toEqual('reopened');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_STATE_BUTTON_LOADING', () => {
|
|
|
|
it('should set isToggleStateButtonLoading as true', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [],
|
2018-03-27 19:54:05 +05:30
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_STATE_BUTTON_LOADING(state, true);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(state.isToggleStateButtonLoading).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set isToggleStateButtonLoading as false', () => {
|
|
|
|
const state = {
|
2018-11-08 19:23:39 +05:30
|
|
|
discussions: [],
|
2018-03-27 19:54:05 +05:30
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: true,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_STATE_BUTTON_LOADING(state, false);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(state.isToggleStateButtonLoading).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
describe('SET_NOTES_FETCHED_STATE', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
it('should set the given state', () => {
|
|
|
|
const state = {
|
|
|
|
isNotesFetched: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_NOTES_FETCHED_STATE(state, true);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(state.isNotesFetched).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
describe('SET_DISCUSSION_DIFF_LINES', () => {
|
|
|
|
it('sets truncated_diff_lines', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
mutations.SET_DISCUSSION_DIFF_LINES(state, {
|
|
|
|
discussionId: 1,
|
|
|
|
diffLines: [{ text: '+a', rich_text: '+<span>a</span>' }],
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(state.discussions[0].truncated_diff_lines).toEqual([{ rich_text: '<span>a</span>' }]);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('keeps reactivity of discussion', () => {
|
|
|
|
const state = {};
|
|
|
|
Vue.set(state, 'discussions', [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
expanded: false,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const discussion = state.discussions[0];
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
mutations.SET_DISCUSSION_DIFF_LINES(state, {
|
|
|
|
discussionId: 1,
|
|
|
|
diffLines: [{ rich_text: '<span>a</span>' }],
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
discussion.expanded = true;
|
|
|
|
|
|
|
|
expect(state.discussions[0].expanded).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
describe('DISABLE_COMMENTS', () => {
|
|
|
|
it('should set comments disabled state', () => {
|
|
|
|
const state = {};
|
|
|
|
|
|
|
|
mutations.DISABLE_COMMENTS(state, true);
|
|
|
|
|
|
|
|
expect(state.commentsDisabled).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
describe('UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS', () => {
|
|
|
|
it('with unresolvable discussions, updates state', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [
|
|
|
|
{ individual_note: false, resolvable: true, notes: [UNRESOLVED_NOTE] },
|
|
|
|
{ individual_note: true, resolvable: true, notes: [UNRESOLVED_NOTE] },
|
|
|
|
{ individual_note: false, resolvable: false, notes: [UNRESOLVED_NOTE] },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS(state);
|
|
|
|
|
|
|
|
expect(state).toEqual(
|
2020-03-13 15:44:24 +05:30
|
|
|
expect.objectContaining({
|
2019-02-15 15:39:39 +05:30
|
|
|
resolvableDiscussionsCount: 1,
|
|
|
|
unresolvedDiscussionsCount: 1,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with resolvable discussions, updates state', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [
|
|
|
|
{
|
|
|
|
individual_note: false,
|
|
|
|
resolvable: true,
|
|
|
|
notes: [RESOLVED_NOTE, SYSTEM_NOTE, RESOLVED_NOTE],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
individual_note: false,
|
|
|
|
resolvable: true,
|
|
|
|
notes: [RESOLVED_NOTE, SYSTEM_NOTE, WEIRD_NOTE],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
individual_note: false,
|
|
|
|
resolvable: true,
|
|
|
|
notes: [SYSTEM_NOTE, RESOLVED_NOTE, WEIRD_NOTE, UNRESOLVED_NOTE],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
individual_note: false,
|
|
|
|
resolvable: true,
|
|
|
|
notes: [UNRESOLVED_NOTE],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS(state);
|
|
|
|
|
|
|
|
expect(state).toEqual(
|
2020-03-13 15:44:24 +05:30
|
|
|
expect.objectContaining({
|
2019-02-15 15:39:39 +05:30
|
|
|
resolvableDiscussionsCount: 4,
|
|
|
|
unresolvedDiscussionsCount: 2,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
describe('CONVERT_TO_DISCUSSION', () => {
|
|
|
|
let discussion;
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
discussion = {
|
|
|
|
id: 42,
|
|
|
|
individual_note: true,
|
|
|
|
};
|
2019-07-07 11:18:12 +05:30
|
|
|
state = { convertedDisscussionIds: [] };
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it('adds a discussion to convertedDisscussionIds', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
mutations.CONVERT_TO_DISCUSSION(state, discussion.id);
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(state.convertedDisscussionIds).toContain(discussion.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('REMOVE_CONVERTED_DISCUSSION', () => {
|
|
|
|
let discussion;
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
discussion = {
|
|
|
|
id: 42,
|
|
|
|
individual_note: true,
|
|
|
|
};
|
|
|
|
state = { convertedDisscussionIds: [41, 42] };
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it('removes a discussion from convertedDisscussionIds', () => {
|
|
|
|
mutations.REMOVE_CONVERTED_DISCUSSION(state, discussion.id);
|
|
|
|
|
|
|
|
expect(state.convertedDisscussionIds).not.toContain(discussion.id);
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
describe('RECEIVE_DESCRIPTION_VERSION', () => {
|
|
|
|
const descriptionVersion = notesWithDescriptionChanges[0].notes[0].note;
|
|
|
|
const versionId = notesWithDescriptionChanges[0].notes[0].id;
|
|
|
|
const state = {};
|
|
|
|
|
|
|
|
it('adds a descriptionVersion', () => {
|
|
|
|
mutations.RECEIVE_DESCRIPTION_VERSION(state, { descriptionVersion, versionId });
|
|
|
|
expect(state.descriptionVersions[versionId]).toBe(descriptionVersion);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('RECEIVE_DELETE_DESCRIPTION_VERSION', () => {
|
|
|
|
const descriptionVersion = notesWithDescriptionChanges[0].notes[0].note;
|
|
|
|
const versionId = notesWithDescriptionChanges[0].notes[0].id;
|
|
|
|
const state = { descriptionVersions: { [versionId]: descriptionVersion } };
|
|
|
|
const deleted = 'Deleted';
|
|
|
|
|
|
|
|
it('updates descriptionVersion to "Deleted"', () => {
|
|
|
|
mutations.RECEIVE_DELETE_DESCRIPTION_VERSION(state, { [versionId]: deleted });
|
|
|
|
expect(state.descriptionVersions[versionId]).toBe(deleted);
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
describe('SET_DISCUSSIONS_SORT', () => {
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = { discussionSortOrder: ASC };
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets sort order', () => {
|
|
|
|
mutations.SET_DISCUSSIONS_SORT(state, DESC);
|
|
|
|
|
|
|
|
expect(state.discussionSortOrder).toBe(DESC);
|
|
|
|
});
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
describe('TOGGLE_BLOCKED_ISSUE_WARNING', () => {
|
|
|
|
it('should set isToggleBlockedIssueWarning as true', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [],
|
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
isToggleBlockedIssueWarning: false,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_BLOCKED_ISSUE_WARNING(state, true);
|
|
|
|
|
|
|
|
expect(state.isToggleBlockedIssueWarning).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set isToggleBlockedIssueWarning as false', () => {
|
|
|
|
const state = {
|
|
|
|
discussions: [],
|
|
|
|
targetNoteHash: null,
|
|
|
|
lastFetchedAt: null,
|
|
|
|
isToggleStateButtonLoading: false,
|
|
|
|
isToggleBlockedIssueWarning: true,
|
|
|
|
notesData: {},
|
|
|
|
userData: {},
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.TOGGLE_BLOCKED_ISSUE_WARNING(state, false);
|
|
|
|
|
|
|
|
expect(state.isToggleBlockedIssueWarning).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|