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