Commit 3a47e385 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Use activeStages for fetchStageMedianValues

parent 1f640eae
...@@ -71,10 +71,9 @@ const fetchStageMedian = (currentGroupPath, stageId, params) => ...@@ -71,10 +71,9 @@ const fetchStageMedian = (currentGroupPath, stageId, params) =>
...data, ...data,
})); }));
export const fetchStageMedianValues = ({ state, dispatch, getters }) => { export const fetchStageMedianValues = ({ dispatch, getters }) => {
const { currentGroupPath, cycleAnalyticsRequestParams } = getters; const { currentGroupPath, cycleAnalyticsRequestParams, activeStages } = getters;
const { stages } = state; const stageIds = activeStages.map(s => s.slug);
const stageIds = stages.map(s => s.slug);
dispatch('requestStageMedianValues'); dispatch('requestStageMedianValues');
return Promise.all( return Promise.all(
......
...@@ -18,7 +18,12 @@ import { ...@@ -18,7 +18,12 @@ import {
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}`);
const flashErrorMessage = 'There was an error while fetching value stream analytics data.'; const flashErrorMessage = 'There was an error while fetching value stream analytics data.';
const [selectedStage] = stages;
stages[0].hidden = true;
const activeStages = stages.filter(({ hidden }) => !hidden);
const hiddenStage = stages[0];
const [selectedStage] = activeStages;
const selectedStageSlug = selectedStage.slug; const selectedStageSlug = selectedStage.slug;
const stageEndpoint = ({ stageId }) => const stageEndpoint = ({ stageId }) =>
...@@ -44,6 +49,7 @@ describe('Cycle analytics actions', () => { ...@@ -44,6 +49,7 @@ describe('Cycle analytics actions', () => {
hasDurationChart: true, hasDurationChart: true,
hasDurationChartMedian: true, hasDurationChartMedian: true,
}, },
activeStages,
}; };
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
...@@ -262,7 +268,10 @@ describe('Cycle analytics actions', () => { ...@@ -262,7 +268,10 @@ describe('Cycle analytics actions', () => {
.mockImplementation(actions.receiveStageMedianValuesError({ commit: () => {} })), .mockImplementation(actions.receiveStageMedianValuesError({ commit: () => {} })),
commit: () => {}, commit: () => {},
state: { ...state }, state: { ...state },
getters, getters: {
...getters,
activeStages,
},
}), }),
}); });
...@@ -374,9 +383,7 @@ describe('Cycle analytics actions', () => { ...@@ -374,9 +383,7 @@ describe('Cycle analytics actions', () => {
return testAction( return testAction(
actions.setDefaultSelectedStage, actions.setDefaultSelectedStage,
null, null,
{ state,
activeStages: stages,
},
[], [],
[ [
{ type: 'setSelectedStage', payload: selectedStage }, { type: 'setSelectedStage', payload: selectedStage },
...@@ -395,13 +402,10 @@ describe('Cycle analytics actions', () => { ...@@ -395,13 +402,10 @@ describe('Cycle analytics actions', () => {
}); });
it('will select the first active stage', () => { it('will select the first active stage', () => {
stages[0].hidden = true;
return testAction( return testAction(
actions.setDefaultSelectedStage, actions.setDefaultSelectedStage,
null, null,
{ state,
activeStages: getters.activeStages({ stages }),
},
[], [],
[ [
{ type: 'setSelectedStage', payload: stages[1] }, { type: 'setSelectedStage', payload: stages[1] },
...@@ -644,26 +648,44 @@ describe('Cycle analytics actions', () => { ...@@ -644,26 +648,44 @@ describe('Cycle analytics actions', () => {
describe('fetchStageMedianValues', () => { describe('fetchStageMedianValues', () => {
let mockDispatch = jest.fn(); let mockDispatch = jest.fn();
const fetchMedianResponse = activeStages.map(({ slug: id }) => ({ events: [], id }));
beforeEach(() => { beforeEach(() => {
state = { ...state, stages: [{ slug: selectedStageSlug }], selectedGroup }; state = { ...state, stages, selectedGroup };
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
mock.onGet(endpoints.stageMedian).reply(200, { events: [] }); mock.onGet(endpoints.stageMedian).reply(200, { events: [] });
mockDispatch = jest.fn(); mockDispatch = jest.fn();
}); });
it('dispatches receiveStageMedianValuesSuccess with received data on success', () => { it('dispatches receiveStageMedianValuesSuccess with received data on success', () => {
return testAction(
actions.fetchStageMedianValues,
null,
state,
[],
[
{ type: 'requestStageMedianValues' },
{ type: 'receiveStageMedianValuesSuccess', payload: fetchMedianResponse },
],
);
});
it('does not request hidden stages', () => {
return actions return actions
.fetchStageMedianValues({ .fetchStageMedianValues({
state, state,
getters, getters: {
...getters,
activeStages,
},
commit: () => {}, commit: () => {},
dispatch: mockDispatch, dispatch: mockDispatch,
}) })
.then(() => { .then(() => {
expect(mockDispatch).toHaveBeenCalledWith('requestStageMedianValues'); expect(mockDispatch).not.toHaveBeenCalledWith('receiveStageMedianValuesSuccess', {
expect(mockDispatch).toHaveBeenCalledWith('receiveStageMedianValuesSuccess', [ events: [],
{ events: [], id: selectedStageSlug }, id: hiddenStage.id,
]); });
}); });
}); });
...@@ -673,17 +695,16 @@ describe('Cycle analytics actions', () => { ...@@ -673,17 +695,16 @@ describe('Cycle analytics actions', () => {
}); });
it('will dispatch receiveStageMedianValuesError', () => { it('will dispatch receiveStageMedianValuesError', () => {
return actions return testAction(
.fetchStageMedianValues({ actions.fetchStageMedianValues,
state, null,
getters, state,
commit: () => {}, [],
dispatch: mockDispatch, [
}) { type: 'requestStageMedianValues' },
.then(() => { { type: 'receiveStageMedianValuesError', payload: error },
expect(mockDispatch).toHaveBeenCalledWith('requestStageMedianValues'); ],
expect(mockDispatch).toHaveBeenCalledWith('receiveStageMedianValuesError', error); );
});
}); });
}); });
}); });
......
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