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 }) => {
export const receiveMergeRequestsSuccess = ({ commit }, data) =>
commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, data);
export const fetchMergeRequests = ({ dispatch, state }) => {
export const fetchMergeRequests = ({ dispatch, state: { scope, state } }, search = '') => {
dispatch('requestMergeRequests');
dispatch('resetMergeRequests');
Api.mergeRequests({ scope: state.scope, state: 'opened' })
.then(({ data }) => {
dispatch('receiveMergeRequestsSuccess', data);
})
Api.mergeRequests({ scope, state, search })
.then(({ data }) => dispatch('receiveMergeRequestsSuccess', data))
.catch(() => dispatch('receiveMergeRequestsError'));
};
......
// eslint-disable-next-line import/prefer-default-export
export const scopes = {
assignedToMe: 'assigned-to-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 () => ({
isLoading: false,
mergeRequests: [],
scope: scopes.assignedToMe,
state: states.opened,
});
......@@ -12,7 +12,7 @@ import actions, {
import { mergeRequests } from '../../../mock_data';
import testAction from '../../../../helpers/vuex_action_helper';
describe('IDe merge requests actions', () => {
describe('IDE merge requests actions', () => {
let mockedState;
let mock;
......@@ -95,6 +95,21 @@ describe('IDe merge requests actions', () => {
params: {
scope: 'assigned-to-me',
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', () => {
null,
mockedState,
[],
[{ type: 'requestMergeRequests' }, { type: 'receiveMergeRequestsSuccess' }],
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsSuccess' },
],
done,
);
});
......@@ -118,6 +137,7 @@ describe('IDe merge requests actions', () => {
[],
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsSuccess', payload: mergeRequests },
],
done,
......@@ -136,7 +156,11 @@ describe('IDe merge requests actions', () => {
null,
mockedState,
[],
[{ type: 'requestMergeRequests' }, { type: 'receiveMergeRequestsError' }],
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsError' },
],
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