2017-08-17 22:00:37 +05:30
|
|
|
/* global CommentsStore */
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
import '~/diff_notes/models/discussion';
|
|
|
|
import '~/diff_notes/models/note';
|
|
|
|
import '~/diff_notes/stores/comments';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
function createDiscussion(noteId = 1, resolved = true) {
|
|
|
|
CommentsStore.create({
|
|
|
|
discussionId: 'a',
|
|
|
|
noteId,
|
|
|
|
canResolve: true,
|
|
|
|
resolved,
|
|
|
|
resolvedBy: 'test',
|
|
|
|
authorName: 'test',
|
|
|
|
authorAvatar: 'test',
|
|
|
|
noteTruncated: 'test...',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
CommentsStore.state = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('New discussion', () => {
|
|
|
|
it('creates new discussion', () => {
|
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
createDiscussion();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates new note in discussion', () => {
|
|
|
|
createDiscussion();
|
|
|
|
createDiscussion(2);
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = CommentsStore.state.a;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(Object.keys(discussion.notes).length).toBe(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Get note', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createDiscussion();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('gets note by ID', () => {
|
|
|
|
const note = CommentsStore.get('a', 1);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(note).toBeDefined();
|
|
|
|
expect(note.id).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Delete discussion', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createDiscussion();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('deletes discussion by ID', () => {
|
|
|
|
CommentsStore.delete('a', 1);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('deletes discussion when no more notes', () => {
|
|
|
|
createDiscussion();
|
|
|
|
createDiscussion(2);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(1);
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(Object.keys(CommentsStore.state.a.notes).length).toBe(2);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
CommentsStore.delete('a', 1);
|
|
|
|
CommentsStore.delete('a', 2);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Update note', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createDiscussion();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates note to be unresolved', () => {
|
|
|
|
CommentsStore.update('a', 1, false, 'test');
|
|
|
|
|
|
|
|
const note = CommentsStore.get('a', 1);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(note.resolved).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Discussion resolved', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createDiscussion();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is resolved with single note', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = CommentsStore.state.a;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(discussion.isResolved()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is unresolved with 2 notes', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = CommentsStore.state.a;
|
2017-08-17 22:00:37 +05:30
|
|
|
createDiscussion(2, false);
|
|
|
|
|
|
|
|
expect(discussion.isResolved()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is resolved with 2 notes', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = CommentsStore.state.a;
|
2017-08-17 22:00:37 +05:30
|
|
|
createDiscussion(2);
|
|
|
|
|
|
|
|
expect(discussion.isResolved()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('resolve all notes', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = CommentsStore.state.a;
|
2017-08-17 22:00:37 +05:30
|
|
|
createDiscussion(2, false);
|
|
|
|
|
|
|
|
discussion.resolveAllNotes();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(discussion.isResolved()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('unresolve all notes', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const discussion = CommentsStore.state.a;
|
2017-08-17 22:00:37 +05:30
|
|
|
createDiscussion(2);
|
|
|
|
|
|
|
|
discussion.unResolveAllNotes();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(discussion.isResolved()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|