Commit 2592e034 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Only request top labels with tasks_by_type flag on

Ensures that we only request the top n labels
when the tasks by type chart feature flag is
enabled.

Updated specs for cycle analytics requests
parent 482586a4
......@@ -114,7 +114,7 @@ export const receiveCycleAnalyticsDataSuccess = ({ state, commit, dispatch }) =>
const { featureFlags: { hasDurationChart = false, hasTasksByTypeChart = false } = {} } = state;
const promises = [];
if (hasDurationChart) promises.push('fetchDurationData');
if (hasTasksByTypeChart) promises.push('fetchTasksByTypeData');
if (hasTasksByTypeChart) promises.push('fetchTopRankedGroupLabels');
return Promise.all(promises.map(func => dispatch(func)));
};
......@@ -132,7 +132,6 @@ export const fetchCycleAnalyticsData = ({ dispatch }) => {
dispatch('requestCycleAnalyticsData');
return Promise.resolve()
.then(() => dispatch('fetchGroupLabels'))
.then(() => dispatch('fetchTopRankedGroupLabels'))
.then(() => dispatch('fetchGroupStagesAndEvents'))
.then(() => dispatch('fetchStageMedianValues'))
.then(() => dispatch('fetchSummaryData'))
......@@ -225,8 +224,10 @@ export const fetchGroupLabels = ({ dispatch, state }) => {
);
};
export const receiveTopRankedGroupLabelsSuccess = ({ commit }, data) =>
export const receiveTopRankedGroupLabelsSuccess = ({ commit, dispatch }, data) => {
commit(types.RECEIVE_TOP_RANKED_GROUP_LABELS_SUCCESS, data);
dispatch('fetchTasksByTypeData');
};
export const receiveTopRankedGroupLabelsError = ({ commit }, error) => {
commit(types.RECEIVE_TOP_RANKED_GROUP_LABELS_ERROR, error);
......
......@@ -432,6 +432,7 @@ describe('Cycle Analytics component', () => {
mockFetchStageMedian = true,
mockFetchDurationData = true,
mockFetchTasksByTypeData = true,
mockFetchTopRankedGroupLabels = true,
}) => {
const defaultStatus = 200;
const defaultRequests = {
......@@ -453,9 +454,11 @@ describe('Cycle Analytics component', () => {
...overrides,
};
if (mockFetchTopRankedGroupLabels) {
mock
.onGet(mockData.endpoints.tasksByTypeTopLabelsData)
.reply(defaultStatus, mockData.groupLabels);
}
if (mockFetchTasksByTypeData) {
mock
......@@ -565,6 +568,16 @@ describe('Cycle Analytics component', () => {
return selectGroupAndFindError('There was an error fetching data for the selected stage');
});
it('will display an error if the fetchTopRankedGroupLabels request fails', () => {
expect(findFlashError()).toBeNull();
mockRequestCycleAnalyticsData({ mockFetchTopRankedGroupLabels: false });
return selectGroupAndFindError(
'There was an error fetching the top labels for the selected group',
);
});
it('will display an error if the fetchTasksByTypeData request fails', () => {
expect(findFlashError()).toBeNull();
......
......@@ -271,6 +271,28 @@ describe('Cycle analytics actions', () => {
],
);
});
describe('receiveTopRankedGroupLabelsSuccess', () => {
beforeEach(() => {
setFixtures('<div class="flash-container"></div>');
});
it(`commits the ${types.RECEIVE_TOP_RANKED_GROUP_LABELS_SUCCESS} mutation and dispatches the 'fetchTasksByTypeData' action`, done => {
testAction(
actions.receiveTopRankedGroupLabelsSuccess,
null,
state,
[
{
type: types.RECEIVE_TOP_RANKED_GROUP_LABELS_SUCCESS,
payload: null,
},
],
[{ type: 'fetchTasksByTypeData' }],
done,
);
});
});
});
describe('with an error', () => {
......@@ -348,7 +370,6 @@ describe('Cycle analytics actions', () => {
[
{ type: 'requestCycleAnalyticsData' },
{ type: 'fetchGroupLabels' },
{ type: 'fetchTopRankedGroupLabels' },
{ type: 'fetchGroupStagesAndEvents' },
{ type: 'fetchStageMedianValues' },
{ type: 'fetchSummaryData' },
......
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