summaryrefslogtreecommitdiff
path: root/spec/frontend/notes/stores/actions_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/notes/stores/actions_spec.js')
-rw-r--r--spec/frontend/notes/stores/actions_spec.js91
1 files changed, 90 insertions, 1 deletions
diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js
index 2ff65d3f47e..bbe074f0105 100644
--- a/spec/frontend/notes/stores/actions_spec.js
+++ b/spec/frontend/notes/stores/actions_spec.js
@@ -119,7 +119,7 @@ describe('Actions Notes Store', () => {
actions.setInitialNotes,
[individualNote],
{ notes: [] },
- [{ type: 'SET_INITIAL_DISCUSSIONS', payload: [individualNote] }],
+ [{ type: 'ADD_OR_UPDATE_DISCUSSIONS', payload: [individualNote] }],
[],
done,
);
@@ -1395,4 +1395,93 @@ describe('Actions Notes Store', () => {
);
});
});
+
+ describe('fetchDiscussions', () => {
+ const discussion = { notes: [] };
+
+ afterEach(() => {
+ window.gon = {};
+ });
+
+ it('updates the discussions and dispatches `updateResolvableDiscussionsCounts`', (done) => {
+ axiosMock.onAny().reply(200, { discussion });
+ testAction(
+ actions.fetchDiscussions,
+ {},
+ null,
+ [
+ { type: mutationTypes.ADD_OR_UPDATE_DISCUSSIONS, payload: { discussion } },
+ { type: mutationTypes.SET_FETCHING_DISCUSSIONS, payload: false },
+ ],
+ [{ type: 'updateResolvableDiscussionsCounts' }],
+ done,
+ );
+ });
+
+ it('dispatches `fetchDiscussionsBatch` action if `paginatedIssueDiscussions` feature flag is enabled', (done) => {
+ window.gon = { features: { paginatedIssueDiscussions: true } };
+
+ testAction(
+ actions.fetchDiscussions,
+ { path: 'test-path', filter: 'test-filter', persistFilter: 'test-persist-filter' },
+ null,
+ [],
+ [
+ {
+ type: 'fetchDiscussionsBatch',
+ payload: {
+ config: {
+ params: { notes_filter: 'test-filter', persist_filter: 'test-persist-filter' },
+ },
+ path: 'test-path',
+ perPage: 20,
+ },
+ },
+ ],
+ done,
+ );
+ });
+ });
+
+ describe('fetchDiscussionsBatch', () => {
+ const discussion = { notes: [] };
+
+ const config = {
+ params: { notes_filter: 'test-filter', persist_filter: 'test-persist-filter' },
+ };
+
+ const actionPayload = { config, path: 'test-path', perPage: 20 };
+
+ it('updates the discussions and dispatches `updateResolvableDiscussionsCounts if there are no headers', (done) => {
+ axiosMock.onAny().reply(200, { discussion }, {});
+ testAction(
+ actions.fetchDiscussionsBatch,
+ actionPayload,
+ null,
+ [
+ { type: mutationTypes.ADD_OR_UPDATE_DISCUSSIONS, payload: { discussion } },
+ { type: mutationTypes.SET_FETCHING_DISCUSSIONS, payload: false },
+ ],
+ [{ type: 'updateResolvableDiscussionsCounts' }],
+ done,
+ );
+ });
+
+ it('dispatches itself if there is `x-next-page-cursor` header', (done) => {
+ axiosMock.onAny().reply(200, { discussion }, { 'x-next-page-cursor': 1 });
+ testAction(
+ actions.fetchDiscussionsBatch,
+ actionPayload,
+ null,
+ [{ type: mutationTypes.ADD_OR_UPDATE_DISCUSSIONS, payload: { discussion } }],
+ [
+ {
+ type: 'fetchDiscussionsBatch',
+ payload: { ...actionPayload, perPage: 30, cursor: 1 },
+ },
+ ],
+ done,
+ );
+ });
+ });
});