Commit f8d8b63f authored by Phil Hughes's avatar Phil Hughes

fixed karma

parent d644798f
...@@ -34,10 +34,9 @@ export const openMergeRequest = ({ commit, dispatch }, { projectPath, id }) => { ...@@ -34,10 +34,9 @@ export const openMergeRequest = ({ commit, dispatch }, { projectPath, id }) => {
dispatch('pipelines/stopPipelinePolling', null, { root: true }); dispatch('pipelines/stopPipelinePolling', null, { root: true });
dispatch('pipelines/clearEtagPoll', null, { root: true }); dispatch('pipelines/clearEtagPoll', null, { root: true });
dispatch('pipelines/resetLatestPipeline', null, { root: true }); dispatch('pipelines/resetLatestPipeline', null, { root: true });
dispatch('setCurrentBranchId', '', { root: true });
return dispatch('setCurrentBranchId', '', { root: true }).then(() => router.push(`/project/${projectPath}/merge_requests/${id}`);
router.push(`/project/${projectPath}/merge_requests/${id}`),
);
}; };
export default () => {}; export default () => {};
...@@ -8,7 +8,9 @@ import actions, { ...@@ -8,7 +8,9 @@ import actions, {
receiveMergeRequestsSuccess, receiveMergeRequestsSuccess,
fetchMergeRequests, fetchMergeRequests,
resetMergeRequests, resetMergeRequests,
openMergeRequest,
} from '~/ide/stores/modules/merge_requests/actions'; } from '~/ide/stores/modules/merge_requests/actions';
import router from '~/ide/ide_router';
import { mergeRequests } from '../../../mock_data'; import { mergeRequests } from '../../../mock_data';
import testAction from '../../../../helpers/vuex_action_helper'; import testAction from '../../../../helpers/vuex_action_helper';
...@@ -29,9 +31,9 @@ describe('IDE merge requests actions', () => { ...@@ -29,9 +31,9 @@ describe('IDE merge requests actions', () => {
it('should should commit request', done => { it('should should commit request', done => {
testAction( testAction(
requestMergeRequests, requestMergeRequests,
null, 'created',
mockedState, mockedState,
[{ type: types.REQUEST_MERGE_REQUESTS }], [{ type: types.REQUEST_MERGE_REQUESTS, payload: 'created' }],
[], [],
done, done,
); );
...@@ -48,16 +50,16 @@ describe('IDE merge requests actions', () => { ...@@ -48,16 +50,16 @@ describe('IDE merge requests actions', () => {
it('should should commit error', done => { it('should should commit error', done => {
testAction( testAction(
receiveMergeRequestsError, receiveMergeRequestsError,
null, 'created',
mockedState, mockedState,
[{ type: types.RECEIVE_MERGE_REQUESTS_ERROR }], [{ type: types.RECEIVE_MERGE_REQUESTS_ERROR, payload: 'created' }],
[], [],
done, done,
); );
}); });
it('creates flash message', () => { it('creates flash message', () => {
receiveMergeRequestsError({ commit() {} }); receiveMergeRequestsError({ commit() {} }, 'created');
expect(flashSpy).toHaveBeenCalled(); expect(flashSpy).toHaveBeenCalled();
}); });
...@@ -67,9 +69,14 @@ describe('IDE merge requests actions', () => { ...@@ -67,9 +69,14 @@ describe('IDE merge requests actions', () => {
it('should commit received data', done => { it('should commit received data', done => {
testAction( testAction(
receiveMergeRequestsSuccess, receiveMergeRequestsSuccess,
'data', { type: 'created', data: 'data' },
mockedState, mockedState,
[{ type: types.RECEIVE_MERGE_REQUESTS_SUCCESS, payload: 'data' }], [
{
type: types.RECEIVE_MERGE_REQUESTS_SUCCESS,
payload: { type: 'created', data: 'data' },
},
],
[], [],
done, done,
); );
...@@ -86,14 +93,14 @@ describe('IDE merge requests actions', () => { ...@@ -86,14 +93,14 @@ describe('IDE merge requests actions', () => {
mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(200, mergeRequests); mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(200, mergeRequests);
}); });
it('calls API with params from state', () => { it('calls API with params', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchMergeRequests({ dispatch() {}, state: mockedState }); fetchMergeRequests({ dispatch() {}, state: mockedState }, { type: 'created' });
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), { expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: { params: {
scope: 'assigned-to-me', scope: 'created-by-me',
state: 'opened', state: 'opened',
search: '', search: '',
}, },
...@@ -103,11 +110,14 @@ describe('IDE merge requests actions', () => { ...@@ -103,11 +110,14 @@ describe('IDE merge requests actions', () => {
it('calls API with search', () => { it('calls API with search', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchMergeRequests({ dispatch() {}, state: mockedState }, 'testing search'); fetchMergeRequests(
{ dispatch() {}, state: mockedState },
{ type: 'created', search: 'testing search' },
);
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), { expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: { params: {
scope: 'assigned-to-me', scope: 'created-by-me',
state: 'opened', state: 'opened',
search: 'testing search', search: 'testing search',
}, },
...@@ -117,7 +127,7 @@ describe('IDE merge requests actions', () => { ...@@ -117,7 +127,7 @@ describe('IDE merge requests actions', () => {
it('dispatches request', done => { it('dispatches request', done => {
testAction( testAction(
fetchMergeRequests, fetchMergeRequests,
null, { type: 'created' },
mockedState, mockedState,
[], [],
[ [
...@@ -132,13 +142,16 @@ describe('IDE merge requests actions', () => { ...@@ -132,13 +142,16 @@ describe('IDE merge requests actions', () => {
it('dispatches success with received data', done => { it('dispatches success with received data', done => {
testAction( testAction(
fetchMergeRequests, fetchMergeRequests,
null, { type: 'created' },
mockedState, mockedState,
[], [],
[ [
{ type: 'requestMergeRequests' }, { type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' }, { type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsSuccess', payload: mergeRequests }, {
type: 'receiveMergeRequestsSuccess',
payload: { type: 'created', data: mergeRequests },
},
], ],
done, done,
); );
...@@ -153,7 +166,7 @@ describe('IDE merge requests actions', () => { ...@@ -153,7 +166,7 @@ describe('IDE merge requests actions', () => {
it('dispatches error', done => { it('dispatches error', done => {
testAction( testAction(
fetchMergeRequests, fetchMergeRequests,
null, { type: 'created' },
mockedState, mockedState,
[], [],
[ [
...@@ -171,12 +184,47 @@ describe('IDE merge requests actions', () => { ...@@ -171,12 +184,47 @@ describe('IDE merge requests actions', () => {
it('commits reset', done => { it('commits reset', done => {
testAction( testAction(
resetMergeRequests, resetMergeRequests,
null, 'created',
mockedState, mockedState,
[{ type: types.RESET_MERGE_REQUESTS }], [{ type: types.RESET_MERGE_REQUESTS, payload: 'created' }],
[], [],
done, done,
); );
}); });
}); });
describe('openMergeRequest', () => {
beforeEach(() => {
spyOn(router, 'push');
});
it('commits reset mutations and actions', done => {
testAction(
openMergeRequest,
{ projectPath: 'gitlab-org/gitlab-ce', id: '1' },
mockedState,
[
{ type: 'CLEAR_PROJECTS' },
{ type: 'SET_CURRENT_MERGE_REQUEST', payload: '1' },
{ type: 'RESET_OPEN_FILES' },
],
[
{ type: 'pipelines/stopPipelinePolling' },
{ type: 'pipelines/clearEtagPoll' },
{ type: 'pipelines/resetLatestPipeline' },
{ type: 'setCurrentBranchId', payload: '' },
],
done,
);
});
it('pushes new route', () => {
openMergeRequest(
{ commit() {}, dispatch() {} },
{ projectPath: 'gitlab-org/gitlab-ce', id: '1' },
);
expect(router.push).toHaveBeenCalledWith('/project/gitlab-org/gitlab-ce/merge_requests/1');
});
});
}); });
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