diff options
Diffstat (limited to 'spec/frontend/notes/stores/actions_spec.js')
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 130 |
1 files changed, 61 insertions, 69 deletions
diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index c9912621785..f0e6a0a68dd 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -1,5 +1,6 @@ import { TEST_HOST } from 'spec/test_constants'; import AxiosMockAdapter from 'axios-mock-adapter'; +import testAction from 'helpers/vuex_action_helper'; import Api from '~/api'; import { deprecatedCreateFlash as Flash } from '~/flash'; import * as actions from '~/notes/stores/actions'; @@ -8,7 +9,6 @@ import * as mutationTypes from '~/notes/stores/mutation_types'; import * as notesConstants from '~/notes/constants'; import createStore from '~/notes/stores'; import mrWidgetEventHub from '~/vue_merge_request_widget/event_hub'; -import testAction from '../../helpers/vuex_action_helper'; import { resetStore } from '../helpers'; import { discussionMock, @@ -53,7 +53,7 @@ describe('Actions Notes Store', () => { }); describe('setNotesData', () => { - it('should set received notes data', done => { + it('should set received notes data', (done) => { testAction( actions.setNotesData, notesDataMock, @@ -66,7 +66,7 @@ describe('Actions Notes Store', () => { }); describe('setNoteableData', () => { - it('should set received issue data', done => { + it('should set received issue data', (done) => { testAction( actions.setNoteableData, noteableDataMock, @@ -79,7 +79,7 @@ describe('Actions Notes Store', () => { }); describe('setUserData', () => { - it('should set received user data', done => { + it('should set received user data', (done) => { testAction( actions.setUserData, userDataMock, @@ -92,7 +92,7 @@ describe('Actions Notes Store', () => { }); describe('setLastFetchedAt', () => { - it('should set received timestamp', done => { + it('should set received timestamp', (done) => { testAction( actions.setLastFetchedAt, 'timestamp', @@ -105,7 +105,7 @@ describe('Actions Notes Store', () => { }); describe('setInitialNotes', () => { - it('should set initial notes', done => { + it('should set initial notes', (done) => { testAction( actions.setInitialNotes, [individualNote], @@ -118,7 +118,7 @@ describe('Actions Notes Store', () => { }); describe('setTargetNoteHash', () => { - it('should set target note hash', done => { + it('should set target note hash', (done) => { testAction( actions.setTargetNoteHash, 'hash', @@ -131,7 +131,7 @@ describe('Actions Notes Store', () => { }); describe('toggleDiscussion', () => { - it('should toggle discussion', done => { + it('should toggle discussion', (done) => { testAction( actions.toggleDiscussion, { discussionId: discussionMock.id }, @@ -144,7 +144,7 @@ describe('Actions Notes Store', () => { }); describe('expandDiscussion', () => { - it('should expand discussion', done => { + it('should expand discussion', (done) => { testAction( actions.expandDiscussion, { discussionId: discussionMock.id }, @@ -157,7 +157,7 @@ describe('Actions Notes Store', () => { }); describe('collapseDiscussion', () => { - it('should commit collapse discussion', done => { + it('should commit collapse discussion', (done) => { testAction( actions.collapseDiscussion, { discussionId: discussionMock.id }, @@ -175,7 +175,7 @@ describe('Actions Notes Store', () => { }); describe('closeMergeRequest', () => { - it('sets state as closed', done => { + it('sets state as closed', (done) => { store .dispatch('closeIssuable', { notesData: { closeIssuePath: '' } }) .then(() => { @@ -188,7 +188,7 @@ describe('Actions Notes Store', () => { }); describe('reopenMergeRequest', () => { - it('sets state as reopened', done => { + it('sets state as reopened', (done) => { store .dispatch('reopenIssuable', { notesData: { reopenIssuePath: '' } }) .then(() => { @@ -203,7 +203,7 @@ describe('Actions Notes Store', () => { describe('emitStateChangedEvent', () => { it('emits an event on the document', () => { - document.addEventListener('issuable_vue_app:change', event => { + document.addEventListener('issuable_vue_app:change', (event) => { expect(event.detail.data).toEqual({ id: '1', state: 'closed' }); expect(event.detail.isClosed).toEqual(false); }); @@ -213,7 +213,7 @@ describe('Actions Notes Store', () => { }); describe('toggleStateButtonLoading', () => { - it('should set loading as true', done => { + it('should set loading as true', (done) => { testAction( actions.toggleStateButtonLoading, true, @@ -224,7 +224,7 @@ describe('Actions Notes Store', () => { ); }); - it('should set loading as false', done => { + it('should set loading as false', (done) => { testAction( actions.toggleStateButtonLoading, false, @@ -237,11 +237,11 @@ describe('Actions Notes Store', () => { }); describe('toggleIssueLocalState', () => { - it('sets issue state as closed', done => { + it('sets issue state as closed', (done) => { testAction(actions.toggleIssueLocalState, 'closed', {}, [{ type: 'CLOSE_ISSUE' }], [], done); }); - it('sets issue state as reopened', done => { + it('sets issue state as reopened', (done) => { testAction( actions.toggleIssueLocalState, 'reopened', @@ -297,24 +297,21 @@ describe('Actions Notes Store', () => { }); describe('poll', () => { - beforeEach(done => { + beforeEach((done) => { axiosMock .onGet(notesDataMock.notesPath) .reply(200, { notes: [], last_fetched_at: '123456' }, { 'poll-interval': '1000' }); - store - .dispatch('setNotesData', notesDataMock) - .then(done) - .catch(done.fail); + store.dispatch('setNotesData', notesDataMock).then(done).catch(done.fail); }); - it('calls service with last fetched state', done => { + it('calls service with last fetched state', (done) => { store .dispatch('poll') .then(() => { jest.advanceTimersByTime(2); }) - .then(() => new Promise(resolve => requestAnimationFrame(resolve))) + .then(() => new Promise((resolve) => requestAnimationFrame(resolve))) .then(() => { expect(store.state.lastFetchedAt).toBe('123456'); @@ -322,7 +319,7 @@ describe('Actions Notes Store', () => { }) .then( () => - new Promise(resolve => { + new Promise((resolve) => { requestAnimationFrame(resolve); }), ) @@ -340,7 +337,7 @@ describe('Actions Notes Store', () => { }); describe('setNotesFetchedState', () => { - it('should set notes fetched state', done => { + it('should set notes fetched state', (done) => { testAction( actions.setNotesFetchedState, true, @@ -367,7 +364,7 @@ describe('Actions Notes Store', () => { document.body.setAttribute('data-page', ''); }); - it('commits DELETE_NOTE and dispatches updateMergeRequestWidget', done => { + it('commits DELETE_NOTE and dispatches updateMergeRequestWidget', (done) => { const note = { path: endpoint, id: 1 }; testAction( @@ -392,7 +389,7 @@ describe('Actions Notes Store', () => { ); }); - it('dispatches removeDiscussionsFromDiff on merge request page', done => { + it('dispatches removeDiscussionsFromDiff on merge request page', (done) => { const note = { path: endpoint, id: 1 }; document.body.setAttribute('data-page', 'projects:merge_requests:show'); @@ -438,7 +435,7 @@ describe('Actions Notes Store', () => { document.body.setAttribute('data-page', ''); }); - it('dispatches removeNote', done => { + it('dispatches removeNote', (done) => { const note = { path: endpoint, id: 1 }; testAction( @@ -471,7 +468,7 @@ describe('Actions Notes Store', () => { axiosMock.onAny().reply(200, res); }); - it('commits ADD_NEW_NOTE and dispatches updateMergeRequestWidget', done => { + it('commits ADD_NEW_NOTE and dispatches updateMergeRequestWidget', (done) => { testAction( actions.createNewNote, { endpoint: `${TEST_HOST}`, data: {} }, @@ -507,7 +504,7 @@ describe('Actions Notes Store', () => { axiosMock.onAny().replyOnce(200, res); }); - it('does not commit ADD_NEW_NOTE or dispatch updateMergeRequestWidget', done => { + it('does not commit ADD_NEW_NOTE or dispatch updateMergeRequestWidget', (done) => { testAction( actions.createNewNote, { endpoint: `${TEST_HOST}`, data: {} }, @@ -530,7 +527,7 @@ describe('Actions Notes Store', () => { }); describe('as note', () => { - it('commits UPDATE_NOTE and dispatches updateMergeRequestWidget', done => { + it('commits UPDATE_NOTE and dispatches updateMergeRequestWidget', (done) => { testAction( actions.toggleResolveNote, { endpoint: `${TEST_HOST}`, isResolved: true, discussion: false }, @@ -555,7 +552,7 @@ describe('Actions Notes Store', () => { }); describe('as discussion', () => { - it('commits UPDATE_DISCUSSION and dispatches updateMergeRequestWidget', done => { + it('commits UPDATE_DISCUSSION and dispatches updateMergeRequestWidget', (done) => { testAction( actions.toggleResolveNote, { endpoint: `${TEST_HOST}`, isResolved: true, discussion: true }, @@ -591,7 +588,7 @@ describe('Actions Notes Store', () => { }); describe('setCommentsDisabled', () => { - it('should set comments disabled state', done => { + it('should set comments disabled state', (done) => { testAction( actions.setCommentsDisabled, true, @@ -604,7 +601,7 @@ describe('Actions Notes Store', () => { }); describe('updateResolvableDiscussionsCounts', () => { - it('commits UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS', done => { + it('commits UPDATE_RESOLVABLE_DISCUSSIONS_COUNTS', (done) => { testAction( actions.updateResolvableDiscussionsCounts, null, @@ -617,7 +614,7 @@ describe('Actions Notes Store', () => { }); describe('convertToDiscussion', () => { - it('commits CONVERT_TO_DISCUSSION with noteId', done => { + it('commits CONVERT_TO_DISCUSSION with noteId', (done) => { const noteId = 'dummy-note-id'; testAction( actions.convertToDiscussion, @@ -721,7 +718,7 @@ describe('Actions Notes Store', () => { describe('replyToDiscussion', () => { const payload = { endpoint: TEST_HOST, data: {} }; - it('updates discussion if response contains disussion', done => { + it('updates discussion if response contains disussion', (done) => { const discussion = { notes: [] }; axiosMock.onAny().reply(200, { discussion }); @@ -741,7 +738,7 @@ describe('Actions Notes Store', () => { ); }); - it('adds a reply to a discussion', done => { + it('adds a reply to a discussion', (done) => { const res = {}; axiosMock.onAny().reply(200, res); @@ -759,7 +756,7 @@ describe('Actions Notes Store', () => { }); describe('removeConvertedDiscussion', () => { - it('commits CONVERT_TO_DISCUSSION with noteId', done => { + it('commits CONVERT_TO_DISCUSSION with noteId', (done) => { const noteId = 'dummy-id'; testAction( actions.removeConvertedDiscussion, @@ -784,7 +781,7 @@ describe('Actions Notes Store', () => { }; }); - it('when unresolved, dispatches action', done => { + it('when unresolved, dispatches action', (done) => { testAction( actions.resolveDiscussion, { discussionId }, @@ -804,8 +801,8 @@ describe('Actions Notes Store', () => { ); }); - it('when resolved, does nothing', done => { - getters.isDiscussionResolved = id => id === discussionId; + it('when resolved, does nothing', (done) => { + getters.isDiscussionResolved = (id) => id === discussionId; testAction( actions.resolveDiscussion, @@ -826,7 +823,7 @@ describe('Actions Notes Store', () => { const res = { errors: { something: ['went wrong'] } }; const error = { message: 'Unprocessable entity', response: { data: res } }; - it('throws an error', done => { + it('throws an error', (done) => { actions .saveNote( { @@ -836,7 +833,7 @@ describe('Actions Notes Store', () => { payload, ) .then(() => done.fail('Expected error to be thrown!')) - .catch(err => { + .catch((err) => { expect(err).toBe(error); expect(Flash).not.toHaveBeenCalled(); }) @@ -849,7 +846,7 @@ describe('Actions Notes Store', () => { const res = { errors: { base: ['something went wrong'] } }; const error = { message: 'Unprocessable entity', response: { data: res } }; - it('sets flash alert using errors.base message', done => { + it('sets flash alert using errors.base message', (done) => { actions .saveNote( { @@ -858,7 +855,7 @@ describe('Actions Notes Store', () => { }, { ...payload, flashContainer }, ) - .then(resp => { + .then((resp) => { expect(resp.hasFlash).toBe(true); expect(Flash).toHaveBeenCalledWith( 'Your comment could not be submitted because something went wrong', @@ -875,7 +872,7 @@ describe('Actions Notes Store', () => { describe('if response contains no errors', () => { const res = { valid: true }; - it('returns the response', done => { + it('returns the response', (done) => { actions .saveNote( { @@ -884,7 +881,7 @@ describe('Actions Notes Store', () => { }, payload, ) - .then(data => { + .then((data) => { expect(data).toBe(res); expect(Flash).not.toHaveBeenCalled(); }) @@ -917,11 +914,10 @@ describe('Actions Notes Store', () => { .catch(done.fail); }; - it('when service success, commits and resolves discussion', done => { + it('when service success, commits and resolves discussion', (done) => { testSubmitSuggestion(done, () => { expect(commit.mock.calls).toEqual([ [mutationTypes.SET_RESOLVING_DISCUSSION, true], - [mutationTypes.APPLY_SUGGESTION, { discussionId, noteId, suggestionId }], [mutationTypes.SET_RESOLVING_DISCUSSION, false], ]); @@ -934,7 +930,7 @@ describe('Actions Notes Store', () => { }); }); - it('when service fails, flashes error message', done => { + it('when service fails, flashes error message', (done) => { const response = { response: { data: { message: TEST_ERROR_MESSAGE } } }; Api.applySuggestion.mockReturnValue(Promise.reject(response)); @@ -949,7 +945,7 @@ describe('Actions Notes Store', () => { }); }); - it('when service fails, and no error message available, uses default message', done => { + it('when service fails, and no error message available, uses default message', (done) => { const response = { response: 'foo' }; Api.applySuggestion.mockReturnValue(Promise.reject(response)); @@ -968,7 +964,7 @@ describe('Actions Notes Store', () => { }); }); - it('when resolve discussion fails, fail gracefully', done => { + it('when resolve discussion fails, fail gracefully', (done) => { dispatch.mockReturnValue(Promise.reject()); testSubmitSuggestion(done, () => { @@ -999,13 +995,11 @@ describe('Actions Notes Store', () => { .catch(done.fail); }; - it('when service succeeds, commits, resolves discussions, resets batch and applying batch state', done => { + it('when service succeeds, commits, resolves discussions, resets batch and applying batch state', (done) => { testSubmitSuggestionBatch(done, () => { expect(commit.mock.calls).toEqual([ [mutationTypes.SET_APPLYING_BATCH_STATE, true], [mutationTypes.SET_RESOLVING_DISCUSSION, true], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[0]], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[1]], [mutationTypes.CLEAR_SUGGESTION_BATCH], [mutationTypes.SET_APPLYING_BATCH_STATE, false], [mutationTypes.SET_RESOLVING_DISCUSSION, false], @@ -1022,7 +1016,7 @@ describe('Actions Notes Store', () => { }); }); - it('when service fails, flashes error message, resets applying batch state', done => { + it('when service fails, flashes error message, resets applying batch state', (done) => { const response = { response: { data: { message: TEST_ERROR_MESSAGE } } }; Api.applySuggestionBatch.mockReturnValue(Promise.reject(response)); @@ -1040,7 +1034,7 @@ describe('Actions Notes Store', () => { }); }); - it('when service fails, and no error message available, uses default message', done => { + it('when service fails, and no error message available, uses default message', (done) => { const response = { response: 'foo' }; Api.applySuggestionBatch.mockReturnValue(Promise.reject(response)); @@ -1062,15 +1056,13 @@ describe('Actions Notes Store', () => { }); }); - it('when resolve discussions fails, fails gracefully, resets batch and applying batch state', done => { + it('when resolve discussions fails, fails gracefully, resets batch and applying batch state', (done) => { dispatch.mockReturnValue(Promise.reject()); testSubmitSuggestionBatch(done, () => { expect(commit.mock.calls).toEqual([ [mutationTypes.SET_APPLYING_BATCH_STATE, true], [mutationTypes.SET_RESOLVING_DISCUSSION, true], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[0]], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[1]], [mutationTypes.CLEAR_SUGGESTION_BATCH], [mutationTypes.SET_APPLYING_BATCH_STATE, false], [mutationTypes.SET_RESOLVING_DISCUSSION, false], @@ -1084,7 +1076,7 @@ describe('Actions Notes Store', () => { describe('addSuggestionInfoToBatch', () => { const suggestionInfo = batchSuggestionsInfoMock[0]; - it("adds a suggestion's info to the current batch", done => { + it("adds a suggestion's info to the current batch", (done) => { testAction( actions.addSuggestionInfoToBatch, suggestionInfo, @@ -1099,7 +1091,7 @@ describe('Actions Notes Store', () => { describe('removeSuggestionInfoFromBatch', () => { const suggestionInfo = batchSuggestionsInfoMock[0]; - it("removes a suggestion's info the current batch", done => { + it("removes a suggestion's info the current batch", (done) => { testAction( actions.removeSuggestionInfoFromBatch, suggestionInfo.suggestionId, @@ -1139,7 +1131,7 @@ describe('Actions Notes Store', () => { }); describe('setDiscussionSortDirection', () => { - it('calls the correct mutation with the correct args', done => { + it('calls the correct mutation with the correct args', (done) => { testAction( actions.setDiscussionSortDirection, { direction: notesConstants.DESC, persist: false }, @@ -1157,7 +1149,7 @@ describe('Actions Notes Store', () => { }); describe('setSelectedCommentPosition', () => { - it('calls the correct mutation with the correct args', done => { + it('calls the correct mutation with the correct args', (done) => { testAction( actions.setSelectedCommentPosition, {}, @@ -1178,7 +1170,7 @@ describe('Actions Notes Store', () => { }; describe('if response contains no errors', () => { - it('dispatches requestDeleteDescriptionVersion', done => { + it('dispatches requestDeleteDescriptionVersion', (done) => { axiosMock.onDelete(endpoint).replyOnce(200); testAction( actions.softDeleteDescriptionVersion, @@ -1201,7 +1193,7 @@ describe('Actions Notes Store', () => { describe('if response contains errors', () => { const errorMessage = 'Request failed with status code 503'; - it('dispatches receiveDeleteDescriptionVersionError and throws an error', done => { + it('dispatches receiveDeleteDescriptionVersionError and throws an error', (done) => { axiosMock.onDelete(endpoint).replyOnce(503); testAction( actions.softDeleteDescriptionVersion, @@ -1236,7 +1228,7 @@ describe('Actions Notes Store', () => { }); describe('updateAssignees', () => { - it('update the assignees state', done => { + it('update the assignees state', (done) => { testAction( actions.updateAssignees, [userDataMock.id], @@ -1351,7 +1343,7 @@ describe('Actions Notes Store', () => { }); describe('updateDiscussionPosition', () => { - it('update the assignees state', done => { + it('update the assignees state', (done) => { const updatedPosition = { discussionId: 1, position: { test: true } }; testAction( actions.updateDiscussionPosition, |