2021-09-04 01:27:46 +05:30
|
|
|
import {
|
|
|
|
transformStagesForPathNavigation,
|
|
|
|
medianTimeToParsedSeconds,
|
|
|
|
formatMedianValues,
|
|
|
|
filterStagesByHiddenStatus,
|
2021-12-11 22:18:48 +05:30
|
|
|
buildCycleAnalyticsInitialData,
|
2023-03-04 22:38:38 +05:30
|
|
|
} from '~/analytics/cycle_analytics/utils';
|
2021-09-04 01:27:46 +05:30
|
|
|
import {
|
|
|
|
selectedStage,
|
|
|
|
allowedStages,
|
|
|
|
stageMedians,
|
|
|
|
pathNavIssueMetric,
|
|
|
|
rawStageMedians,
|
|
|
|
} from './mock_data';
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
describe('Value stream analytics utils', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
describe('transformStagesForPathNavigation', () => {
|
|
|
|
const stages = allowedStages;
|
|
|
|
const response = transformStagesForPathNavigation({
|
|
|
|
stages,
|
|
|
|
medians: stageMedians,
|
|
|
|
selectedStage,
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('transforms the data as expected', () => {
|
|
|
|
it('returns an array of stages', () => {
|
|
|
|
expect(Array.isArray(response)).toBe(true);
|
|
|
|
expect(response.length).toBe(stages.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('selects the correct stage', () => {
|
|
|
|
const selected = response.filter((stage) => stage.selected === true)[0];
|
|
|
|
|
|
|
|
expect(selected.title).toBe(selectedStage.title);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('includes the correct metric for the associated stage', () => {
|
|
|
|
const issue = response.filter((stage) => stage.name === 'issue')[0];
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(issue.metric).toBe(pathNavIssueMetric);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('medianTimeToParsedSeconds', () => {
|
|
|
|
it.each`
|
|
|
|
value | result
|
|
|
|
${1036800} | ${'1w'}
|
|
|
|
${259200} | ${'3d'}
|
|
|
|
${172800} | ${'2d'}
|
|
|
|
${86400} | ${'1d'}
|
|
|
|
${1000} | ${'16m'}
|
|
|
|
${61} | ${'1m'}
|
|
|
|
${59} | ${'<1m'}
|
|
|
|
${0} | ${'-'}
|
|
|
|
`('will correctly parse $value seconds into $result', ({ value, result }) => {
|
|
|
|
expect(medianTimeToParsedSeconds(value)).toBe(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('formatMedianValues', () => {
|
|
|
|
const calculatedMedians = formatMedianValues(rawStageMedians);
|
|
|
|
|
|
|
|
it('returns an object with each stage and their median formatted for display', () => {
|
|
|
|
rawStageMedians.forEach(({ id, value }) => {
|
|
|
|
expect(calculatedMedians).toMatchObject({ [id]: medianTimeToParsedSeconds(value) });
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
describe('filterStagesByHiddenStatus', () => {
|
|
|
|
const hiddenStages = [{ title: 'three', hidden: true }];
|
|
|
|
const visibleStages = [
|
|
|
|
{ title: 'one', hidden: false },
|
|
|
|
{ title: 'two', hidden: false },
|
|
|
|
];
|
|
|
|
const mockStages = [...visibleStages, ...hiddenStages];
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
isHidden | result
|
|
|
|
${false} | ${visibleStages}
|
|
|
|
${undefined} | ${hiddenStages}
|
|
|
|
${true} | ${hiddenStages}
|
|
|
|
`('with isHidden=$isHidden returns matching stages', ({ isHidden, result }) => {
|
|
|
|
expect(filterStagesByHiddenStatus(mockStages, isHidden)).toEqual(result);
|
|
|
|
});
|
|
|
|
});
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe('buildCycleAnalyticsInitialData', () => {
|
|
|
|
let res = null;
|
|
|
|
const projectId = '5';
|
|
|
|
const createdAfter = '2021-09-01';
|
|
|
|
const createdBefore = '2021-11-06';
|
2023-06-20 00:43:36 +05:30
|
|
|
const groupPath = 'groups/fake-group';
|
2023-05-27 22:25:52 +05:30
|
|
|
const namespaceName = 'Fake project';
|
|
|
|
const namespaceFullPath = 'fake-group/fake-project';
|
2021-12-11 22:18:48 +05:30
|
|
|
const labelsPath = '/fake-group/fake-project/-/labels.json';
|
|
|
|
const milestonesPath = '/fake-group/fake-project/-/milestones.json';
|
|
|
|
const requestPath = '/fake-group/fake-project/-/value_stream_analytics';
|
|
|
|
|
|
|
|
const rawData = {
|
|
|
|
projectId,
|
|
|
|
createdBefore,
|
|
|
|
createdAfter,
|
2023-05-27 22:25:52 +05:30
|
|
|
namespaceName,
|
|
|
|
namespaceFullPath,
|
2021-12-11 22:18:48 +05:30
|
|
|
requestPath,
|
|
|
|
labelsPath,
|
|
|
|
milestonesPath,
|
|
|
|
groupPath,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('with minimal data', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
res = buildCycleAnalyticsInitialData(rawData);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the projectId', () => {
|
|
|
|
expect(res.projectId).toBe(parseInt(projectId, 10));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the date range', () => {
|
|
|
|
expect(res.createdBefore).toEqual(new Date(createdBefore));
|
|
|
|
expect(res.createdAfter).toEqual(new Date(createdAfter));
|
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('sets the namespace', () => {
|
|
|
|
expect(res.namespace.name).toBe(namespaceName);
|
|
|
|
expect(res.namespace.fullPath).toBe(namespaceFullPath);
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('sets the endpoints', () => {
|
2023-06-20 00:43:36 +05:30
|
|
|
expect(res.groupPath).toBe(groupPath);
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null when there is no stage', () => {
|
|
|
|
expect(res.selectedStage).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false for missing features', () => {
|
|
|
|
expect(res.features.cycleAnalyticsForGroups).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a stage set', () => {
|
|
|
|
const jsonStage = '{"id":"fakeStage","title":"fakeStage"}';
|
|
|
|
|
|
|
|
it('parses the selectedStage data', () => {
|
|
|
|
res = buildCycleAnalyticsInitialData({ ...rawData, stage: jsonStage });
|
|
|
|
|
|
|
|
const { selectedStage: stage } = res;
|
|
|
|
|
|
|
|
expect(stage.id).toBe('fakeStage');
|
|
|
|
expect(stage.title).toBe('fakeStage');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with features set', () => {
|
|
|
|
const fakeFeatures = { cycleAnalyticsForGroups: true };
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
window.gon = { licensed_features: fakeFeatures };
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('sets the feature flags', () => {
|
|
|
|
res = buildCycleAnalyticsInitialData({
|
|
|
|
...rawData,
|
|
|
|
});
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(res.features).toMatchObject(fakeFeatures);
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|