diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-24 15:09:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-24 15:09:32 +0300 |
commit | a46b489e175708cc64fc5198f458f927558f11ba (patch) | |
tree | 96bb3be8fa37d729d1417b4e91df0bf718039911 /spec/frontend/mr_notes | |
parent | bd818d0618b0c1316c23f47f9ae41449e5d41fa8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/mr_notes')
-rw-r--r-- | spec/frontend/mr_notes/stores/actions_spec.js | 69 | ||||
-rw-r--r-- | spec/frontend/mr_notes/stores/mutations_spec.js | 12 |
2 files changed, 80 insertions, 1 deletions
diff --git a/spec/frontend/mr_notes/stores/actions_spec.js b/spec/frontend/mr_notes/stores/actions_spec.js index dbceedface1..c6578453d85 100644 --- a/spec/frontend/mr_notes/stores/actions_spec.js +++ b/spec/frontend/mr_notes/stores/actions_spec.js @@ -1,5 +1,9 @@ +import MockAdapter from 'axios-mock-adapter'; + import testAction from 'helpers/vuex_action_helper'; -import { setEndpoints } from '~/mr_notes/stores/actions'; +import axios from '~/lib/utils/axios_utils'; + +import { setEndpoints, setMrMetadata, fetchMrMetadata } from '~/mr_notes/stores/actions'; import mutationTypes from '~/mr_notes/stores/mutation_types'; describe('MR Notes Mutator Actions', () => { @@ -22,4 +26,67 @@ describe('MR Notes Mutator Actions', () => { ); }); }); + + describe('setMrMetadata', () => { + it('should trigger the SET_MR_METADATA state mutation', async () => { + const mrMetadata = { propA: 'a', propB: 'b' }; + + await testAction( + setMrMetadata, + mrMetadata, + {}, + [ + { + type: mutationTypes.SET_MR_METADATA, + payload: mrMetadata, + }, + ], + [], + ); + }); + }); + + describe('fetchMrMetadata', () => { + const mrMetadata = { meta: true, data: 'foo' }; + const state = { + endpoints: { + metadata: 'metadata', + }, + }; + let mock; + + beforeEach(() => { + mock = new MockAdapter(axios); + + mock.onGet(state.endpoints.metadata).reply(200, mrMetadata); + }); + + afterEach(() => { + mock.restore(); + }); + + it('should fetch the data from the API', async () => { + await fetchMrMetadata({ state, dispatch: () => {} }); + + await axios.waitForAll(); + + expect(mock.history.get).toHaveLength(1); + expect(mock.history.get[0].url).toBe(state.endpoints.metadata); + }); + + it('should set the fetched data into state', () => { + return testAction( + fetchMrMetadata, + {}, + state, + [], + [ + { + type: 'setMrMetadata', + payload: mrMetadata, + }, + ], + ); + }); + }); }); diff --git a/spec/frontend/mr_notes/stores/mutations_spec.js b/spec/frontend/mr_notes/stores/mutations_spec.js index 422db3d5a38..35b8a2e4be2 100644 --- a/spec/frontend/mr_notes/stores/mutations_spec.js +++ b/spec/frontend/mr_notes/stores/mutations_spec.js @@ -12,4 +12,16 @@ describe('MR Notes Mutations', () => { expect(state.endpoints).toEqual(endpoints); }); }); + + describe(mutationTypes.SET_MR_METADATA, () => { + it('store the provided MR Metadata in the state', () => { + const state = {}; + const metadata = { propA: 'A', propB: 'B' }; + + mutations[mutationTypes.SET_MR_METADATA](state, metadata); + + expect(state.mrMetadata.propA).toBe('A'); + expect(state.mrMetadata.propB).toBe('B'); + }); + }); }); |