Commit b0759564 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch...

Merge branch '13836-follow-up-from-productivity-analytics-add-error-handling-for-reporting-on-groups-which-have-no-plan' into 'master'

Resolve "Follow-up from "Productivity Analytics: Add error handling for reporting on groups which have no plan""

Closes #13836

See merge request gitlab-org/gitlab!17206
parents fd40fcbf 0c309355
...@@ -111,7 +111,7 @@ export const isSelectedMetric = state => ({ metric, chartKey }) => ...@@ -111,7 +111,7 @@ export const isSelectedMetric = state => ({ metric, chartKey }) =>
state.charts[chartKey].params.metricType === metric; state.charts[chartKey].params.metricType === metric;
export const hasNoAccessError = state => export const hasNoAccessError = state =>
state.charts[chartKeys.main].hasError === httpStatus.FORBIDDEN; state.charts[chartKeys.main].errorCode === httpStatus.FORBIDDEN;
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
...@@ -10,12 +10,12 @@ export default { ...@@ -10,12 +10,12 @@ export default {
}, },
[types.RECEIVE_CHART_DATA_SUCCESS](state, { chartKey, data }) { [types.RECEIVE_CHART_DATA_SUCCESS](state, { chartKey, data }) {
state.charts[chartKey].isLoading = false; state.charts[chartKey].isLoading = false;
state.charts[chartKey].hasError = false; state.charts[chartKey].errorCode = null;
state.charts[chartKey].data = data; state.charts[chartKey].data = data;
}, },
[types.RECEIVE_CHART_DATA_ERROR](state, { chartKey, status }) { [types.RECEIVE_CHART_DATA_ERROR](state, { chartKey, status }) {
state.charts[chartKey].isLoading = false; state.charts[chartKey].isLoading = false;
state.charts[chartKey].hasError = status; state.charts[chartKey].errorCode = status;
state.charts[chartKey].data = {}; state.charts[chartKey].data = {};
}, },
[types.SET_METRIC_TYPE](state, { chartKey, metricType }) { [types.SET_METRIC_TYPE](state, { chartKey, metricType }) {
......
...@@ -4,7 +4,7 @@ export default () => ({ ...@@ -4,7 +4,7 @@ export default () => ({
charts: { charts: {
[chartKeys.main]: { [chartKeys.main]: {
isLoading: false, isLoading: false,
hasError: false, errorCode: null,
data: {}, data: {},
selected: [], selected: [],
params: { params: {
...@@ -13,7 +13,7 @@ export default () => ({ ...@@ -13,7 +13,7 @@ export default () => ({
}, },
[chartKeys.timeBasedHistogram]: { [chartKeys.timeBasedHistogram]: {
isLoading: false, isLoading: false,
hasError: false, errorCode: null,
data: {}, data: {},
selected: [], selected: [],
params: { params: {
...@@ -23,7 +23,7 @@ export default () => ({ ...@@ -23,7 +23,7 @@ export default () => ({
}, },
[chartKeys.commitBasedHistogram]: { [chartKeys.commitBasedHistogram]: {
isLoading: false, isLoading: false,
hasError: false, errorCode: null,
data: {}, data: {},
selected: [], selected: [],
params: { params: {
...@@ -33,7 +33,7 @@ export default () => ({ ...@@ -33,7 +33,7 @@ export default () => ({
}, },
[chartKeys.scatterplot]: { [chartKeys.scatterplot]: {
isLoading: false, isLoading: false,
hasError: false, errorCode: null,
data: {}, data: {},
selected: [], selected: [],
params: { params: {
......
...@@ -7,13 +7,13 @@ export default { ...@@ -7,13 +7,13 @@ export default {
}, },
[types.RECEIVE_MERGE_REQUESTS_SUCCESS](state, { pageInfo, mergeRequests }) { [types.RECEIVE_MERGE_REQUESTS_SUCCESS](state, { pageInfo, mergeRequests }) {
state.isLoadingTable = false; state.isLoadingTable = false;
state.hasError = false; state.errorCode = null;
state.pageInfo = pageInfo; state.pageInfo = pageInfo;
state.mergeRequests = mergeRequests; state.mergeRequests = mergeRequests;
}, },
[types.RECEIVE_MERGE_REQUESTS_ERROR](state, errCode) { [types.RECEIVE_MERGE_REQUESTS_ERROR](state, errCode) {
state.isLoadingTable = false; state.isLoadingTable = false;
state.hasError = errCode; state.errorCode = errCode;
state.pageInfo = {}; state.pageInfo = {};
state.mergeRequests = []; state.mergeRequests = [];
}, },
......
...@@ -2,7 +2,7 @@ import { tableSortOrder } from '../../../constants'; ...@@ -2,7 +2,7 @@ import { tableSortOrder } from '../../../constants';
export default () => ({ export default () => ({
isLoadingTable: false, isLoadingTable: false,
hasError: false, errorCode: null,
mergeRequests: [], mergeRequests: [],
pageInfo: {}, pageInfo: {},
sortOrder: tableSortOrder.asc.value, sortOrder: tableSortOrder.asc.value,
......
...@@ -75,7 +75,7 @@ describe('ProductivityApp component', () => { ...@@ -75,7 +75,7 @@ describe('ProductivityApp component', () => {
describe('and user has no access to the group', () => { describe('and user has no access to the group', () => {
beforeEach(() => { beforeEach(() => {
store.state.charts.charts[chartKeys.main].hasError = 403; store.state.charts.charts[chartKeys.main].errorCode = 403;
}); });
it('renders the no access illustration', () => { it('renders the no access illustration', () => {
...@@ -88,7 +88,7 @@ describe('ProductivityApp component', () => { ...@@ -88,7 +88,7 @@ describe('ProductivityApp component', () => {
describe('and user has access to the group', () => { describe('and user has access to the group', () => {
beforeEach(() => { beforeEach(() => {
store.state.charts.charts[chartKeys.main].hasError = false; store.state.charts.charts[chartKeys.main].errorCode = null;
}); });
describe('Time to merge chart', () => { describe('Time to merge chart', () => {
......
...@@ -179,13 +179,13 @@ describe('Productivity analytics chart getters', () => { ...@@ -179,13 +179,13 @@ describe('Productivity analytics chart getters', () => {
}); });
describe('hasNoAccessError', () => { describe('hasNoAccessError', () => {
it('returns true if "hasError" is set to 403', () => { it('returns true if errorCode is set to 403', () => {
state.charts[chartKeys.main].hasError = 403; state.charts[chartKeys.main].errorCode = 403;
expect(getters.hasNoAccessError(state)).toEqual(true); expect(getters.hasNoAccessError(state)).toEqual(true);
}); });
it('returns false if "hasError" is not set to 403', () => { it('returns false if errorCode is not set to 403', () => {
state.charts[chartKeys.main].hasError = false; state.charts[chartKeys.main].errorCode = null;
expect(getters.hasNoAccessError(state)).toEqual(false); expect(getters.hasNoAccessError(state)).toEqual(false);
}); });
}); });
......
...@@ -34,18 +34,24 @@ describe('Productivity analytics chart mutations', () => { ...@@ -34,18 +34,24 @@ describe('Productivity analytics chart mutations', () => {
mutations[types.RECEIVE_CHART_DATA_SUCCESS](state, { chartKey, data: mockHistogramData }); mutations[types.RECEIVE_CHART_DATA_SUCCESS](state, { chartKey, data: mockHistogramData });
expect(state.charts[chartKey].isLoading).toBe(false); expect(state.charts[chartKey].isLoading).toBe(false);
expect(state.charts[chartKey].hasError).toBe(false); expect(state.charts[chartKey].errorCode).toBe(null);
expect(state.charts[chartKey].data).toEqual(mockHistogramData); expect(state.charts[chartKey].data).toEqual(mockHistogramData);
}); });
}); });
describe(types.RECEIVE_CHART_DATA_ERROR, () => { describe(types.RECEIVE_CHART_DATA_ERROR, () => {
it('sets isError to error code and clears data', () => { const status = 500;
const status = 500; beforeEach(() => {
mutations[types.RECEIVE_CHART_DATA_ERROR](state, { chartKey, status }); mutations[types.RECEIVE_CHART_DATA_ERROR](state, { chartKey, status });
});
it('sets errorCode to 500', () => {
expect(state.charts[chartKey].isLoading).toBe(false);
expect(state.charts[chartKey].errorCode).toBe(status);
});
it('clears data', () => {
expect(state.charts[chartKey].isLoading).toBe(false); expect(state.charts[chartKey].isLoading).toBe(false);
expect(state.charts[chartKey].hasError).toBe(status);
expect(state.charts[chartKey].data).toEqual({}); expect(state.charts[chartKey].data).toEqual({});
}); });
}); });
......
...@@ -33,19 +33,25 @@ describe('Productivity analytics table mutations', () => { ...@@ -33,19 +33,25 @@ describe('Productivity analytics table mutations', () => {
}); });
expect(state.isLoadingTable).toBe(false); expect(state.isLoadingTable).toBe(false);
expect(state.hasError).toBe(false); expect(state.errorCode).toBe(null);
expect(state.mergeRequests).toEqual(mockMergeRequests); expect(state.mergeRequests).toEqual(mockMergeRequests);
expect(state.pageInfo).toEqual(pageInfo); expect(state.pageInfo).toEqual(pageInfo);
}); });
}); });
describe(types.RECEIVE_MERGE_REQUESTS_ERROR, () => { describe(types.RECEIVE_MERGE_REQUESTS_ERROR, () => {
it('sets hasError to error code and clears data', () => { const errorCode = 500;
const errorCode = 500; beforeEach(() => {
mutations[types.RECEIVE_MERGE_REQUESTS_ERROR](state, errorCode); mutations[types.RECEIVE_MERGE_REQUESTS_ERROR](state, errorCode);
});
it('sets errorCode to 500', () => {
expect(state.isLoadingTable).toBe(false);
expect(state.errorCode).toBe(errorCode);
});
it('clears data', () => {
expect(state.isLoadingTable).toBe(false); expect(state.isLoadingTable).toBe(false);
expect(state.hasError).toBe(errorCode);
expect(state.mergeRequests).toEqual([]); expect(state.mergeRequests).toEqual([]);
expect(state.pageInfo).toEqual({}); expect(state.pageInfo).toEqual({});
}); });
......
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