diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/frontend/mr_notes/stores/actions_spec.js | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/frontend/mr_notes/stores/actions_spec.js')
-rw-r--r-- | spec/frontend/mr_notes/stores/actions_spec.js | 88 |
1 files changed, 30 insertions, 58 deletions
diff --git a/spec/frontend/mr_notes/stores/actions_spec.js b/spec/frontend/mr_notes/stores/actions_spec.js index c6578453d85..568c1b930c9 100644 --- a/spec/frontend/mr_notes/stores/actions_spec.js +++ b/spec/frontend/mr_notes/stores/actions_spec.js @@ -1,64 +1,37 @@ import MockAdapter from 'axios-mock-adapter'; - -import testAction from 'helpers/vuex_action_helper'; import axios from '~/lib/utils/axios_utils'; -import { setEndpoints, setMrMetadata, fetchMrMetadata } from '~/mr_notes/stores/actions'; -import mutationTypes from '~/mr_notes/stores/mutation_types'; +import { createStore } from '~/mr_notes/stores'; describe('MR Notes Mutator Actions', () => { + let store; + + beforeEach(() => { + store = createStore(); + }); + describe('setEndpoints', () => { - it('should trigger the SET_ENDPOINTS state mutation', (done) => { + it('sets endpoints', async () => { const endpoints = { endpointA: 'a' }; - testAction( - setEndpoints, - endpoints, - {}, - [ - { - type: mutationTypes.SET_ENDPOINTS, - payload: endpoints, - }, - ], - [], - done, - ); - }); - }); + await store.dispatch('setEndpoints', endpoints); - 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, - }, - ], - [], - ); + expect(store.state.page.endpoints).toEqual(endpoints); }); }); describe('fetchMrMetadata', () => { const mrMetadata = { meta: true, data: 'foo' }; - const state = { - endpoints: { - metadata: 'metadata', - }, - }; + const metadata = 'metadata'; + const endpoints = { metadata }; let mock; - beforeEach(() => { + beforeEach(async () => { + await store.dispatch('setEndpoints', endpoints); + mock = new MockAdapter(axios); - mock.onGet(state.endpoints.metadata).reply(200, mrMetadata); + mock.onGet(metadata).reply(200, mrMetadata); }); afterEach(() => { @@ -66,27 +39,26 @@ describe('MR Notes Mutator Actions', () => { }); it('should fetch the data from the API', async () => { - await fetchMrMetadata({ state, dispatch: () => {} }); + await store.dispatch('fetchMrMetadata'); await axios.waitForAll(); expect(mock.history.get).toHaveLength(1); - expect(mock.history.get[0].url).toBe(state.endpoints.metadata); + expect(mock.history.get[0].url).toBe(metadata); + }); + + it('should set the fetched data into state', async () => { + await store.dispatch('fetchMrMetadata'); + + expect(store.state.page.mrMetadata).toEqual(mrMetadata); }); - it('should set the fetched data into state', () => { - return testAction( - fetchMrMetadata, - {}, - state, - [], - [ - { - type: 'setMrMetadata', - payload: mrMetadata, - }, - ], - ); + it('should set failedToLoadMetadata flag when request fails', async () => { + mock.onGet(metadata).reply(500); + + await store.dispatch('fetchMrMetadata'); + + expect(store.state.page.failedToLoadMetadata).toBe(true); }); }); }); |