2018-10-09 11:25:53 -04:00
|
|
|
/* eslint-disable jasmine/no-global-setup, dot-notation, jasmine/no-expect-in-setup-teardown */
|
2016-12-13 22:01:05 -05:00
|
|
|
/* global CommentsStore */
|
|
|
|
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/diff_notes/models/discussion';
|
|
|
|
import '~/diff_notes/models/note';
|
|
|
|
import '~/diff_notes/stores/comments';
|
2016-12-13 22:01:05 -05:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
function createDiscussion(noteId = 1, resolved = true) {
|
|
|
|
CommentsStore.create({
|
|
|
|
discussionId: 'a',
|
|
|
|
noteId,
|
|
|
|
canResolve: true,
|
|
|
|
resolved,
|
|
|
|
resolvedBy: 'test',
|
|
|
|
authorName: 'test',
|
|
|
|
authorAvatar: 'test',
|
|
|
|
noteTruncated: 'test...',
|
2016-07-29 10:03:58 -04:00
|
|
|
});
|
2017-04-17 02:35:56 -04:00
|
|
|
}
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
CommentsStore.state = {};
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
describe('New discussion', () => {
|
|
|
|
it('creates new discussion', () => {
|
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
createDiscussion();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(1);
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('creates new note in discussion', () => {
|
|
|
|
createDiscussion();
|
|
|
|
createDiscussion(2);
|
|
|
|
|
|
|
|
const discussion = CommentsStore.state['a'];
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(Object.keys(discussion.notes).length).toBe(2);
|
2016-07-29 10:03:58 -04:00
|
|
|
});
|
2017-04-17 02:35:56 -04:00
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
describe('Get note', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
createDiscussion();
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('gets note by ID', () => {
|
|
|
|
const note = CommentsStore.get('a', 1);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(note).toBeDefined();
|
|
|
|
expect(note.id).toBe(1);
|
2016-07-29 10:03:58 -04:00
|
|
|
});
|
2017-04-17 02:35:56 -04:00
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
describe('Delete discussion', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
createDiscussion();
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('deletes discussion by ID', () => {
|
|
|
|
CommentsStore.delete('a', 1);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('deletes discussion when no more notes', () => {
|
|
|
|
createDiscussion();
|
|
|
|
createDiscussion(2);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(1);
|
|
|
|
expect(Object.keys(CommentsStore.state['a'].notes).length).toBe(2);
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
CommentsStore.delete('a', 1);
|
|
|
|
CommentsStore.delete('a', 2);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
2016-07-29 10:03:58 -04:00
|
|
|
});
|
2017-04-17 02:35:56 -04:00
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
describe('Update note', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
createDiscussion();
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('updates note to be unresolved', () => {
|
|
|
|
CommentsStore.update('a', 1, false, 'test');
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
const note = CommentsStore.get('a', 1);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(note.resolved).toBe(false);
|
2016-07-29 10:03:58 -04:00
|
|
|
});
|
2017-04-17 02:35:56 -04:00
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
describe('Discussion resolved', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
expect(Object.keys(CommentsStore.state).length).toBe(0);
|
|
|
|
createDiscussion();
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('is resolved with single note', () => {
|
|
|
|
const discussion = CommentsStore.state['a'];
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(discussion.isResolved()).toBe(true);
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('is unresolved with 2 notes', () => {
|
|
|
|
const discussion = CommentsStore.state['a'];
|
|
|
|
createDiscussion(2, false);
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(discussion.isResolved()).toBe(false);
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('is resolved with 2 notes', () => {
|
|
|
|
const discussion = CommentsStore.state['a'];
|
|
|
|
createDiscussion(2);
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(discussion.isResolved()).toBe(true);
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('resolve all notes', () => {
|
|
|
|
const discussion = CommentsStore.state['a'];
|
|
|
|
createDiscussion(2, false);
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
discussion.resolveAllNotes();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(discussion.isResolved()).toBe(true);
|
|
|
|
});
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
it('unresolve all notes', () => {
|
|
|
|
const discussion = CommentsStore.state['a'];
|
|
|
|
createDiscussion(2);
|
2016-07-29 10:03:58 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
discussion.unResolveAllNotes();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-04-17 02:35:56 -04:00
|
|
|
expect(discussion.isResolved()).toBe(false);
|
2016-07-29 10:03:58 -04:00
|
|
|
});
|
2017-04-17 02:35:56 -04:00
|
|
|
});
|