summaryrefslogtreecommitdiff
path: root/spec/frontend/notes/stores/getters_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/notes/stores/getters_spec.js')
-rw-r--r--spec/frontend/notes/stores/getters_spec.js69
1 files changed, 56 insertions, 13 deletions
diff --git a/spec/frontend/notes/stores/getters_spec.js b/spec/frontend/notes/stores/getters_spec.js
index 4d2f86a1ecf..3adb5da020e 100644
--- a/spec/frontend/notes/stores/getters_spec.js
+++ b/spec/frontend/notes/stores/getters_spec.js
@@ -1,4 +1,4 @@
-import { DESC } from '~/notes/constants';
+import { DESC, ASC } from '~/notes/constants';
import * as getters from '~/notes/stores/getters';
import {
notesDataMock,
@@ -12,6 +12,9 @@ import {
discussion3,
resolvedDiscussion1,
unresolvableDiscussion,
+ draftComments,
+ draftReply,
+ draftDiffDiscussion,
} from '../mock_data';
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
@@ -23,6 +26,8 @@ const createDiscussionNeighborParams = (discussionId, diffOrder, step) => ({
step,
});
+const asDraftDiscussion = (x) => ({ ...x, individual_note: true });
+
describe('Getters Notes Store', () => {
let state;
@@ -61,20 +66,58 @@ describe('Getters Notes Store', () => {
});
describe('discussions', () => {
- it('should return all discussions in the store', () => {
- expect(getters.discussions(state)).toEqual([individualNote]);
- });
+ let batchComments = null;
+
+ const getDiscussions = () => getters.discussions(state, {}, { batchComments });
+
+ describe('without batchComments module', () => {
+ it('should return all discussions in the store', () => {
+ expect(getDiscussions()).toEqual([individualNote]);
+ });
+
+ it('should transform discussion to individual notes in timeline view', () => {
+ state.discussions = [discussionMock];
+ state.isTimelineEnabled = true;
- it('should transform discussion to individual notes in timeline view', () => {
- state.discussions = [discussionMock];
- state.isTimelineEnabled = true;
+ const discussions = getDiscussions();
+
+ expect(discussions.length).toEqual(discussionMock.notes.length);
+ discussions.forEach((discussion) => {
+ expect(discussion.individual_note).toBe(true);
+ expect(discussion.id).toBe(discussion.notes[0].id);
+ expect(discussion.created_at).toBe(discussion.notes[0].created_at);
+ });
+ });
+ });
- expect(getters.discussions(state).length).toEqual(discussionMock.notes.length);
- getters.discussions(state).forEach((discussion) => {
- expect(discussion.individual_note).toBe(true);
- expect(discussion.id).toBe(discussion.notes[0].id);
- expect(discussion.created_at).toBe(discussion.notes[0].created_at);
+ describe('with batchComments', () => {
+ beforeEach(() => {
+ batchComments = { drafts: [...draftComments, draftReply, draftDiffDiscussion] };
});
+
+ it.each`
+ discussionSortOrder | expectation
+ ${ASC} | ${[individualNote, ...draftComments.map(asDraftDiscussion)]}
+ ${DESC} | ${[...draftComments.reverse().map(asDraftDiscussion), individualNote]}
+ `(
+ 'only appends draft comments (discussionSortOrder=$discussionSortOrder)',
+ ({ discussionSortOrder, expectation }) => {
+ state.discussionSortOrder = discussionSortOrder;
+
+ expect(getDiscussions()).toEqual(expectation);
+ },
+ );
+ });
+ });
+
+ describe('hasDrafts', () => {
+ it.each`
+ rootGetters | expected
+ ${{}} | ${false}
+ ${{ 'batchComments/hasDrafts': true }} | ${true}
+ ${{ 'batchComments/hasDrafts': false }} | ${false}
+ `('with rootGetters=$rootGetters, returns $expected', ({ rootGetters, expected }) => {
+ expect(getters.hasDrafts({}, {}, {}, rootGetters)).toBe(expected);
});
});
@@ -103,7 +146,7 @@ describe('Getters Notes Store', () => {
};
it('should return a single system note when a description was updated multiple times', () => {
- expect(getters.discussions(stateCollapsedNotes).length).toEqual(1);
+ expect(getters.discussions(stateCollapsedNotes, {}, {}).length).toEqual(1);
});
});