Commit 7afcc3b6 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '273107-add-missing-vsa-vuex-specs' into 'master'

[VSA] Add missing vuex action specs

See merge request gitlab-org/gitlab!67114
parents 5e77e697 e2ae04a1
import { s__ } from '~/locale';
import { __, s__ } from '~/locale';
export const DEFAULT_DAYS_IN_PAST = 30;
export const DEFAULT_DAYS_TO_DISPLAY = 30;
......@@ -22,3 +22,11 @@ export const PAGINATION_SORT_DIRECTION_ASC = 'asc';
export const STAGE_TITLE_STAGING = 'staging';
export const STAGE_TITLE_TEST = 'test';
export const I18N_VSA_ERROR_STAGES = __(
'There was an error fetching value stream analytics stages.',
);
export const I18N_VSA_ERROR_STAGE_MEDIAN = __('There was an error fetching median data for stages');
export const I18N_VSA_ERROR_SELECTED_STAGE = __(
'There was an error fetching data for the selected stage',
);
......@@ -7,7 +7,11 @@ import {
} from '~/api/analytics_api';
import createFlash from '~/flash';
import { __ } from '~/locale';
import { DEFAULT_DAYS_TO_DISPLAY, DEFAULT_VALUE_STREAM } from '../constants';
import {
DEFAULT_DAYS_TO_DISPLAY,
DEFAULT_VALUE_STREAM,
I18N_VSA_ERROR_STAGE_MEDIAN,
} from '../constants';
import * as types from './mutation_types';
export const setSelectedValueStream = ({ commit, dispatch }, valueStream) => {
......@@ -120,9 +124,7 @@ export const fetchStageMedians = ({
.then((data) => commit(types.RECEIVE_STAGE_MEDIANS_SUCCESS, data))
.catch((error) => {
commit(types.RECEIVE_STAGE_MEDIANS_ERROR, error);
createFlash({
message: __('There was an error fetching median data for stages'),
});
createFlash({ message: I18N_VSA_ERROR_STAGE_MEDIAN });
});
};
......
import Api from 'ee/api';
import { getValueStreamStageMedian } from '~/api/analytics_api';
import {
I18N_VSA_ERROR_STAGES,
I18N_VSA_ERROR_STAGE_MEDIAN,
I18N_VSA_ERROR_SELECTED_STAGE,
} from '~/cycle_analytics/constants';
import createFlash from '~/flash';
import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
import { __ } from '~/locale';
import { OVERVIEW_STAGE_CONFIG } from '../../constants';
import { checkForDataError, flashErrorIfStatusNotOk, throwIfUserForbidden } from '../../utils';
import * as types from '../mutation_types';
......@@ -16,10 +20,7 @@ export const requestStageData = ({ commit }) => commit(types.REQUEST_STAGE_DATA)
export const receiveStageDataError = ({ commit }, error) => {
const { message = '' } = error;
flashErrorIfStatusNotOk({
error,
message: __('There was an error fetching data for the selected stage'),
});
flashErrorIfStatusNotOk({ error, message: I18N_VSA_ERROR_SELECTED_STAGE });
commit(types.RECEIVE_STAGE_DATA_ERROR, message);
};
......@@ -54,9 +55,7 @@ export const requestStageMedianValues = ({ commit }) => commit(types.REQUEST_STA
export const receiveStageMedianValuesError = ({ commit }, error) => {
commit(types.RECEIVE_STAGE_MEDIANS_ERROR, error);
createFlash({
message: __('There was an error fetching median data for stages'),
});
createFlash({ message: I18N_VSA_ERROR_STAGE_MEDIAN });
};
const fetchStageMedian = ({ groupId, valueStreamId, stageId, params }) =>
......@@ -137,9 +136,7 @@ export const requestGroupStages = ({ commit }) => commit(types.REQUEST_GROUP_STA
export const receiveGroupStagesError = ({ commit }, error) => {
commit(types.RECEIVE_GROUP_STAGES_ERROR, error);
createFlash({
message: __('There was an error fetching value stream analytics stages.'),
});
createFlash({ message: I18N_VSA_ERROR_STAGES });
};
export const receiveGroupStagesSuccess = ({ commit }, stages) =>
......
......@@ -20,7 +20,12 @@ import {
import PathNavigation from '~/cycle_analytics/components/path_navigation.vue';
import StageTable from '~/cycle_analytics/components/stage_table.vue';
import ValueStreamFilters from '~/cycle_analytics/components/value_stream_filters.vue';
import { OVERVIEW_STAGE_ID } from '~/cycle_analytics/constants';
import {
OVERVIEW_STAGE_ID,
I18N_VSA_ERROR_STAGES,
I18N_VSA_ERROR_STAGE_MEDIAN,
I18N_VSA_ERROR_SELECTED_STAGE,
} from '~/cycle_analytics/constants';
import createFlash from '~/flash';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import * as commonUtils from '~/lib/utils/common_utils';
......@@ -343,9 +348,7 @@ describe('EE Value Stream Analytics component', () => {
.reply(httpStatusCodes.NOT_FOUND, { response: { status: httpStatusCodes.NOT_FOUND } });
wrapper = await createComponent();
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching value stream analytics stages.',
});
expect(createFlash).toHaveBeenCalledWith({ message: I18N_VSA_ERROR_STAGES });
});
it('will display an error if the fetchStageData request fails', async () => {
......@@ -357,9 +360,7 @@ describe('EE Value Stream Analytics component', () => {
wrapper = await createComponent({ selectedStage: issueStage });
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching data for the selected stage',
});
expect(createFlash).toHaveBeenCalledWith({ message: I18N_VSA_ERROR_SELECTED_STAGE });
});
it('will display an error if the fetchTopRankedGroupLabels request fails', async () => {
......@@ -398,9 +399,7 @@ describe('EE Value Stream Analytics component', () => {
.reply(httpStatusCodes.NOT_FOUND, { response: { status: httpStatusCodes.NOT_FOUND } });
wrapper = await createComponent();
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching median data for stages',
});
expect(createFlash).toHaveBeenCalledWith({ message: I18N_VSA_ERROR_STAGE_MEDIAN });
});
it('will display an error if the fetchStageData request is successful but has an embedded error', async () => {
......
......@@ -78,4 +78,19 @@ describe('Value Stream Analytics actions / filters', () => {
});
});
});
describe('updateStageTablePagination', () => {
beforeEach(() => {
state = { ...state, selectedStage };
});
it(`will dispatch the "fetchStageData" action and commit the ${types.SET_PAGINATION} mutation`, () => {
return testAction({
action: actions.updateStageTablePagination,
state,
expectedMutations: [{ type: types.SET_PAGINATION }],
expectedActions: [{ type: 'fetchStageData', payload: selectedStage.id }],
});
});
});
});
......@@ -6,6 +6,11 @@ import * as getters from 'ee/analytics/cycle_analytics/store/getters';
import * as types from 'ee/analytics/cycle_analytics/store/mutation_types';
import testAction from 'helpers/vuex_action_helper';
import { createdAfter, createdBefore, currentGroup } from 'jest/cycle_analytics/mock_data';
import {
I18N_VSA_ERROR_STAGES,
I18N_VSA_ERROR_STAGE_MEDIAN,
I18N_VSA_ERROR_SELECTED_STAGE,
} from '~/cycle_analytics/constants';
import createFlash from '~/flash';
import httpStatusCodes from '~/lib/utils/http_status';
import {
......@@ -26,9 +31,15 @@ const [selectedStage] = activeStages;
const selectedStageSlug = selectedStage.slug;
const [selectedValueStream] = valueStreams;
const selectedProjectIds = [1, 2];
const mockGetters = {
currentGroupPath: () => currentGroup.fullPath,
currentValueStreamId: () => selectedValueStream.id,
cycleAnalyticsRequestParams: () => ({
created_after: createdAfter,
project_ids: selectedProjectIds,
}),
};
jest.mock('~/flash');
......@@ -77,6 +88,15 @@ describe('Value Stream Analytics actions / stages', () => {
});
});
describe('requestStageData', () => {
it(`commits the ${types.REQUEST_STAGE_DATA} mutation`, () => {
return testAction({
action: actions.requestStageData,
expectedMutations: [{ type: types.REQUEST_STAGE_DATA }],
});
});
});
describe('fetchStageData', () => {
const headers = {
'X-Next-Page': 2,
......@@ -182,8 +202,15 @@ describe('Value Stream Analytics actions / stages', () => {
it('will flash an error message', () => {
actions.receiveStageDataError({ commit: () => {} }, {});
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching data for the selected stage',
expect(createFlash).toHaveBeenCalledWith({ message: I18N_VSA_ERROR_SELECTED_STAGE });
});
});
describe('requestStageMedianValues', () => {
it(`commits the ${types.REQUEST_STAGE_MEDIANS} mutation`, () => {
return testAction({
action: actions.requestStageMedianValues,
expectedMutations: [{ type: types.REQUEST_STAGE_MEDIANS }],
});
});
});
......@@ -284,9 +311,7 @@ describe('Value Stream Analytics actions / stages', () => {
it('will flash an error message', () => {
actions.receiveStageMedianValuesError({ commit: () => {} });
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching median data for stages',
});
expect(createFlash).toHaveBeenCalledWith({ message: I18N_VSA_ERROR_STAGE_MEDIAN });
});
});
......@@ -318,6 +343,32 @@ describe('Value Stream Analytics actions / stages', () => {
});
});
describe('requestGroupStages', () => {
it(`commits the ${types.REQUEST_GROUP_STAGES} mutation`, () => {
return testAction({
action: actions.requestGroupStages,
expectedMutations: [{ type: types.REQUEST_GROUP_STAGES }],
});
});
});
describe('receiveGroupStagesError', () => {
it(`commits the ${types.RECEIVE_GROUP_STAGES_ERROR} mutation`, () => {
return testAction({
action: actions.receiveGroupStagesError,
expectedMutations: [{ type: types.RECEIVE_GROUP_STAGES_ERROR }],
});
});
it('will flash an error message', async () => {
expect(createFlash).not.toHaveBeenCalled();
await actions.receiveGroupStagesError({ commit: () => {} });
expect(createFlash).toHaveBeenCalledWith({ message: I18N_VSA_ERROR_STAGES });
});
});
describe('receiveGroupStagesSuccess', () => {
it(`commits the ${types.RECEIVE_GROUP_STAGES_SUCCESS} mutation'`, () => {
return testAction(
......@@ -334,4 +385,56 @@ describe('Value Stream Analytics actions / stages', () => {
);
});
});
describe('fetchGroupStagesAndEvents', () => {
const { stages: groupStages, events } = customizableStagesAndEvents;
beforeEach(() => {
state = { ...state, ...mockGetters };
mock = new MockAdapter(axios);
mock
.onGet(endpoints.baseStagesEndpoint)
.reply(httpStatusCodes.OK, customizableStagesAndEvents);
});
it(`commits ${types.RECEIVE_STAGE_DATA_SUCCESS} with received data and headers on success`, () => {
return testAction({
action: actions.fetchGroupStagesAndEvents,
state,
expectedMutations: [
{ type: types.SET_STAGE_EVENTS, payload: [] },
{
type: types.SET_STAGE_EVENTS,
payload: events,
},
],
expectedActions: [
{ type: 'requestGroupStages' },
{ type: 'receiveGroupStagesSuccess', payload: groupStages },
],
});
});
describe('with a failing request', () => {
beforeEach(() => {
mock = new MockAdapter(axios);
mock.onGet(endpoints.baseStagesEndpoint).replyOnce(httpStatusCodes.NOT_FOUND, { error });
});
it('dispatches receiveGroupStagesError on error', () => {
return testAction({
action: actions.fetchGroupStagesAndEvents,
state,
expectedMutations: [{ type: types.SET_STAGE_EVENTS, payload: [] }],
expectedActions: [
{ type: 'requestGroupStages' },
{
type: 'receiveGroupStagesError',
payload: error,
},
],
});
});
});
});
});
......@@ -129,6 +129,24 @@ describe('Value Stream Analytics actions / value streams', () => {
});
});
describe('receiveCreateValueStreamSuccess', () => {
beforeEach(() => {
state = { ...state, valueStream: {} };
});
it(`will dispatch the "fetchCycleAnalyticsData" action and commit the ${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} mutation`, () => {
return testAction({
action: actions.receiveCreateValueStreamSuccess,
payload: selectedValueStream,
state,
expectedMutations: [
{ type: types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS, payload: selectedValueStream },
],
expectedActions: [{ type: 'fetchCycleAnalyticsData' }],
});
});
});
describe('updateValueStream', () => {
const payload = {
name: 'cool value stream',
......
......@@ -5,6 +5,7 @@ import * as getters from 'ee/analytics/cycle_analytics/store/getters';
import * as types from 'ee/analytics/cycle_analytics/store/mutation_types';
import testAction from 'helpers/vuex_action_helper';
import { createdAfter, createdBefore, currentGroup } from 'jest/cycle_analytics/mock_data';
import { I18N_VSA_ERROR_STAGES, I18N_VSA_ERROR_STAGE_MEDIAN } from '~/cycle_analytics/constants';
import createFlash from '~/flash';
import { allowedStages as stages, valueStreams } from '../mock_data';
......@@ -149,9 +150,7 @@ describe('Value Stream Analytics actions', () => {
commit: () => {},
})
.then(() => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching median data for stages',
});
expect(createFlash).toHaveBeenCalledWith({ message: I18N_VSA_ERROR_STAGE_MEDIAN });
});
});
......@@ -176,7 +175,7 @@ describe('Value Stream Analytics actions', () => {
})
.then(() => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching value stream analytics stages.',
message: I18N_VSA_ERROR_STAGES,
});
});
});
......
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