Commit 9e2240d2 authored by Brandon Labuschagne's avatar Brandon Labuschagne Committed by Martin Wortschack

Resolve "Cleanup cycle analytics mapped imports"

parent 8a6ea16a
...@@ -58,7 +58,6 @@ export default { ...@@ -58,7 +58,6 @@ export default {
'isAddingCustomStage', 'isAddingCustomStage',
'isSavingCustomStage', 'isSavingCustomStage',
'selectedGroup', 'selectedGroup',
'selectedProjectIds',
'selectedStageId', 'selectedStageId',
'stages', 'stages',
'summary', 'summary',
...@@ -74,7 +73,6 @@ export default { ...@@ -74,7 +73,6 @@ export default {
'currentStage', 'currentStage',
'defaultStage', 'defaultStage',
'hasNoAccessError', 'hasNoAccessError',
'currentGroupPath',
'durationChartPlottableData', 'durationChartPlottableData',
]), ]),
shouldRenderEmptyState() { shouldRenderEmptyState() {
...@@ -110,13 +108,10 @@ export default { ...@@ -110,13 +108,10 @@ export default {
}, },
methods: { methods: {
...mapActions([ ...mapActions([
'fetchCustomStageFormData',
'fetchCycleAnalyticsData', 'fetchCycleAnalyticsData',
'fetchStageData', 'fetchStageData',
'fetchGroupStagesAndEvents',
'setSelectedGroup', 'setSelectedGroup',
'setSelectedProjects', 'setSelectedProjects',
'setSelectedTimeframe',
'setSelectedStageId', 'setSelectedStageId',
'hideCustomStageForm', 'hideCustomStageForm',
'showCustomStageForm', 'showCustomStageForm',
......
import dateFormat from 'dateformat'; import Api from 'ee/api';
import createFlash, { hideFlash } from '~/flash'; import createFlash, { hideFlash } from '~/flash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import Api from 'ee/api';
import httpStatus from '~/lib/utils/http_status'; import httpStatus from '~/lib/utils/http_status';
import * as types from './mutation_types'; import * as types from './mutation_types';
import { nestQueryStringKeys } from '../utils'; import { nestQueryStringKeys } from '../utils';
import { dateFormats } from '../../shared/constants';
const removeError = () => { const removeError = () => {
const flashEl = document.querySelector('.flash-alert'); const flashEl = document.querySelector('.flash-alert');
...@@ -305,26 +303,27 @@ export const receiveDurationDataError = ({ commit }) => { ...@@ -305,26 +303,27 @@ export const receiveDurationDataError = ({ commit }) => {
createFlash(__('There was an error while fetching cycle analytics duration data.')); createFlash(__('There was an error while fetching cycle analytics duration data.'));
}; };
export const fetchDurationData = ({ state, dispatch }) => { export const fetchDurationData = ({ state, dispatch, getters }) => {
dispatch('requestDurationData'); dispatch('requestDurationData');
const { const {
stages, stages,
startDate,
endDate,
selectedProjectIds,
selectedGroup: { fullPath }, selectedGroup: { fullPath },
} = state; } = state;
const {
cycleAnalyticsRequestParams: { created_after, created_before, project_ids },
} = getters;
return Promise.all( return Promise.all(
stages.map(stage => { stages.map(stage => {
const { slug } = stage; const { slug } = stage;
return Api.cycleAnalyticsDurationChart(slug, { return Api.cycleAnalyticsDurationChart(slug, {
group_id: fullPath, group_id: fullPath,
created_after: dateFormat(startDate, dateFormats.isoDate), created_after,
created_before: dateFormat(endDate, dateFormats.isoDate), created_before,
project_ids: selectedProjectIds, project_ids,
}).then(({ data }) => ({ }).then(({ data }) => ({
slug, slug,
selected: true, selected: true,
......
...@@ -352,7 +352,7 @@ describe('Cycle analytics actions', () => { ...@@ -352,7 +352,7 @@ describe('Cycle analytics actions', () => {
{ {
dispatch: mockDispatchContext, dispatch: mockDispatchContext,
state: { ...state, endpoints: { cycleAnalyticsStagesPath: '/this/is/fake' } }, state: { ...state, endpoints: { cycleAnalyticsStagesPath: '/this/is/fake' } },
commit: () => {}, getters,
}, },
{}, {},
); );
...@@ -710,32 +710,52 @@ describe('Cycle analytics actions', () => { ...@@ -710,32 +710,52 @@ describe('Cycle analytics actions', () => {
}); });
}); });
it("dispatches the 'requestDurationData' and 'receiveDurationDataSuccess' actions", done => { it("dispatches the 'receiveDurationDataSuccess' action on success", done => {
const stateWithStages = { const stateWithStages = {
...state, ...state,
stages: [stages[0], stages[1]], stages: [stages[0], stages[1]],
selectedGroup, selectedGroup,
startDate,
endDate,
}; };
const dispatch = jest.fn();
testAction( actions
actions.fetchDurationData, .fetchDurationData({
dispatch,
state: stateWithStages,
getters,
})
.then(() => {
expect(dispatch).toHaveBeenCalledWith(
'receiveDurationDataSuccess',
transformedDurationData, transformedDurationData,
stateWithStages,
[],
[
{ type: 'requestDurationData' },
{
type: 'receiveDurationDataSuccess',
payload: transformedDurationData,
},
],
done,
); );
done();
})
.catch(done.fail);
}); });
it("dispatches the 'requestDurationData' and 'receiveDurationDataError' actions when there is an error", done => { it("dispatches the 'requestDurationData' action", done => {
const stateWithStages = {
...state,
stages: [stages[0], stages[1]],
selectedGroup,
};
const dispatch = jest.fn();
actions
.fetchDurationData({
dispatch,
state: stateWithStages,
getters,
})
.then(() => {
expect(dispatch).toHaveBeenNthCalledWith(1, 'requestDurationData');
done();
})
.catch(done.fail);
});
it("dispatches the 'receiveDurationDataError' action when there is an error", done => {
const brokenState = { const brokenState = {
...state, ...state,
stages: [ stages: [
...@@ -744,18 +764,20 @@ describe('Cycle analytics actions', () => { ...@@ -744,18 +764,20 @@ describe('Cycle analytics actions', () => {
}, },
], ],
selectedGroup, selectedGroup,
startDate,
endDate,
}; };
const dispatch = jest.fn();
testAction( actions
actions.fetchDurationData, .fetchDurationData({
{}, dispatch,
brokenState, state: brokenState,
[], getters,
[{ type: 'requestDurationData' }, { type: 'receiveDurationDataError' }], })
done, .then(() => {
); expect(dispatch).toHaveBeenCalledWith('receiveDurationDataError');
done();
})
.catch(done.fail);
}); });
}); });
......
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