2021-07-15 14:09:37 -04:00
|
|
|
import { useFakeDate } from 'helpers/fake_date';
|
2021-04-21 05:09:15 -04:00
|
|
|
import * as types from '~/cycle_analytics/store/mutation_types';
|
|
|
|
import mutations from '~/cycle_analytics/store/mutations';
|
2021-10-12 11:12:08 -04:00
|
|
|
import {
|
|
|
|
PAGINATION_SORT_FIELD_END_EVENT,
|
|
|
|
PAGINATION_SORT_DIRECTION_DESC,
|
|
|
|
} from '~/cycle_analytics/constants';
|
2021-06-11 11:09:58 -04:00
|
|
|
import {
|
|
|
|
selectedStage,
|
2021-07-23 08:09:05 -04:00
|
|
|
rawIssueEvents,
|
|
|
|
issueEvents,
|
2021-06-11 11:09:58 -04:00
|
|
|
selectedValueStream,
|
|
|
|
rawValueStreamStages,
|
|
|
|
valueStreamStages,
|
2021-07-15 14:09:37 -04:00
|
|
|
rawStageMedians,
|
|
|
|
formattedStageMedians,
|
2021-08-06 14:09:57 -04:00
|
|
|
rawStageCounts,
|
|
|
|
stageCounts,
|
2021-10-12 11:12:08 -04:00
|
|
|
initialPaginationState as pagination,
|
2021-06-11 11:09:58 -04:00
|
|
|
} from '../mock_data';
|
2021-04-21 05:09:15 -04:00
|
|
|
|
|
|
|
let state;
|
2021-07-23 08:09:05 -04:00
|
|
|
const rawEvents = rawIssueEvents.events;
|
|
|
|
const convertedEvents = issueEvents.events;
|
2021-04-21 05:09:15 -04:00
|
|
|
const mockRequestPath = 'fake/request/path';
|
2021-07-15 14:09:37 -04:00
|
|
|
const mockCreatedAfter = '2020-06-18';
|
|
|
|
const mockCreatedBefore = '2020-07-18';
|
2021-04-21 05:09:15 -04:00
|
|
|
|
|
|
|
describe('Project Value Stream Analytics mutations', () => {
|
2021-07-15 14:09:37 -04:00
|
|
|
useFakeDate(2020, 6, 18);
|
|
|
|
|
2021-04-21 05:09:15 -04:00
|
|
|
beforeEach(() => {
|
2021-10-12 11:12:08 -04:00
|
|
|
state = { pagination };
|
2021-04-21 05:09:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
state = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
mutation | stateKey | value
|
2021-06-11 11:09:58 -04:00
|
|
|
${types.REQUEST_VALUE_STREAMS} | ${'valueStreams'} | ${[]}
|
|
|
|
${types.RECEIVE_VALUE_STREAMS_ERROR} | ${'valueStreams'} | ${[]}
|
|
|
|
${types.REQUEST_VALUE_STREAM_STAGES} | ${'stages'} | ${[]}
|
|
|
|
${types.RECEIVE_VALUE_STREAM_STAGES_ERROR} | ${'stages'} | ${[]}
|
2021-04-21 05:09:15 -04:00
|
|
|
${types.REQUEST_CYCLE_ANALYTICS_DATA} | ${'isLoading'} | ${true}
|
|
|
|
${types.REQUEST_CYCLE_ANALYTICS_DATA} | ${'hasError'} | ${false}
|
|
|
|
${types.RECEIVE_CYCLE_ANALYTICS_DATA_SUCCESS} | ${'hasError'} | ${false}
|
|
|
|
${types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR} | ${'isLoading'} | ${false}
|
|
|
|
${types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR} | ${'hasError'} | ${true}
|
|
|
|
${types.REQUEST_STAGE_DATA} | ${'isLoadingStage'} | ${true}
|
|
|
|
${types.REQUEST_STAGE_DATA} | ${'isEmptyStage'} | ${false}
|
|
|
|
${types.REQUEST_STAGE_DATA} | ${'hasError'} | ${false}
|
|
|
|
${types.REQUEST_STAGE_DATA} | ${'selectedStageEvents'} | ${[]}
|
|
|
|
${types.RECEIVE_STAGE_DATA_SUCCESS} | ${'isLoadingStage'} | ${false}
|
|
|
|
${types.RECEIVE_STAGE_DATA_SUCCESS} | ${'selectedStageEvents'} | ${[]}
|
|
|
|
${types.RECEIVE_STAGE_DATA_SUCCESS} | ${'hasError'} | ${false}
|
|
|
|
${types.RECEIVE_STAGE_DATA_ERROR} | ${'isLoadingStage'} | ${false}
|
|
|
|
${types.RECEIVE_STAGE_DATA_ERROR} | ${'selectedStageEvents'} | ${[]}
|
|
|
|
${types.RECEIVE_STAGE_DATA_ERROR} | ${'hasError'} | ${true}
|
|
|
|
${types.RECEIVE_STAGE_DATA_ERROR} | ${'isEmptyStage'} | ${true}
|
2021-07-15 14:09:37 -04:00
|
|
|
${types.REQUEST_STAGE_MEDIANS} | ${'medians'} | ${{}}
|
|
|
|
${types.RECEIVE_STAGE_MEDIANS_ERROR} | ${'medians'} | ${{}}
|
2021-08-06 14:09:57 -04:00
|
|
|
${types.REQUEST_STAGE_COUNTS} | ${'stageCounts'} | ${{}}
|
|
|
|
${types.RECEIVE_STAGE_COUNTS_ERROR} | ${'stageCounts'} | ${{}}
|
2021-04-21 05:09:15 -04:00
|
|
|
`('$mutation will set $stateKey to $value', ({ mutation, stateKey, value }) => {
|
2021-08-04 14:09:57 -04:00
|
|
|
mutations[mutation](state);
|
2021-04-21 05:09:15 -04:00
|
|
|
|
|
|
|
expect(state).toMatchObject({ [stateKey]: value });
|
|
|
|
});
|
|
|
|
|
2021-09-07 11:11:06 -04:00
|
|
|
const mockSetDatePayload = { createdAfter: mockCreatedAfter, createdBefore: mockCreatedBefore };
|
2021-08-04 14:09:57 -04:00
|
|
|
const mockInitialPayload = {
|
|
|
|
endpoints: { requestPath: mockRequestPath },
|
|
|
|
currentGroup: { title: 'cool-group' },
|
|
|
|
id: 1337,
|
2021-09-07 11:11:06 -04:00
|
|
|
...mockSetDatePayload,
|
2021-08-04 14:09:57 -04:00
|
|
|
};
|
|
|
|
const mockInitializedObj = {
|
|
|
|
endpoints: { requestPath: mockRequestPath },
|
2021-09-07 11:11:06 -04:00
|
|
|
...mockSetDatePayload,
|
2021-08-04 14:09:57 -04:00
|
|
|
};
|
|
|
|
|
2021-04-21 05:09:15 -04:00
|
|
|
it.each`
|
2021-08-04 14:09:57 -04:00
|
|
|
mutation | stateKey | value
|
|
|
|
${types.INITIALIZE_VSA} | ${'endpoints'} | ${{ requestPath: mockRequestPath }}
|
|
|
|
${types.INITIALIZE_VSA} | ${'createdAfter'} | ${mockCreatedAfter}
|
|
|
|
${types.INITIALIZE_VSA} | ${'createdBefore'} | ${mockCreatedBefore}
|
|
|
|
`('$mutation will set $stateKey', ({ mutation, stateKey, value }) => {
|
|
|
|
mutations[mutation](state, { ...mockInitialPayload });
|
|
|
|
|
|
|
|
expect(state).toMatchObject({ ...mockInitializedObj, [stateKey]: value });
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
2021-10-12 11:12:08 -04:00
|
|
|
mutation | payload | stateKey | value
|
|
|
|
${types.SET_DATE_RANGE} | ${mockSetDatePayload} | ${'createdAfter'} | ${mockCreatedAfter}
|
|
|
|
${types.SET_DATE_RANGE} | ${mockSetDatePayload} | ${'createdBefore'} | ${mockCreatedBefore}
|
|
|
|
${types.SET_LOADING} | ${true} | ${'isLoading'} | ${true}
|
|
|
|
${types.SET_LOADING} | ${false} | ${'isLoading'} | ${false}
|
|
|
|
${types.SET_SELECTED_VALUE_STREAM} | ${selectedValueStream} | ${'selectedValueStream'} | ${selectedValueStream}
|
|
|
|
${types.SET_PAGINATION} | ${pagination} | ${'pagination'} | ${{ ...pagination, sort: PAGINATION_SORT_FIELD_END_EVENT, direction: PAGINATION_SORT_DIRECTION_DESC }}
|
|
|
|
${types.SET_PAGINATION} | ${{ ...pagination, sort: 'duration', direction: 'asc' }} | ${'pagination'} | ${{ ...pagination, sort: 'duration', direction: 'asc' }}
|
2021-11-12 22:09:49 -05:00
|
|
|
${types.SET_SELECTED_STAGE} | ${selectedStage} | ${'selectedStage'} | ${selectedStage}
|
2021-10-12 11:12:08 -04:00
|
|
|
${types.RECEIVE_VALUE_STREAMS_SUCCESS} | ${[selectedValueStream]} | ${'valueStreams'} | ${[selectedValueStream]}
|
|
|
|
${types.RECEIVE_VALUE_STREAM_STAGES_SUCCESS} | ${{ stages: rawValueStreamStages }} | ${'stages'} | ${valueStreamStages}
|
|
|
|
${types.RECEIVE_STAGE_MEDIANS_SUCCESS} | ${rawStageMedians} | ${'medians'} | ${formattedStageMedians}
|
|
|
|
${types.RECEIVE_STAGE_COUNTS_SUCCESS} | ${rawStageCounts} | ${'stageCounts'} | ${stageCounts}
|
2021-04-21 05:09:15 -04:00
|
|
|
`(
|
|
|
|
'$mutation with $payload will set $stateKey to $value',
|
|
|
|
({ mutation, payload, stateKey, value }) => {
|
|
|
|
mutations[mutation](state, payload);
|
|
|
|
|
|
|
|
expect(state).toMatchObject({ [stateKey]: value });
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('with a stage selected', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
state = {
|
|
|
|
selectedStage,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
2021-08-04 14:09:57 -04:00
|
|
|
mutation | payload | stateKey | value
|
|
|
|
${types.RECEIVE_STAGE_DATA_SUCCESS} | ${[]} | ${'isEmptyStage'} | ${true}
|
|
|
|
${types.RECEIVE_STAGE_DATA_SUCCESS} | ${rawEvents} | ${'selectedStageEvents'} | ${convertedEvents}
|
|
|
|
${types.RECEIVE_STAGE_DATA_SUCCESS} | ${rawEvents} | ${'isEmptyStage'} | ${false}
|
2021-07-15 14:09:37 -04:00
|
|
|
`(
|
|
|
|
'$mutation with $payload will set $stateKey to $value',
|
|
|
|
({ mutation, payload, stateKey, value }) => {
|
|
|
|
mutations[mutation](state, payload);
|
|
|
|
|
|
|
|
expect(state).toMatchObject({ [stateKey]: value });
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2021-04-21 05:09:15 -04:00
|
|
|
});
|