Commit d1bd7207 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '37281-cleanup-cycle-analytics-mapped-imports' into 'master'

Resolve "Cleanup cycle analytics mapped imports"

Closes #37281

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