Commit b128e665 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Adds vuex action and mutation specs

Added jest specs for the vuex actions and mutations
needed for updating a value stream

Minor data refactor
parent a4738af3
......@@ -79,7 +79,7 @@ export const defaultCustomStageFields = { ...defaultFields, custom: true };
*
* More information: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49094#note_464116439
*/
export const BASE_DEFAULT_STAGE_CONFIG = [
const BASE_DEFAULT_STAGE_CONFIG = [
{
id: 'issue',
startEventIdentifier: ['issue_created'],
......
......@@ -16,6 +16,13 @@ import {
valueStreams,
} from '../mock_data';
const mockStartEventIdentifier = 'issue_first_mentioned_in_commit';
const mockEndEventIdentifier = 'issue_first_added_to_board';
const mockEvents = {
startEventIdentifier: mockStartEventIdentifier,
endEventIdentifier: mockEndEventIdentifier,
};
const group = { fullPath: 'fake_group_full_path' };
const milestonesPath = 'fake_milestones_path';
const labelsPath = 'fake_labels_path';
......@@ -904,7 +911,18 @@ describe('Value Stream Analytics actions', () => {
});
describe('createValueStream', () => {
const payload = { name: 'cool value stream' };
const payload = {
name: 'cool value stream',
stages: [
{
...selectedStage,
...mockEvents,
id: null,
},
{ ...hiddenStage, ...mockEvents },
],
};
const createResp = { id: 'new value stream', is_custom: true, ...payload };
beforeEach(() => {
......@@ -957,6 +975,70 @@ describe('Value Stream Analytics actions', () => {
});
});
describe('updateValueStream', () => {
const payload = {
name: 'cool value stream',
stages: [
{
...selectedStage,
...mockEvents,
id: 'stage-1',
},
{ ...hiddenStage, ...mockEvents },
],
};
const createResp = { id: 'new value stream', is_custom: true, ...payload };
beforeEach(() => {
state = { currentGroup };
});
describe('with no errors', () => {
beforeEach(() => {
mock.onPut(endpoints.valueStreamData).replyOnce(httpStatusCodes.OK, createResp);
});
it(`commits the ${types.REQUEST_UPDATE_VALUE_STREAM} and ${types.RECEIVE_UPDATE_VALUE_STREAM_SUCCESS} actions`, () => {
return testAction(
actions.updateValueStream,
payload,
state,
[
{
type: types.REQUEST_UPDATE_VALUE_STREAM,
},
],
[{ type: 'receiveUpdateValueStreamSuccess', payload: createResp }],
);
});
});
describe('with errors', () => {
const errors = { name: ['is taken'] };
const message = { message: 'error' };
const resp = { message, payload: { errors } };
beforeEach(() => {
mock.onPut(endpoints.valueStreamData).replyOnce(httpStatusCodes.NOT_FOUND, resp);
});
it(`commits the ${types.REQUEST_UPDATE_VALUE_STREAM} and ${types.RECEIVE_UPDATE_VALUE_STREAM_ERROR} actions `, () => {
return testAction(
actions.updateValueStream,
payload,
state,
[
{ type: types.REQUEST_UPDATE_VALUE_STREAM },
{
type: types.RECEIVE_UPDATE_VALUE_STREAM_ERROR,
payload: { message, data: payload, errors },
},
],
[],
);
});
});
});
describe('deleteValueStream', () => {
const payload = 'my-fake-value-stream';
......
......@@ -49,6 +49,10 @@ describe('Value Stream Analytics mutations', () => {
${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} | ${'isCreatingValueStream'} | ${false}
${types.REQUEST_CREATE_VALUE_STREAM} | ${'createValueStreamErrors'} | ${{}}
${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} | ${'createValueStreamErrors'} | ${{}}
${types.REQUEST_UPDATE_VALUE_STREAM} | ${'isEditingValueStream'} | ${true}
${types.RECEIVE_UPDATE_VALUE_STREAM_SUCCESS} | ${'isEditingValueStream'} | ${false}
${types.REQUEST_UPDATE_VALUE_STREAM} | ${'createValueStreamErrors'} | ${{}}
${types.RECEIVE_UPDATE_VALUE_STREAM_SUCCESS} | ${'createValueStreamErrors'} | ${{}}
${types.REQUEST_DELETE_VALUE_STREAM} | ${'isDeletingValueStream'} | ${true}
${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'isDeletingValueStream'} | ${false}
${types.REQUEST_DELETE_VALUE_STREAM} | ${'deleteValueStreamError'} | ${null}
......@@ -61,17 +65,32 @@ describe('Value Stream Analytics mutations', () => {
expect(state[stateKey]).toEqual(value);
});
const valueStreamErrors = {
data: { stages },
errors: {
name: ['is required'],
stages: { 1: { name: "Can't be blank" } },
},
};
const expectedValueStreamErrors = {
name: ['is required'],
stages: [{}, { name: "Can't be blank" }, {}, {}, {}, {}, {}, {}],
};
it.each`
mutation | payload | expectedState
${types.SET_FEATURE_FLAGS} | ${{ hasDurationChart: true }} | ${{ featureFlags: { hasDurationChart: true } }}
${types.SET_SELECTED_PROJECTS} | ${selectedProjects} | ${{ selectedProjects }}
${types.SET_DATE_RANGE} | ${{ startDate, endDate }} | ${{ startDate, endDate }}
${types.SET_SELECTED_STAGE} | ${{ id: 'first-stage' }} | ${{ selectedStage: { id: 'first-stage' } }}
${types.RECEIVE_CREATE_VALUE_STREAM_ERROR} | ${{ data: { stages }, errors: { name: ['is required'] } }} | ${{ createValueStreamErrors: { name: ['is required'] }, isCreatingValueStream: false }}
${types.RECEIVE_DELETE_VALUE_STREAM_ERROR} | ${'Some error occurred'} | ${{ deleteValueStreamError: 'Some error occurred' }}
${types.RECEIVE_VALUE_STREAMS_SUCCESS} | ${valueStreams} | ${{ valueStreams, isLoadingValueStreams: false }}
${types.SET_SELECTED_VALUE_STREAM} | ${valueStreams[1].id} | ${{ selectedValueStream: {} }}
${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} | ${valueStreams[1]} | ${{ selectedValueStream: valueStreams[1] }}
mutation | payload | expectedState
${types.SET_FEATURE_FLAGS} | ${{ hasDurationChart: true }} | ${{ featureFlags: { hasDurationChart: true } }}
${types.SET_SELECTED_PROJECTS} | ${selectedProjects} | ${{ selectedProjects }}
${types.SET_DATE_RANGE} | ${{ startDate, endDate }} | ${{ startDate, endDate }}
${types.SET_SELECTED_STAGE} | ${{ id: 'first-stage' }} | ${{ selectedStage: { id: 'first-stage' } }}
${types.RECEIVE_CREATE_VALUE_STREAM_ERROR} | ${valueStreamErrors} | ${{ createValueStreamErrors: expectedValueStreamErrors, isCreatingValueStream: false }}
${types.RECEIVE_UPDATE_VALUE_STREAM_ERROR} | ${valueStreamErrors} | ${{ createValueStreamErrors: expectedValueStreamErrors, isEditingValueStream: false }}
${types.RECEIVE_DELETE_VALUE_STREAM_ERROR} | ${'Some error occurred'} | ${{ deleteValueStreamError: 'Some error occurred' }}
${types.RECEIVE_VALUE_STREAMS_SUCCESS} | ${valueStreams} | ${{ valueStreams, isLoadingValueStreams: false }}
${types.SET_SELECTED_VALUE_STREAM} | ${valueStreams[1].id} | ${{ selectedValueStream: {} }}
${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} | ${valueStreams[1]} | ${{ selectedValueStream: valueStreams[1] }}
${types.RECEIVE_UPDATE_VALUE_STREAM_SUCCESS} | ${valueStreams[1]} | ${{ selectedValueStream: valueStreams[1] }}
`(
'$mutation with payload $payload will update state with $expectedState',
({ mutation, payload, expectedState }) => {
......
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