Commit 101c9b24 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Added mutation specs for chart data requests

Regenerate gitlab pot file and minor lints
parent 747dbd8b
......@@ -117,7 +117,10 @@ export default {
// https://gitlab.com/gitlab-org/gitlab/merge_requests/18514
this.fetchTasksByTypeData();
})
.catch(() => createFlash(__('There was an error fetching data for the chart')));
.catch(err => {
createFlash(__('There was an error fetching data for the chart'));
throw err;
});
},
onProjectsSelect(projects) {
const projectIds = projects.map(value => value.id);
......
......@@ -234,7 +234,6 @@ export const fetchTasksByTypeData = ({ dispatch, state, getters }) => {
dispatch('requestTasksByTypeData');
// TODO: move to service / api
return axios
.get(endpoint, { params })
.then(data => dispatch('receiveTasksByTypeDataSuccess', data))
......
......@@ -39,5 +39,3 @@ export const SET_TASKS_BY_TYPE_LABELS = 'SET_TASKS_BY_TYPE_LABELS';
export const REQUEST_TASKS_BY_TYPE_DATA = 'REQUEST_TASKS_BY_TYPE_DATA';
export const RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS = 'RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS';
export const RECEIVE_TASKS_BY_TYPE_DATA_ERROR = 'RECEIVE_TASKS_BY_TYPE_DATA_ERROR';
export const SET_TIMEFRAME_START_AND_END = 'SET_TIMEFRAME_START_AND_END';
......@@ -146,7 +146,11 @@ export default {
[types.RECEIVE_TASKS_BY_TYPE_DATA_ERROR](state) {
state.isLoadingChartData = false;
},
[types.RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS](state) {
[types.RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS](state, data) {
state.isLoadingChartData = false;
state.tasksByType = {
...state.tasksByType,
data,
};
},
};
......@@ -33,8 +33,7 @@ export default () => ({
customStageFormEvents: [],
tasksByType: {
subject: TASKS_BY_TYPE_SUBJECT_ISSUE, // issues | merge_requests, defaults to issues
// list of selected labels for the tasks by type chart
subject: TASKS_BY_TYPE_SUBJECT_ISSUE,
labelIds: [],
data: [],
},
......
......@@ -16,6 +16,7 @@ import {
startDate,
endDate,
customizableStagesAndEvents,
tasksByTypeData,
} from '../mock_data';
let state = null;
......@@ -47,6 +48,8 @@ describe('Cycle analytics mutations', () => {
${types.REQUEST_GROUP_STAGES_AND_EVENTS} | ${'customStageFormEvents'} | ${[]}
${types.REQUEST_CREATE_CUSTOM_STAGE} | ${'isSavingCustomStage'} | ${true}
${types.RECEIVE_CREATE_CUSTOM_STAGE_RESPONSE} | ${'isSavingCustomStage'} | ${false}
${types.REQUEST_TASKS_BY_TYPE_DATA} | ${'isLoadingChartData'} | ${true}
${types.RECEIVE_TASKS_BY_TYPE_DATA_ERROR} | ${'isLoadingChartData'} | ${false}
`('$mutation will set $stateKey=$value', ({ mutation, stateKey, value }) => {
mutations[mutation](state);
......@@ -100,6 +103,19 @@ describe('Cycle analytics mutations', () => {
});
});
describe.each`
mutation | value
${types.REQUEST_GROUP_LABELS} | ${[]}
${types.RECEIVE_GROUP_LABELS_ERROR} | ${[]}
`('$mutation', ({ mutation, value }) => {
it(`will set tasksByType.labelIds to ${value}`, () => {
state = { tasksByType: {} };
mutations[mutation](state);
expect(state.tasksByType.labelIds).toEqual(value);
});
});
describe(`${types.RECEIVE_GROUP_LABELS_SUCCESS}`, () => {
it('will set the labels state item with the camelCased group labels', () => {
mutations[types.RECEIVE_GROUP_LABELS_SUCCESS](state, groupLabels);
......@@ -193,4 +209,19 @@ describe('Cycle analytics mutations', () => {
expect(state.errorCode).toBe(errorCode);
});
});
describe(`${types.RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS}`, () => {
it('sets isLoadingChartData to false', () => {
mutations[types.RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS](state, {});
expect(state.isLoadingChartData).toEqual(false);
});
it('sets tasksByType.data to the raw returned chart data', () => {
state = { tasksByType: { data: null } };
mutations[types.RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS](state, tasksByTypeData);
expect(state.tasksByType.data).toEqual(tasksByTypeData);
});
});
});
......@@ -134,4 +134,4 @@ describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
expect(response).to be_successful
end
end
end
\ No newline at end of file
end
......@@ -17422,6 +17422,9 @@ msgstr ""
msgid "There was an error fetching data for the selected stage"
msgstr ""
msgid "There was an error fetching data for the chart"
msgstr ""
msgid "There was an error fetching label data for the selected group"
msgstr ""
......
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