diff options
Diffstat (limited to 'spec/frontend/notes')
-rw-r--r-- | spec/frontend/notes/components/discussion_counter_spec.js | 6 | ||||
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 91 | ||||
-rw-r--r-- | spec/frontend/notes/stores/mutation_spec.js | 10 |
3 files changed, 99 insertions, 8 deletions
diff --git a/spec/frontend/notes/components/discussion_counter_spec.js b/spec/frontend/notes/components/discussion_counter_spec.js index 9db0f823d84..c454d502beb 100644 --- a/spec/frontend/notes/components/discussion_counter_spec.js +++ b/spec/frontend/notes/components/discussion_counter_spec.js @@ -53,7 +53,7 @@ describe('DiscussionCounter component', () => { describe('has no resolvable discussions', () => { it('does not render', () => { - store.commit(types.SET_INITIAL_DISCUSSIONS, [{ ...discussionMock, resolvable: false }]); + store.commit(types.ADD_OR_UPDATE_DISCUSSIONS, [{ ...discussionMock, resolvable: false }]); store.dispatch('updateResolvableDiscussionsCounts'); wrapper = shallowMount(DiscussionCounter, { store, localVue }); @@ -64,7 +64,7 @@ describe('DiscussionCounter component', () => { describe('has resolvable discussions', () => { const updateStore = (note = {}) => { discussionMock.notes[0] = { ...discussionMock.notes[0], ...note }; - store.commit(types.SET_INITIAL_DISCUSSIONS, [discussionMock]); + store.commit(types.ADD_OR_UPDATE_DISCUSSIONS, [discussionMock]); store.dispatch('updateResolvableDiscussionsCounts'); }; @@ -97,7 +97,7 @@ describe('DiscussionCounter component', () => { let toggleAllButton; const updateStoreWithExpanded = (expanded) => { const discussion = { ...discussionMock, expanded }; - store.commit(types.SET_INITIAL_DISCUSSIONS, [discussion]); + store.commit(types.ADD_OR_UPDATE_DISCUSSIONS, [discussion]); store.dispatch('updateResolvableDiscussionsCounts'); wrapper = shallowMount(DiscussionCounter, { store, localVue }); toggleAllButton = wrapper.find('.toggle-all-discussions-btn'); 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, + ); + }); + }); }); diff --git a/spec/frontend/notes/stores/mutation_spec.js b/spec/frontend/notes/stores/mutation_spec.js index 99e24f724f4..c9e24039b64 100644 --- a/spec/frontend/notes/stores/mutation_spec.js +++ b/spec/frontend/notes/stores/mutation_spec.js @@ -159,7 +159,7 @@ describe('Notes Store mutations', () => { }); }); - describe('SET_INITIAL_DISCUSSIONS', () => { + describe('ADD_OR_UPDATE_DISCUSSIONS', () => { it('should set the initial notes received', () => { const state = { discussions: [], @@ -169,15 +169,17 @@ describe('Notes Store mutations', () => { individual_note: true, notes: [ { + id: 100, note: '1', }, { + id: 101, note: '2', }, ], }; - mutations.SET_INITIAL_DISCUSSIONS(state, [note, legacyNote]); + mutations.ADD_OR_UPDATE_DISCUSSIONS(state, [note, legacyNote]); expect(state.discussions[0].id).toEqual(note.id); expect(state.discussions[1].notes[0].note).toBe(legacyNote.notes[0].note); @@ -190,7 +192,7 @@ describe('Notes Store mutations', () => { discussions: [], }; - mutations.SET_INITIAL_DISCUSSIONS(state, [ + mutations.ADD_OR_UPDATE_DISCUSSIONS(state, [ { ...note, diff_file: { @@ -208,7 +210,7 @@ describe('Notes Store mutations', () => { discussions: [], }; - mutations.SET_INITIAL_DISCUSSIONS(state, [ + mutations.ADD_OR_UPDATE_DISCUSSIONS(state, [ { ...note, diff_file: { |