diff options
Diffstat (limited to 'spec/frontend/notes/stores/actions_spec.js')
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index 6b8d0790669..4681f3aa429 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -3,6 +3,7 @@ import AxiosMockAdapter from 'axios-mock-adapter'; import Api from '~/api'; import { deprecatedCreateFlash as Flash } from '~/flash'; import * as actions from '~/notes/stores/actions'; +import mutations from '~/notes/stores/mutations'; import * as mutationTypes from '~/notes/stores/mutation_types'; import * as notesConstants from '~/notes/constants'; import createStore from '~/notes/stores'; @@ -334,6 +335,9 @@ describe('Actions Notes Store', () => { it('calls service with last fetched state', done => { store .dispatch('poll') + .then(() => { + jest.advanceTimersByTime(2); + }) .then(() => new Promise(resolve => requestAnimationFrame(resolve))) .then(() => { expect(store.state.lastFetchedAt).toBe('123456'); @@ -651,6 +655,26 @@ describe('Actions Notes Store', () => { }); describe('updateOrCreateNotes', () => { + it('Prevents `fetchDiscussions` being called multiple times within time limit', () => { + jest.useFakeTimers(); + const note = { id: 1234, type: notesConstants.DIFF_NOTE }; + const getters = { notesById: {} }; + state = { discussions: [note], notesData: { discussionsPath: '' } }; + commit.mockImplementation((type, value) => { + if (type === mutationTypes.SET_FETCHING_DISCUSSIONS) { + mutations[type](state, value); + } + }); + + actions.updateOrCreateNotes({ commit, state, getters, dispatch }, [note]); + actions.updateOrCreateNotes({ commit, state, getters, dispatch }, [note]); + + jest.runAllTimers(); + actions.updateOrCreateNotes({ commit, state, getters, dispatch }, [note]); + + expect(dispatch).toHaveBeenCalledTimes(2); + }); + it('Updates existing note', () => { const note = { id: 1234 }; const getters = { notesById: { 1234: note } }; |