Commit 8f646faf authored by Phil Hughes's avatar Phil Hughes

improved stored data

created reset action to reset stored merge requests
parent c7609650
...@@ -14,11 +14,13 @@ export const receiveMergeRequestsSuccess = ({ commit }, data) => ...@@ -14,11 +14,13 @@ export const receiveMergeRequestsSuccess = ({ commit }, data) =>
export const fetchMergeRequests = ({ dispatch, state }) => { export const fetchMergeRequests = ({ dispatch, state }) => {
dispatch('requestMergeRequests'); dispatch('requestMergeRequests');
Api.mergeRequests({ scope: state.scope, view: 'simple' }) Api.mergeRequests({ scope: state.scope, state: 'opened' })
.then(({ data }) => { .then(({ data }) => {
dispatch('receiveMergeRequestsSuccess', data); dispatch('receiveMergeRequestsSuccess', data);
}) })
.catch(() => dispatch('receiveMergeRequestsError')); .catch(() => dispatch('receiveMergeRequestsError'));
}; };
export const resetMergeRequests = ({ commit }) => commit(types.RESET_MERGE_REQUESTS);
export default () => {}; export default () => {};
export const REQUEST_MERGE_REQUESTS = 'REQUEST_MERGE_REQUESTS'; export const REQUEST_MERGE_REQUESTS = 'REQUEST_MERGE_REQUESTS';
export const RECEIVE_MERGE_REQUESTS_ERROR = 'RECEIVE_MERGE_REQUESTS_ERROR'; export const RECEIVE_MERGE_REQUESTS_ERROR = 'RECEIVE_MERGE_REQUESTS_ERROR';
export const RECEIVE_MERGE_REQUESTS_SUCCESS = 'RECEIVE_MERGE_REQUESTS_SUCCESS'; export const RECEIVE_MERGE_REQUESTS_SUCCESS = 'RECEIVE_MERGE_REQUESTS_SUCCESS';
export const RESET_MERGE_REQUESTS = 'RESET_MERGE_REQUESTS';
...@@ -10,8 +10,16 @@ export default { ...@@ -10,8 +10,16 @@ export default {
}, },
[types.RECEIVE_MERGE_REQUESTS_SUCCESS](state, data) { [types.RECEIVE_MERGE_REQUESTS_SUCCESS](state, data) {
state.mergeRequests = data.map(mergeRequest => ({ state.mergeRequests = data.map(mergeRequest => ({
id: mergeRequest.iid, id: mergeRequest.id,
iid: mergeRequest.iid,
title: mergeRequest.title, title: mergeRequest.title,
projectId: mergeRequest.project_id,
projectPathWithNamespace: mergeRequest.web_url
.replace(`${gon.gitlab_url}/`, '')
.replace(`/merge_requests/${mergeRequest.iid}`, ''),
})); }));
}, },
[types.RESET_MERGE_REQUESTS](state) {
state.mergeRequests = [];
},
}; };
...@@ -96,8 +96,10 @@ export const fullPipelinesResponse = { ...@@ -96,8 +96,10 @@ export const fullPipelinesResponse = {
export const mergeRequests = [ export const mergeRequests = [
{ {
id: 1,
iid: 1, iid: 1,
title: 'Test merge request', title: 'Test merge request',
project_id: 1, project_id: 1,
web_url: `${gl.TEST_HOST}/namespace/project-path/merge_requests/1`,
}, },
]; ];
...@@ -7,6 +7,7 @@ import actions, { ...@@ -7,6 +7,7 @@ import actions, {
receiveMergeRequestsError, receiveMergeRequestsError,
receiveMergeRequestsSuccess, receiveMergeRequestsSuccess,
fetchMergeRequests, fetchMergeRequests,
resetMergeRequests,
} from '~/ide/stores/modules/merge_requests/actions'; } from '~/ide/stores/modules/merge_requests/actions';
import { mergeRequests } from '../../../mock_data'; import { mergeRequests } from '../../../mock_data';
import testAction from '../../../../helpers/vuex_action_helper'; import testAction from '../../../../helpers/vuex_action_helper';
...@@ -93,7 +94,7 @@ describe('IDe merge requests actions', () => { ...@@ -93,7 +94,7 @@ describe('IDe merge requests actions', () => {
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), { expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: { params: {
scope: 'assigned-to-me', scope: 'assigned-to-me',
view: 'simple', state: 'opened',
}, },
}); });
}); });
...@@ -141,4 +142,17 @@ describe('IDe merge requests actions', () => { ...@@ -141,4 +142,17 @@ describe('IDe merge requests actions', () => {
}); });
}); });
}); });
describe('resetMergeRequests', () => {
it('commits reset', done => {
testAction(
resetMergeRequests,
null,
mockedState,
[{ type: types.RESET_MERGE_REQUESTS }],
[],
done,
);
});
});
}); });
...@@ -28,14 +28,28 @@ describe('IDE merge requests mutations', () => { ...@@ -28,14 +28,28 @@ describe('IDE merge requests mutations', () => {
describe(types.RECEIVE_MERGE_REQUESTS_SUCCESS, () => { describe(types.RECEIVE_MERGE_REQUESTS_SUCCESS, () => {
it('sets merge requests', () => { it('sets merge requests', () => {
gon.gitlab_url = gl.TEST_HOST;
mutations[types.RECEIVE_MERGE_REQUESTS_SUCCESS](mockedState, mergeRequests); mutations[types.RECEIVE_MERGE_REQUESTS_SUCCESS](mockedState, mergeRequests);
expect(mockedState.mergeRequests).toEqual([ expect(mockedState.mergeRequests).toEqual([
{ {
id: 1, id: 1,
iid: 1,
title: 'Test merge request', title: 'Test merge request',
projectId: 1,
projectPathWithNamespace: 'namespace/project-path',
}, },
]); ]);
}); });
}); });
describe(types.RESET_MERGE_REQUESTS, () => {
it('clears merge request array', () => {
mockedState.mergeRequests = ['test'];
mutations[types.RESET_MERGE_REQUESTS](mockedState);
expect(mockedState.mergeRequests).toEqual([]);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment