Commit 7942ba3e authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Additional clean up for existing specs

Minor fixes and cleanup for the
cycle analytics store specs

Fix base_spec tests
parent 13d0fd61
...@@ -133,16 +133,19 @@ export const setDefaultSelectedStage = ({ dispatch, getters }) => { ...@@ -133,16 +133,19 @@ export const setDefaultSelectedStage = ({ dispatch, getters }) => {
const { activeStages = [] } = getters; const { activeStages = [] } = getters;
if (activeStages && activeStages.length) { if (activeStages && activeStages.length) {
const [firstActiveStage] = activeStages; const [firstActiveStage] = activeStages;
dispatch('setSelectedStage', firstActiveStage); return Promise.all([
dispatch('fetchStageData', firstActiveStage.slug); dispatch('setSelectedStage', firstActiveStage),
} else { dispatch('fetchStageData', firstActiveStage.slug),
createFlash(__('There was an error while fetching value stream analytics data.')); ]);
} }
createFlash(__('There was an error while fetching value stream analytics data.'));
return Promise.resolve();
}; };
export const receiveGroupStagesSuccess = ({ commit, dispatch }, stages) => { export const receiveGroupStagesSuccess = ({ commit, dispatch }, stages) => {
commit(types.RECEIVE_GROUP_STAGES_SUCCESS, stages); commit(types.RECEIVE_GROUP_STAGES_SUCCESS, stages);
dispatch('setDefaultSelectedStage'); return dispatch('setDefaultSelectedStage');
}; };
export const fetchGroupStagesAndEvents = ({ state, dispatch, getters }) => { export const fetchGroupStagesAndEvents = ({ state, dispatch, getters }) => {
...@@ -197,8 +200,8 @@ export const receiveUpdateStageError = ( ...@@ -197,8 +200,8 @@ export const receiveUpdateStageError = (
? sprintf(__(`'%{name}' stage already exists`), { name }) ? sprintf(__(`'%{name}' stage already exists`), { name })
: __('There was a problem saving your custom stage, please try again'); : __('There was a problem saving your custom stage, please try again');
dispatch('customStages/setStageFormErrors', errors);
createFlash(__(message)); createFlash(__(message));
return dispatch('customStages/setStageFormErrors', errors);
}; };
export const updateStage = ({ dispatch, state }, { id, ...rest }) => { export const updateStage = ({ dispatch, state }, { id, ...rest }) => {
...@@ -219,7 +222,7 @@ export const requestRemoveStage = ({ commit }) => commit(types.REQUEST_REMOVE_ST ...@@ -219,7 +222,7 @@ export const requestRemoveStage = ({ commit }) => commit(types.REQUEST_REMOVE_ST
export const receiveRemoveStageSuccess = ({ commit, dispatch }) => { export const receiveRemoveStageSuccess = ({ commit, dispatch }) => {
commit(types.RECEIVE_REMOVE_STAGE_RESPONSE); commit(types.RECEIVE_REMOVE_STAGE_RESPONSE);
createFlash(__('Stage removed'), 'notice'); createFlash(__('Stage removed'), 'notice');
dispatch('fetchCycleAnalyticsData'); return dispatch('fetchCycleAnalyticsData');
}; };
export const receiveRemoveStageError = ({ commit }) => { export const receiveRemoveStageError = ({ commit }) => {
......
...@@ -60,9 +60,8 @@ export const receiveCreateStageSuccess = ({ commit, dispatch }, { data: { title ...@@ -60,9 +60,8 @@ export const receiveCreateStageSuccess = ({ commit, dispatch }, { data: { title
createFlash(sprintf(__(`Your custom stage '%{title}' was created`), { title }), 'notice'); createFlash(sprintf(__(`Your custom stage '%{title}' was created`), { title }), 'notice');
return Promise.resolve() return Promise.resolve()
.then(() => dispatch('fetchGroupStagesAndEvents')) .then(() => dispatch('fetchGroupStagesAndEvents', null, { root: true }))
.catch(err => { .catch(() => {
console.log('err', err);
createFlash(__('There was a problem refreshing the data, please try again')); createFlash(__('There was a problem refreshing the data, please try again'));
}); });
}; };
...@@ -78,14 +77,15 @@ export const receiveCreateStageError = ( ...@@ -78,14 +77,15 @@ export const receiveCreateStageError = (
? sprintf(__(`'%{name}' stage already exists`), { name }) ? sprintf(__(`'%{name}' stage already exists`), { name })
: __('There was a problem saving your custom stage, please try again'); : __('There was a problem saving your custom stage, please try again');
dispatch('setStageFormErrors', errors);
createFlash(flashMessage); createFlash(flashMessage);
return dispatch('setStageFormErrors', errors);
}; };
export const createStage = ({ dispatch, state }, data) => { export const createStage = ({ dispatch, rootState }, data) => {
const { const {
selectedGroup: { fullPath }, selectedGroup: { fullPath },
} = state; } = rootState;
dispatch('requestCreateStage'); dispatch('requestCreateStage');
return Api.cycleAnalyticsCreateStage(fullPath, data) return Api.cycleAnalyticsCreateStage(fullPath, data)
......
...@@ -85,9 +85,10 @@ function createComponent({ ...@@ -85,9 +85,10 @@ function createComponent({
...selectedGroup, ...selectedGroup,
}); });
comp.vm.$store.dispatch('receiveGroupStagesSuccess', { comp.vm.$store.dispatch(
...mockData.customizableStagesAndEvents.stages, 'receiveGroupStagesSuccess',
}); mockData.customizableStagesAndEvents.stages,
);
comp.vm.$store.dispatch('receiveStageDataSuccess', mockData.issueEvents); comp.vm.$store.dispatch('receiveStageDataSuccess', mockData.issueEvents);
} }
......
...@@ -16,7 +16,6 @@ import { ...@@ -16,7 +16,6 @@ import {
customizableStagesAndEvents, customizableStagesAndEvents,
endpoints, endpoints,
} from '../mock_data'; } from '../mock_data';
import { shouldFlashAMessage } from '../helpers';
const stageData = { events: [] }; const stageData = { events: [] };
const error = new Error(`Request failed with status code ${httpStatusCodes.NOT_FOUND}`); const error = new Error(`Request failed with status code ${httpStatusCodes.NOT_FOUND}`);
...@@ -27,10 +26,17 @@ const selectedStageSlug = selectedStage.slug; ...@@ -27,10 +26,17 @@ const selectedStageSlug = selectedStage.slug;
const stageEndpoint = ({ stageId }) => const stageEndpoint = ({ stageId }) =>
`/groups/${selectedGroup.fullPath}/-/analytics/value_stream_analytics/stages/${stageId}`; `/groups/${selectedGroup.fullPath}/-/analytics/value_stream_analytics/stages/${stageId}`;
jest.mock('~/flash');
describe('Cycle analytics actions', () => { describe('Cycle analytics actions', () => {
let state; let state;
let mock; let mock;
const shouldFlashAMessage = (msg, type = null) => {
const args = type ? [msg, type] : [msg];
expect(createFlash).toHaveBeenCalledWith(...args);
};
beforeEach(() => { beforeEach(() => {
state = { state = {
startDate, startDate,
...@@ -74,14 +80,13 @@ describe('Cycle analytics actions', () => { ...@@ -74,14 +80,13 @@ describe('Cycle analytics actions', () => {
describe('setDateRange', () => { describe('setDateRange', () => {
const payload = { startDate, endDate }; const payload = { startDate, endDate };
it('dispatches the fetchCycleAnalyticsData action', done => { it('dispatches the fetchCycleAnalyticsData action', () => {
testAction( return testAction(
actions.setDateRange, actions.setDateRange,
payload, payload,
state, state,
[{ type: types.SET_DATE_RANGE, payload: { startDate, endDate } }], [{ type: types.SET_DATE_RANGE, payload: { startDate, endDate } }],
[{ type: 'fetchCycleAnalyticsData' }], [{ type: 'fetchCycleAnalyticsData' }],
done,
); );
}); });
}); });
...@@ -93,8 +98,8 @@ describe('Cycle analytics actions', () => { ...@@ -93,8 +98,8 @@ describe('Cycle analytics actions', () => {
mock.onGet(endpoints.stageData).reply(200, { events: [] }); mock.onGet(endpoints.stageData).reply(200, { events: [] });
}); });
it('dispatches receiveStageDataSuccess with received data on success', done => { it('dispatches receiveStageDataSuccess with received data on success', () => {
testAction( return testAction(
actions.fetchStageData, actions.fetchStageData,
selectedStageSlug, selectedStageSlug,
state, state,
...@@ -106,7 +111,6 @@ describe('Cycle analytics actions', () => { ...@@ -106,7 +111,6 @@ describe('Cycle analytics actions', () => {
payload: { events: [] }, payload: { events: [] },
}, },
], ],
done,
); );
}); });
...@@ -116,8 +120,8 @@ describe('Cycle analytics actions', () => { ...@@ -116,8 +120,8 @@ describe('Cycle analytics actions', () => {
mock.onGet(endpoints.stageData).replyOnce(httpStatusCodes.NOT_FOUND, { error }); mock.onGet(endpoints.stageData).replyOnce(httpStatusCodes.NOT_FOUND, { error });
}); });
it('dispatches receiveStageDataError on error', done => { it('dispatches receiveStageDataError on error', () => {
testAction( return testAction(
actions.fetchStageData, actions.fetchStageData,
selectedStage, selectedStage,
state, state,
...@@ -131,29 +135,25 @@ describe('Cycle analytics actions', () => { ...@@ -131,29 +135,25 @@ describe('Cycle analytics actions', () => {
payload: error, payload: error,
}, },
], ],
done,
); );
}); });
}); });
describe('receiveStageDataSuccess', () => { describe('receiveStageDataSuccess', () => {
it(`commits the ${types.RECEIVE_STAGE_DATA_SUCCESS} mutation`, done => { it(`commits the ${types.RECEIVE_STAGE_DATA_SUCCESS} mutation`, () => {
testAction( return testAction(
actions.receiveStageDataSuccess, actions.receiveStageDataSuccess,
{ ...stageData }, { ...stageData },
state, state,
[{ type: types.RECEIVE_STAGE_DATA_SUCCESS, payload: { events: [] } }], [{ type: types.RECEIVE_STAGE_DATA_SUCCESS, payload: { events: [] } }],
[], [],
done,
); );
}); });
}); });
}); });
describe('receiveStageDataError', () => { describe('receiveStageDataError', () => {
beforeEach(() => { beforeEach(() => {});
setFixtures('<div class="flash-container"></div>');
});
it(`commits the ${types.RECEIVE_STAGE_DATA_ERROR} mutation`, () => { it(`commits the ${types.RECEIVE_STAGE_DATA_ERROR} mutation`, () => {
return testAction( return testAction(
actions.receiveStageDataError, actions.receiveStageDataError,
...@@ -169,10 +169,7 @@ describe('Cycle analytics actions', () => { ...@@ -169,10 +169,7 @@ describe('Cycle analytics actions', () => {
}); });
it('will flash an error message', () => { it('will flash an error message', () => {
actions.receiveStageDataError({ actions.receiveStageDataError({ commit: () => {} });
commit: () => {},
});
shouldFlashAMessage('There was an error fetching data for the selected stage'); shouldFlashAMessage('There was an error fetching data for the selected stage');
}); });
}); });
...@@ -200,11 +197,10 @@ describe('Cycle analytics actions', () => { ...@@ -200,11 +197,10 @@ describe('Cycle analytics actions', () => {
} }
beforeEach(() => { beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
state = { ...state, selectedGroup, startDate, endDate }; state = { ...state, selectedGroup, startDate, endDate };
}); });
it(`dispatches actions for required value stream analytics analytics data`, done => { it(`dispatches actions for required value stream analytics analytics data`, () => {
testAction( testAction(
actions.fetchCycleAnalyticsData, actions.fetchCycleAnalyticsData,
state, state,
...@@ -216,11 +212,10 @@ describe('Cycle analytics actions', () => { ...@@ -216,11 +212,10 @@ describe('Cycle analytics actions', () => {
{ type: 'fetchStageMedianValues' }, { type: 'fetchStageMedianValues' },
{ type: 'receiveCycleAnalyticsDataSuccess' }, { type: 'receiveCycleAnalyticsDataSuccess' },
], ],
done,
); );
}); });
it(`displays an error if fetchStageMedianValues fails`, done => { it(`displays an error if fetchStageMedianValues fails`, () => {
const { mockDispatchContext } = mockFetchCycleAnalyticsAction({ const { mockDispatchContext } = mockFetchCycleAnalyticsAction({
fetchStageMedianValues: actions.fetchStageMedianValues({ fetchStageMedianValues: actions.fetchStageMedianValues({
dispatch: jest dispatch: jest
...@@ -233,7 +228,7 @@ describe('Cycle analytics actions', () => { ...@@ -233,7 +228,7 @@ describe('Cycle analytics actions', () => {
}), }),
}); });
actions return actions
.fetchCycleAnalyticsData({ .fetchCycleAnalyticsData({
dispatch: mockDispatchContext, dispatch: mockDispatchContext,
state: {}, state: {},
...@@ -241,12 +236,10 @@ describe('Cycle analytics actions', () => { ...@@ -241,12 +236,10 @@ describe('Cycle analytics actions', () => {
}) })
.then(() => { .then(() => {
shouldFlashAMessage('There was an error fetching median data for stages'); shouldFlashAMessage('There was an error fetching median data for stages');
done(); });
})
.catch(done.fail);
}); });
it(`displays an error if fetchGroupStagesAndEvents fails`, done => { it(`displays an error if fetchGroupStagesAndEvents fails`, () => {
const { mockDispatchContext } = mockFetchCycleAnalyticsAction({ const { mockDispatchContext } = mockFetchCycleAnalyticsAction({
fetchGroupStagesAndEvents: actions.fetchGroupStagesAndEvents({ fetchGroupStagesAndEvents: actions.fetchGroupStagesAndEvents({
dispatch: jest dispatch: jest
...@@ -259,7 +252,7 @@ describe('Cycle analytics actions', () => { ...@@ -259,7 +252,7 @@ describe('Cycle analytics actions', () => {
}), }),
}); });
actions return actions
.fetchCycleAnalyticsData({ .fetchCycleAnalyticsData({
dispatch: mockDispatchContext, dispatch: mockDispatchContext,
state: {}, state: {},
...@@ -267,61 +260,16 @@ describe('Cycle analytics actions', () => { ...@@ -267,61 +260,16 @@ describe('Cycle analytics actions', () => {
}) })
.then(() => { .then(() => {
shouldFlashAMessage('There was an error fetching value stream analytics stages.'); shouldFlashAMessage('There was an error fetching value stream analytics stages.');
done(); });
})
.catch(done.fail);
});
describe('with an existing error', () => {
beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
});
it('removes an existing flash error if present', () => {
const { mockDispatchContext } = mockFetchCycleAnalyticsAction();
createFlash(flashErrorMessage);
const flashAlert = document.querySelector('.flash-alert');
expect(flashAlert).toBeVisible();
return actions
.fetchCycleAnalyticsData({
dispatch: mockDispatchContext,
state: {},
commit: () => {},
})
.then(() => {
expect(flashAlert.style.opacity).toBe('0');
});
});
}); });
// it('will flash an error when there are no stages', () => {
// [[], null].forEach(emptyStages => {
// actions.receiveGroupStagesSuccess(
// {
// dispatch: () => {},
// commit: () => {},
// state: { stages: emptyStages },
// getters,
// },
// {},
// );
// shouldFlashAMessage(flashErrorMessage);
// });
// });
}); });
describe('receiveCycleAnalyticsDataError', () => { describe('receiveCycleAnalyticsDataError', () => {
beforeEach(() => { beforeEach(() => {});
setFixtures('<div class="flash-container"></div>');
});
it(`commits the ${types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR} mutation on a 403 response`, done => { it(`commits the ${types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR} mutation on a 403 response`, () => {
const response = { status: 403 }; const response = { status: 403 };
testAction( return testAction(
actions.receiveCycleAnalyticsDataError, actions.receiveCycleAnalyticsDataError,
{ response }, { response },
state, state,
...@@ -332,13 +280,12 @@ describe('Cycle analytics actions', () => { ...@@ -332,13 +280,12 @@ describe('Cycle analytics actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
it(`commits the ${types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR} mutation on a non 403 error response`, done => { it(`commits the ${types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR} mutation on a non 403 error response`, () => {
const response = { status: 500 }; const response = { status: 500 };
testAction( return testAction(
actions.receiveCycleAnalyticsDataError, actions.receiveCycleAnalyticsDataError,
{ response }, { response },
state, state,
...@@ -349,7 +296,6 @@ describe('Cycle analytics actions', () => { ...@@ -349,7 +296,6 @@ describe('Cycle analytics actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
...@@ -367,9 +313,7 @@ describe('Cycle analytics actions', () => { ...@@ -367,9 +313,7 @@ describe('Cycle analytics actions', () => {
}); });
describe('receiveGroupStagesSuccess', () => { describe('receiveGroupStagesSuccess', () => {
beforeEach(() => { beforeEach(() => {});
setFixtures('<div class="flash-container"></div>');
});
it(`commits the ${types.RECEIVE_GROUP_STAGES_SUCCESS} mutation and dispatches 'setDefaultSelectedStage'`, () => { it(`commits the ${types.RECEIVE_GROUP_STAGES_SUCCESS} mutation and dispatches 'setDefaultSelectedStage'`, () => {
return testAction( return testAction(
...@@ -387,7 +331,7 @@ describe('Cycle analytics actions', () => { ...@@ -387,7 +331,7 @@ describe('Cycle analytics actions', () => {
}); });
}); });
describe.only('setDefaultSelectedStage', () => { describe('setDefaultSelectedStage', () => {
it("dispatches the 'fetchStageData' action", () => { it("dispatches the 'fetchStageData' action", () => {
return testAction( return testAction(
actions.setDefaultSelectedStage, actions.setDefaultSelectedStage,
...@@ -403,19 +347,30 @@ describe('Cycle analytics actions', () => { ...@@ -403,19 +347,30 @@ describe('Cycle analytics actions', () => {
); );
}); });
it('will flash an error when there are no stages', () => { it.each`
[[], null].forEach(emptyStages => { data
actions.setDefaultSelectedStage( ${[]}
{ ${null}
getters: { activeStages: emptyStages }, `('with $data will flash an error', ({ data }) => {
dispatch: () => {}, actions.setDefaultSelectedStage({ getters: { activeStages: data }, dispatch: () => {} }, {});
},
{},
);
});
shouldFlashAMessage(flashErrorMessage); shouldFlashAMessage(flashErrorMessage);
}); });
it('will select the first active stage', () => {
stages[0].hidden = true;
return testAction(
actions.setDefaultSelectedStage,
null,
{
activeStages: getters.activeStages({ stages }),
},
[],
[
{ type: 'setSelectedStage', payload: stages[1] },
{ type: 'fetchStageData', payload: stages[1].slug },
],
);
});
}); });
describe('updateStage', () => { describe('updateStage', () => {
...@@ -427,8 +382,8 @@ describe('Cycle analytics actions', () => { ...@@ -427,8 +382,8 @@ describe('Cycle analytics actions', () => {
state = { selectedGroup }; state = { selectedGroup };
}); });
it('dispatches receiveUpdateStageSuccess with put request response data', done => { it('dispatches receiveUpdateStageSuccess with put request response data', () => {
testAction( return testAction(
actions.updateStage, actions.updateStage,
{ {
id: stageId, id: stageId,
...@@ -443,24 +398,22 @@ describe('Cycle analytics actions', () => { ...@@ -443,24 +398,22 @@ describe('Cycle analytics actions', () => {
payload, payload,
}, },
], ],
done,
); );
}); });
describe('with a failed request', () => { describe('with a failed request', () => {
beforeEach(() => { beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
mock.onPut(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.NOT_FOUND); mock.onPut(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.NOT_FOUND);
}); });
it('dispatches receiveUpdateStageError', done => { it('dispatches receiveUpdateStageError', () => {
const data = { const data = {
id: stageId, id: stageId,
name: 'issue', name: 'issue',
...payload, ...payload,
}; };
testAction( return testAction(
actions.updateStage, actions.updateStage,
data, data,
state, state,
...@@ -475,50 +428,49 @@ describe('Cycle analytics actions', () => { ...@@ -475,50 +428,49 @@ describe('Cycle analytics actions', () => {
}, },
}, },
], ],
done,
); );
}); });
it('flashes an error if the stage name already exists', done => { it('flashes an error if the stage name already exists', () => {
actions.receiveUpdateStageError( return actions
{ .receiveUpdateStageError(
commit: () => {}, {
state, commit: () => {},
}, dispatch: () => Promise.resolve(),
{ state,
status: httpStatusCodes.UNPROCESSABLE_ENTITY,
responseData: {
errors: { name: ['is reserved'] },
}, },
data: { {
name: stageId, status: httpStatusCodes.UNPROCESSABLE_ENTITY,
responseData: {
errors: { name: ['is reserved'] },
},
data: {
name: stageId,
},
}, },
}, )
); .then(() => {
shouldFlashAMessage(`'${stageId}' stage already exists`);
shouldFlashAMessage(`'${stageId}' stage already exists`); });
done();
}); });
it('flashes an error message', done => { it('flashes an error message', () => {
actions.receiveUpdateStageError( return actions
{ .receiveUpdateStageError(
commit: () => {}, {
state, dispatch: () => Promise.resolve(),
}, commit: () => {},
{ status: httpStatusCodes.BAD_REQUEST }, state,
); },
{ status: httpStatusCodes.BAD_REQUEST },
shouldFlashAMessage('There was a problem saving your custom stage, please try again'); )
done(); .then(() => {
shouldFlashAMessage('There was a problem saving your custom stage, please try again');
});
}); });
}); });
describe('receiveUpdateStageSuccess', () => { describe('receiveUpdateStageSuccess', () => {
beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
});
const response = { const response = {
title: 'NEW - COOL', title: 'NEW - COOL',
}; };
...@@ -532,8 +484,8 @@ describe('Cycle analytics actions', () => { ...@@ -532,8 +484,8 @@ describe('Cycle analytics actions', () => {
[{ type: 'fetchGroupStagesAndEvents' }, { type: 'setSelectedStage', payload: response }], [{ type: 'fetchGroupStagesAndEvents' }, { type: 'setSelectedStage', payload: response }],
)); ));
it('will flash a success message', () => it('will flash a success message', () => {
actions return actions
.receiveUpdateStageSuccess( .receiveUpdateStageSuccess(
{ {
dispatch: () => {}, dispatch: () => {},
...@@ -542,8 +494,9 @@ describe('Cycle analytics actions', () => { ...@@ -542,8 +494,9 @@ describe('Cycle analytics actions', () => {
response, response,
) )
.then(() => { .then(() => {
shouldFlashAMessage('Stage data updated'); shouldFlashAMessage('Stage data updated', 'notice');
})); });
});
describe('with an error', () => { describe('with an error', () => {
it('will flash an error message', () => it('will flash an error message', () =>
...@@ -566,13 +519,12 @@ describe('Cycle analytics actions', () => { ...@@ -566,13 +519,12 @@ describe('Cycle analytics actions', () => {
const stageId = 'cool-stage'; const stageId = 'cool-stage';
beforeEach(() => { beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
mock.onDelete(stageEndpoint({ stageId })).replyOnce(200); mock.onDelete(stageEndpoint({ stageId })).replyOnce(200);
state = { selectedGroup }; state = { selectedGroup };
}); });
it('dispatches receiveRemoveStageSuccess with put request response data', done => { it('dispatches receiveRemoveStageSuccess with put request response data', () => {
testAction( return testAction(
actions.removeStage, actions.removeStage,
stageId, stageId,
state, state,
...@@ -583,7 +535,6 @@ describe('Cycle analytics actions', () => { ...@@ -583,7 +535,6 @@ describe('Cycle analytics actions', () => {
type: 'receiveRemoveStageSuccess', type: 'receiveRemoveStageSuccess',
}, },
], ],
done,
); );
}); });
...@@ -593,8 +544,8 @@ describe('Cycle analytics actions', () => { ...@@ -593,8 +544,8 @@ describe('Cycle analytics actions', () => {
mock.onDelete(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.NOT_FOUND); mock.onDelete(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.NOT_FOUND);
}); });
it('dispatches receiveRemoveStageError', done => { it('dispatches receiveRemoveStageError', () => {
testAction( return testAction(
actions.removeStage, actions.removeStage,
stageId, stageId,
state, state,
...@@ -606,21 +557,12 @@ describe('Cycle analytics actions', () => { ...@@ -606,21 +557,12 @@ describe('Cycle analytics actions', () => {
payload: error, payload: error,
}, },
], ],
done,
); );
}); });
it('flashes an error message', done => { it('flashes an error message', () => {
actions.receiveRemoveStageError( actions.receiveRemoveStageError({ commit: () => {}, state }, {});
{
commit: () => {},
state,
},
{},
);
shouldFlashAMessage('There was an error removing your custom stage, please try again'); shouldFlashAMessage('There was an error removing your custom stage, please try again');
done();
}); });
}); });
}); });
...@@ -629,34 +571,31 @@ describe('Cycle analytics actions', () => { ...@@ -629,34 +571,31 @@ describe('Cycle analytics actions', () => {
const stageId = 'cool-stage'; const stageId = 'cool-stage';
beforeEach(() => { beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
mock.onDelete(stageEndpoint({ stageId })).replyOnce(200); mock.onDelete(stageEndpoint({ stageId })).replyOnce(200);
state = { selectedGroup }; state = { selectedGroup };
}); });
it('dispatches fetchCycleAnalyticsData', done => { it('dispatches fetchCycleAnalyticsData', () => {
testAction( return testAction(
actions.receiveRemoveStageSuccess, actions.receiveRemoveStageSuccess,
stageId, stageId,
state, state,
[{ type: 'RECEIVE_REMOVE_STAGE_RESPONSE' }], [{ type: 'RECEIVE_REMOVE_STAGE_RESPONSE' }],
[{ type: 'fetchCycleAnalyticsData' }], [{ type: 'fetchCycleAnalyticsData' }],
done,
); );
}); });
it('flashes a success message', done => { it('flashes a success message', () => {
actions.receiveRemoveStageSuccess( return actions
{ .receiveRemoveStageSuccess(
dispatch: () => {}, {
commit: () => {}, dispatch: () => Promise.resolve(),
state, commit: () => {},
}, state,
{}, },
); {},
)
shouldFlashAMessage('Stage removed'); .then(() => shouldFlashAMessage('Stage removed', 'notice'));
done();
}); });
}); });
...@@ -669,8 +608,8 @@ describe('Cycle analytics actions', () => { ...@@ -669,8 +608,8 @@ describe('Cycle analytics actions', () => {
mockDispatch = jest.fn(); mockDispatch = jest.fn();
}); });
it('dispatches receiveStageMedianValuesSuccess with received data on success', done => { it('dispatches receiveStageMedianValuesSuccess with received data on success', () => {
actions return actions
.fetchStageMedianValues({ .fetchStageMedianValues({
state, state,
getters, getters,
...@@ -682,9 +621,7 @@ describe('Cycle analytics actions', () => { ...@@ -682,9 +621,7 @@ describe('Cycle analytics actions', () => {
expect(mockDispatch).toHaveBeenCalledWith('receiveStageMedianValuesSuccess', [ expect(mockDispatch).toHaveBeenCalledWith('receiveStageMedianValuesSuccess', [
{ events: [], id: selectedStageSlug }, { events: [], id: selectedStageSlug },
]); ]);
done(); });
})
.catch(done.fail);
}); });
describe('with a failing request', () => { describe('with a failing request', () => {
...@@ -692,8 +629,8 @@ describe('Cycle analytics actions', () => { ...@@ -692,8 +629,8 @@ describe('Cycle analytics actions', () => {
mock.onGet(endpoints.stageMedian).reply(httpStatusCodes.NOT_FOUND, { error }); mock.onGet(endpoints.stageMedian).reply(httpStatusCodes.NOT_FOUND, { error });
}); });
it('will dispatch receiveStageMedianValuesError', done => { it('will dispatch receiveStageMedianValuesError', () => {
actions return actions
.fetchStageMedianValues({ .fetchStageMedianValues({
state, state,
getters, getters,
...@@ -703,19 +640,15 @@ describe('Cycle analytics actions', () => { ...@@ -703,19 +640,15 @@ describe('Cycle analytics actions', () => {
.then(() => { .then(() => {
expect(mockDispatch).toHaveBeenCalledWith('requestStageMedianValues'); expect(mockDispatch).toHaveBeenCalledWith('requestStageMedianValues');
expect(mockDispatch).toHaveBeenCalledWith('receiveStageMedianValuesError', error); expect(mockDispatch).toHaveBeenCalledWith('receiveStageMedianValuesError', error);
done(); });
})
.catch(done.fail);
}); });
}); });
}); });
describe('receiveStageMedianValuesError', () => { describe('receiveStageMedianValuesError', () => {
beforeEach(() => { beforeEach(() => {});
setFixtures('<div class="flash-container"></div>');
});
it(`commits the ${types.RECEIVE_STAGE_MEDIANS_ERROR} mutation`, done => { it(`commits the ${types.RECEIVE_STAGE_MEDIANS_ERROR} mutation`, () => {
testAction( testAction(
actions.receiveStageMedianValuesError, actions.receiveStageMedianValuesError,
null, null,
...@@ -726,28 +659,23 @@ describe('Cycle analytics actions', () => { ...@@ -726,28 +659,23 @@ describe('Cycle analytics actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
it('will flash an error message', () => { it('will flash an error message', () => {
actions.receiveStageMedianValuesError({ actions.receiveStageMedianValuesError({ commit: () => {} });
commit: () => {},
});
shouldFlashAMessage('There was an error fetching median data for stages'); shouldFlashAMessage('There was an error fetching median data for stages');
}); });
}); });
describe('receiveStageMedianValuesSuccess', () => { describe('receiveStageMedianValuesSuccess', () => {
it(`commits the ${types.RECEIVE_STAGE_MEDIANS_SUCCESS} mutation`, done => { it(`commits the ${types.RECEIVE_STAGE_MEDIANS_SUCCESS} mutation`, () => {
testAction( return testAction(
actions.receiveStageMedianValuesSuccess, actions.receiveStageMedianValuesSuccess,
{ ...stageData }, { ...stageData },
state, state,
[{ type: types.RECEIVE_STAGE_MEDIANS_SUCCESS, payload: { events: [] } }], [{ type: types.RECEIVE_STAGE_MEDIANS_SUCCESS, payload: { events: [] } }],
[], [],
done,
); );
}); });
}); });
...@@ -829,42 +757,48 @@ describe('Cycle analytics actions', () => { ...@@ -829,42 +757,48 @@ describe('Cycle analytics actions', () => {
data: { name: 'uh oh' }, data: { name: 'uh oh' },
}; };
beforeEach(() => { beforeEach(() => {});
setFixtures('<div class="flash-container"></div>');
});
it('will commit the RECEIVE_CREATE_STAGE_ERROR mutation', () => it('will commit the RECEIVE_CREATE_STAGE_ERROR mutation', () =>
testAction(customStageActions.receiveCreateStageError, response, state, [ testAction(
{ type: customStageTypes.RECEIVE_CREATE_STAGE_ERROR, payload: { errors: {} } }, customStageActions.receiveCreateStageError,
]));
it('will flash an error message', done => {
customStageActions.receiveCreateStageError(
{
commit: () => {},
},
response, response,
); state,
[{ type: customStageTypes.RECEIVE_CREATE_STAGE_ERROR }],
shouldFlashAMessage('There was a problem saving your custom stage, please try again'); [{ type: 'setStageFormErrors', payload: {} }],
done(); ));
});
describe('with a stage name error', () => { it('will flash an error message', () => {
it('will flash an error message', done => { return customStageActions
customStageActions.receiveCreateStageError( .receiveCreateStageError(
{ {
dispatch: () => Promise.resolve(),
commit: () => {}, commit: () => {},
}, },
{ response,
...response, )
status: httpStatusCodes.UNPROCESSABLE_ENTITY, .then(() => {
errors: { name: ['is reserved'] }, shouldFlashAMessage('There was a problem saving your custom stage, please try again');
}, });
); });
shouldFlashAMessage("'uh oh' stage already exists"); describe('with a stage name error', () => {
done(); it('will flash an error message', () => {
return customStageActions
.receiveCreateStageError(
{
dispatch: () => Promise.resolve(),
commit: () => {},
},
{
...response,
status: httpStatusCodes.UNPROCESSABLE_ENTITY,
errors: { name: ['is reserved'] },
},
)
.then(() => {
shouldFlashAMessage("'uh oh' stage already exists");
});
}); });
}); });
}); });
...@@ -941,14 +875,10 @@ describe('Cycle analytics actions', () => { ...@@ -941,14 +875,10 @@ describe('Cycle analytics actions', () => {
response, response,
state, state,
[{ type: customStageTypes.RECEIVE_CREATE_STAGE_SUCCESS }], [{ type: customStageTypes.RECEIVE_CREATE_STAGE_SUCCESS }],
[{ type: 'fetchGroupStagesAndEvents' }], [{ type: 'fetchGroupStagesAndEvents', payload: null }],
)); ));
describe('with an error', () => { describe('with an error', () => {
beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
});
it('will flash an error message', () => it('will flash an error message', () =>
customStageActions customStageActions
.receiveCreateStageSuccess( .receiveCreateStageSuccess(
...@@ -977,14 +907,13 @@ describe('Cycle analytics actions', () => { ...@@ -977,14 +907,13 @@ describe('Cycle analytics actions', () => {
mock.onPut(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.OK); mock.onPut(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.OK);
}); });
it(`dispatches the ${types.REQUEST_REORDER_STAGE} and ${types.RECEIVE_REORDER_STAGE_SUCCESS} actions`, done => { it(`dispatches the ${types.REQUEST_REORDER_STAGE} and ${types.RECEIVE_REORDER_STAGE_SUCCESS} actions`, () => {
testAction( return testAction(
actions.reorderStage, actions.reorderStage,
payload, payload,
state, state,
[], [],
[{ type: 'requestReorderStage' }, { type: 'receiveReorderStageSuccess' }], [{ type: 'requestReorderStage' }, { type: 'receiveReorderStageSuccess' }],
done,
); );
}); });
}); });
...@@ -994,8 +923,8 @@ describe('Cycle analytics actions', () => { ...@@ -994,8 +923,8 @@ describe('Cycle analytics actions', () => {
mock.onPut(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.NOT_FOUND); mock.onPut(stageEndpoint({ stageId })).replyOnce(httpStatusCodes.NOT_FOUND);
}); });
it(`dispatches the ${types.REQUEST_REORDER_STAGE} and ${types.RECEIVE_REORDER_STAGE_ERROR} actions `, done => { it(`dispatches the ${types.REQUEST_REORDER_STAGE} and ${types.RECEIVE_REORDER_STAGE_ERROR} actions `, () => {
testAction( return testAction(
actions.reorderStage, actions.reorderStage,
payload, payload,
state, state,
...@@ -1004,19 +933,16 @@ describe('Cycle analytics actions', () => { ...@@ -1004,19 +933,16 @@ describe('Cycle analytics actions', () => {
{ type: 'requestReorderStage' }, { type: 'requestReorderStage' },
{ type: 'receiveReorderStageError', payload: { status: httpStatusCodes.NOT_FOUND } }, { type: 'receiveReorderStageError', payload: { status: httpStatusCodes.NOT_FOUND } },
], ],
done,
); );
}); });
}); });
}); });
describe('receiveReorderStageError', () => { describe('receiveReorderStageError', () => {
beforeEach(() => { beforeEach(() => {});
setFixtures('<div class="flash-container"></div>');
});
it(`commits the ${types.RECEIVE_REORDER_STAGE_ERROR} mutation and flashes an error`, () => { it(`commits the ${types.RECEIVE_REORDER_STAGE_ERROR} mutation and flashes an error`, () => {
testAction( return testAction(
actions.receiveReorderStageError, actions.receiveReorderStageError,
null, null,
state, state,
...@@ -1026,23 +952,22 @@ describe('Cycle analytics actions', () => { ...@@ -1026,23 +952,22 @@ describe('Cycle analytics actions', () => {
}, },
], ],
[], [],
); ).then(() => {
shouldFlashAMessage(
shouldFlashAMessage( 'There was an error updating the stage order. Please try reloading the page.',
'There was an error updating the stage order. Please try reloading the page.', );
); });
}); });
}); });
describe('receiveReorderStageSuccess', () => { describe('receiveReorderStageSuccess', () => {
it(`commits the ${types.RECEIVE_REORDER_STAGE_SUCCESS} mutation`, done => { it(`commits the ${types.RECEIVE_REORDER_STAGE_SUCCESS} mutation`, () => {
testAction( return testAction(
actions.receiveReorderStageSuccess, actions.receiveReorderStageSuccess,
null, null,
state, state,
[{ type: types.RECEIVE_REORDER_STAGE_SUCCESS }], [{ type: types.RECEIVE_REORDER_STAGE_SUCCESS }],
[], [],
done,
); );
}); });
}); });
......
...@@ -5,8 +5,6 @@ import * as customStageTypes from 'ee/analytics/cycle_analytics/store/modules/cu ...@@ -5,8 +5,6 @@ import * as customStageTypes from 'ee/analytics/cycle_analytics/store/modules/cu
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { import {
rawIssueEvents,
issueEvents as transformedEvents,
issueStage, issueStage,
planStage, planStage,
codeStage, codeStage,
......
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