Commit 3bffbb15 authored by Phil Hughes's avatar Phil Hughes

ability to search merge requests

reset merge requests before fetch
parent 8f646faf
...@@ -11,13 +11,12 @@ export const receiveMergeRequestsError = ({ commit }) => { ...@@ -11,13 +11,12 @@ export const receiveMergeRequestsError = ({ commit }) => {
export const receiveMergeRequestsSuccess = ({ commit }, data) => export const receiveMergeRequestsSuccess = ({ commit }, data) =>
commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, data); commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, data);
export const fetchMergeRequests = ({ dispatch, state }) => { export const fetchMergeRequests = ({ dispatch, state: { scope, state } }, search = '') => {
dispatch('requestMergeRequests'); dispatch('requestMergeRequests');
dispatch('resetMergeRequests');
Api.mergeRequests({ scope: state.scope, state: 'opened' }) Api.mergeRequests({ scope, state, search })
.then(({ data }) => { .then(({ data }) => dispatch('receiveMergeRequestsSuccess', data))
dispatch('receiveMergeRequestsSuccess', data);
})
.catch(() => dispatch('receiveMergeRequestsError')); .catch(() => dispatch('receiveMergeRequestsError'));
}; };
......
// eslint-disable-next-line import/prefer-default-export
export const scopes = { export const scopes = {
assignedToMe: 'assigned-to-me', assignedToMe: 'assigned-to-me',
createdByMe: 'created-by-me', createdByMe: 'created-by-me',
}; };
export const states = {
opened: 'opened',
closed: 'closed',
merged: 'merged',
};
import { scopes } from './constants'; import { scopes, states } from './constants';
export default () => ({ export default () => ({
isLoading: false, isLoading: false,
mergeRequests: [], mergeRequests: [],
scope: scopes.assignedToMe, scope: scopes.assignedToMe,
state: states.opened,
}); });
...@@ -12,7 +12,7 @@ import actions, { ...@@ -12,7 +12,7 @@ import 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';
describe('IDe merge requests actions', () => { describe('IDE merge requests actions', () => {
let mockedState; let mockedState;
let mock; let mock;
...@@ -95,6 +95,21 @@ describe('IDe merge requests actions', () => { ...@@ -95,6 +95,21 @@ describe('IDe merge requests actions', () => {
params: { params: {
scope: 'assigned-to-me', scope: 'assigned-to-me',
state: 'opened', state: 'opened',
search: '',
},
});
});
it('calls API with search', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchMergeRequests({ dispatch() {}, state: mockedState }, 'testing search');
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: {
scope: 'assigned-to-me',
state: 'opened',
search: 'testing search',
}, },
}); });
}); });
...@@ -105,7 +120,11 @@ describe('IDe merge requests actions', () => { ...@@ -105,7 +120,11 @@ describe('IDe merge requests actions', () => {
null, null,
mockedState, mockedState,
[], [],
[{ type: 'requestMergeRequests' }, { type: 'receiveMergeRequestsSuccess' }], [
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsSuccess' },
],
done, done,
); );
}); });
...@@ -118,6 +137,7 @@ describe('IDe merge requests actions', () => { ...@@ -118,6 +137,7 @@ describe('IDe merge requests actions', () => {
[], [],
[ [
{ type: 'requestMergeRequests' }, { type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsSuccess', payload: mergeRequests }, { type: 'receiveMergeRequestsSuccess', payload: mergeRequests },
], ],
done, done,
...@@ -136,7 +156,11 @@ describe('IDe merge requests actions', () => { ...@@ -136,7 +156,11 @@ describe('IDe merge requests actions', () => {
null, null,
mockedState, mockedState,
[], [],
[{ type: 'requestMergeRequests' }, { type: 'receiveMergeRequestsError' }], [
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsError' },
],
done, done,
); );
}); });
......
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