Commit 85e2d719 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Move additional data to mock file

Deduplicates the logic for label events
into a single place in the mock_data file.
parent c98eadce
import Vue from 'vue';
import { mount } from '@vue/test-utils';
import CustomStageForm from 'ee/analytics/cycle_analytics/components/custom_stage_form.vue';
import { customStageEvents, groupLabels } from '../mock_data';
const startEvents = customStageEvents.filter(ev => ev.canBeStartEvent);
const stopEvents = customStageEvents.filter(ev => !ev.canBeStartEvent);
// const labelStartEvent = startEvents.find(({ type }) => type === 'label'); // returning 0, currently no label events seeded
// TODO: the shim below should be removed once we have label events seeding
const labelStartEvent = { ...startEvents[0], type: 'label' };
const firstAllowedStopEvent = labelStartEvent.allowedEndEvents[0];
// We need to enusre that the stop event can be applied to the start event
const labelStopEvent = {
...stopEvents.find(ev => ev.identifier === firstAllowedStopEvent),
type: 'label',
};
const events = [
...startEvents.slice(1),
...stopEvents.filter(ev => ev.identifier !== firstAllowedStopEvent),
import {
groupLabels,
customStageEvents as events,
labelStartEvent,
labelStopEvent,
];
// console.log('events', events);
customStageStartEvents as startEvents,
customStageStopEvents as stopEvents,
} from '../mock_data';
const initData = {
name: 'Cool stage pre',
startEvent: 'issue_label_added',
startEvent: labelStartEvent.identifier,
startEventLabel: groupLabels[0].id,
stopEvent: 'issue_label_removed',
stopEvent: labelStopEvent.identifier,
stopEventLabel: groupLabels[1].id,
};
......
......@@ -56,4 +56,23 @@ export const stagingEvents = stageFixtures.staging;
export const productionEvents = stageFixtures.production;
const { events: rawCustomStageEvents } = getJSONFixture('analytics/cycle_analytics/stages.json');
export const customStageEvents = rawCustomStageEvents.map(deepCamelCase);
const camelCasedStageEvents = rawCustomStageEvents.map(deepCamelCase);
export const customStageStartEvents = camelCasedStageEvents.filter(ev => ev.canBeStartEvent);
export const customStageStopEvents = camelCasedStageEvents.filter(ev => !ev.canBeStartEvent);
// TODO: the shim below should be removed once we have label events seeding
export const labelStartEvent = { ...customStageStartEvents[0], type: 'label' };
const firstAllowedStopEvent = labelStartEvent.allowedEndEvents[0];
// We need to enusre that the stop event can be applied to the start event
export const labelStopEvent = {
...customStageStopEvents.find(ev => ev.identifier === firstAllowedStopEvent),
type: 'label',
};
export const customStageEvents = [
...customStageStartEvents.filter(ev => ev.identifier !== labelStartEvent.identifier),
...customStageStopEvents.filter(ev => ev.identifier !== labelStopEvent.identifier),
labelStartEvent,
labelStopEvent,
];
......@@ -6,32 +6,24 @@ import {
eventsByIdentifier,
getLabelEventsIdentifiers,
} from 'ee/analytics/cycle_analytics/utils';
import { customStageEvents } from './mock_data';
const startEvents = customStageEvents.filter(ev => ev.canBeStartEvent);
const stopEvents = customStageEvents.filter(ev => !ev.canBeStartEvent);
const startEvent = customStageEvents.find(ev => ev.canBeStartEvent);
const endEvent = customStageEvents.find(ev => !ev.canBeStartEvent);
const labelStartEvent = { ...startEvent, type: 'label' };
const labelStopEvent = { ...endEvent, type: 'label' };
const labelEvents = [labelStartEvent, labelStopEvent].map(i => i.identifier);
const events = [
...startEvents.filter(ev => ev.identifier !== labelStartEvent.identifier),
...stopEvents.filter(ev => ev.identifier !== labelStopEvent.identifier),
import {
customStageEvents as events,
labelStartEvent,
labelStopEvent,
];
customStageStartEvents as startEvents,
customStageStopEvents as stopEvents,
} from './mock_data';
const labelEvents = [labelStartEvent, labelStopEvent].map(i => i.identifier);
describe('Cycle analytics utils', () => {
describe('isStartEvent', () => {
it('will return true for a valid start event', () => {
expect(isStartEvent(startEvent)).toEqual(true);
expect(isStartEvent(startEvents[0])).toEqual(true);
});
it('will return false for input that is not a start event', () => {
[endEvent, {}, [], null, undefined].forEach(ev => {
[stopEvents[0], {}, [], null, undefined].forEach(ev => {
expect(isStartEvent(ev)).toEqual(false);
});
});
......
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