diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/frontend/diff_comments_store_spec.js | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/frontend/diff_comments_store_spec.js')
-rw-r--r-- | spec/frontend/diff_comments_store_spec.js | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/spec/frontend/diff_comments_store_spec.js b/spec/frontend/diff_comments_store_spec.js new file mode 100644 index 00000000000..6f25c9dd3bc --- /dev/null +++ b/spec/frontend/diff_comments_store_spec.js @@ -0,0 +1,136 @@ +/* global CommentsStore */ + +import '~/diff_notes/models/discussion'; +import '~/diff_notes/models/note'; +import '~/diff_notes/stores/comments'; + +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(); + + expect(Object.keys(CommentsStore.state).length).toBe(1); + }); + + it('creates new note in discussion', () => { + createDiscussion(); + createDiscussion(2); + + const discussion = CommentsStore.state.a; + + expect(Object.keys(discussion.notes).length).toBe(2); + }); +}); + +describe('Get note', () => { + beforeEach(() => { + createDiscussion(); + }); + + it('gets note by ID', () => { + const note = CommentsStore.get('a', 1); + + expect(note).toBeDefined(); + expect(note.id).toBe(1); + }); +}); + +describe('Delete discussion', () => { + beforeEach(() => { + createDiscussion(); + }); + + it('deletes discussion by ID', () => { + CommentsStore.delete('a', 1); + + expect(Object.keys(CommentsStore.state).length).toBe(0); + }); + + it('deletes discussion when no more notes', () => { + createDiscussion(); + createDiscussion(2); + + expect(Object.keys(CommentsStore.state).length).toBe(1); + expect(Object.keys(CommentsStore.state.a.notes).length).toBe(2); + + CommentsStore.delete('a', 1); + CommentsStore.delete('a', 2); + + 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); + + expect(note.resolved).toBe(false); + }); +}); + +describe('Discussion resolved', () => { + beforeEach(() => { + createDiscussion(); + }); + + it('is resolved with single note', () => { + const discussion = CommentsStore.state.a; + + expect(discussion.isResolved()).toBe(true); + }); + + it('is unresolved with 2 notes', () => { + const discussion = CommentsStore.state.a; + createDiscussion(2, false); + + expect(discussion.isResolved()).toBe(false); + }); + + it('is resolved with 2 notes', () => { + const discussion = CommentsStore.state.a; + createDiscussion(2); + + expect(discussion.isResolved()).toBe(true); + }); + + it('resolve all notes', () => { + const discussion = CommentsStore.state.a; + createDiscussion(2, false); + + discussion.resolveAllNotes(); + + expect(discussion.isResolved()).toBe(true); + }); + + it('unresolve all notes', () => { + const discussion = CommentsStore.state.a; + createDiscussion(2); + + discussion.unResolveAllNotes(); + + expect(discussion.isResolved()).toBe(false); + }); +}); |