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 }) => ...@@ -114,7 +114,7 @@ export const receiveCycleAnalyticsDataSuccess = ({ state, commit, dispatch }) =>
const { featureFlags: { hasDurationChart = false, hasTasksByTypeChart = false } = {} } = state; const { featureFlags: { hasDurationChart = false, hasTasksByTypeChart = false } = {} } = state;
const promises = []; const promises = [];
if (hasDurationChart) promises.push('fetchDurationData'); if (hasDurationChart) promises.push('fetchDurationData');
if (hasTasksByTypeChart) promises.push('fetchTasksByTypeData'); if (hasTasksByTypeChart) promises.push('fetchTopRankedGroupLabels');
return Promise.all(promises.map(func => dispatch(func))); return Promise.all(promises.map(func => dispatch(func)));
}; };
...@@ -132,7 +132,6 @@ export const fetchCycleAnalyticsData = ({ dispatch }) => { ...@@ -132,7 +132,6 @@ export const fetchCycleAnalyticsData = ({ dispatch }) => {
dispatch('requestCycleAnalyticsData'); dispatch('requestCycleAnalyticsData');
return Promise.resolve() return Promise.resolve()
.then(() => dispatch('fetchGroupLabels')) .then(() => dispatch('fetchGroupLabels'))
.then(() => dispatch('fetchTopRankedGroupLabels'))
.then(() => dispatch('fetchGroupStagesAndEvents')) .then(() => dispatch('fetchGroupStagesAndEvents'))
.then(() => dispatch('fetchStageMedianValues')) .then(() => dispatch('fetchStageMedianValues'))
.then(() => dispatch('fetchSummaryData')) .then(() => dispatch('fetchSummaryData'))
...@@ -225,8 +224,10 @@ export const fetchGroupLabels = ({ dispatch, state }) => { ...@@ -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); commit(types.RECEIVE_TOP_RANKED_GROUP_LABELS_SUCCESS, data);
dispatch('fetchTasksByTypeData');
};
export const receiveTopRankedGroupLabelsError = ({ commit }, error) => { export const receiveTopRankedGroupLabelsError = ({ commit }, error) => {
commit(types.RECEIVE_TOP_RANKED_GROUP_LABELS_ERROR, error); commit(types.RECEIVE_TOP_RANKED_GROUP_LABELS_ERROR, error);
......
...@@ -432,6 +432,7 @@ describe('Cycle Analytics component', () => { ...@@ -432,6 +432,7 @@ describe('Cycle Analytics component', () => {
mockFetchStageMedian = true, mockFetchStageMedian = true,
mockFetchDurationData = true, mockFetchDurationData = true,
mockFetchTasksByTypeData = true, mockFetchTasksByTypeData = true,
mockFetchTopRankedGroupLabels = true,
}) => { }) => {
const defaultStatus = 200; const defaultStatus = 200;
const defaultRequests = { const defaultRequests = {
...@@ -453,9 +454,11 @@ describe('Cycle Analytics component', () => { ...@@ -453,9 +454,11 @@ describe('Cycle Analytics component', () => {
...overrides, ...overrides,
}; };
if (mockFetchTopRankedGroupLabels) {
mock mock
.onGet(mockData.endpoints.tasksByTypeTopLabelsData) .onGet(mockData.endpoints.tasksByTypeTopLabelsData)
.reply(defaultStatus, mockData.groupLabels); .reply(defaultStatus, mockData.groupLabels);
}
if (mockFetchTasksByTypeData) { if (mockFetchTasksByTypeData) {
mock mock
...@@ -565,6 +568,16 @@ describe('Cycle Analytics component', () => { ...@@ -565,6 +568,16 @@ describe('Cycle Analytics component', () => {
return selectGroupAndFindError('There was an error fetching data for the selected stage'); 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', () => { it('will display an error if the fetchTasksByTypeData request fails', () => {
expect(findFlashError()).toBeNull(); expect(findFlashError()).toBeNull();
......
...@@ -271,6 +271,28 @@ describe('Cycle analytics actions', () => { ...@@ -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', () => { describe('with an error', () => {
...@@ -348,7 +370,6 @@ describe('Cycle analytics actions', () => { ...@@ -348,7 +370,6 @@ describe('Cycle analytics actions', () => {
[ [
{ type: 'requestCycleAnalyticsData' }, { type: 'requestCycleAnalyticsData' },
{ type: 'fetchGroupLabels' }, { type: 'fetchGroupLabels' },
{ type: 'fetchTopRankedGroupLabels' },
{ type: 'fetchGroupStagesAndEvents' }, { type: 'fetchGroupStagesAndEvents' },
{ type: 'fetchStageMedianValues' }, { type: 'fetchStageMedianValues' },
{ type: 'fetchSummaryData' }, { 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