Commit 0fc6db6a authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Fix cycle analytics jest specs

Moves the timeSummaryForPathNavigation and medianTimeToParsedSeconds
to CE and updates related jest tests.
parent 59f35ed4
import { roundToNearestHalf, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { dasherize } from '~/lib/utils/text_utility';
import { unescape } from 'lodash';
import { sanitize } from '~/lib/dompurify';
import {
newDate,
dayAfter,
secondsToDays,
getDatesInRange,
parseSeconds,
} from '~/lib/utils/datetime_utility';
import { parseSeconds } from '~/lib/utils/datetime_utility';
import { dasherize } from '~/lib/utils/text_utility';
import { __, s__, sprintf } from '../locale';
import DEFAULT_EVENT_OBJECTS from './default_event_objects';
import { OVERVIEW_STAGE_ID } from './constants';
const EMPTY_STAGE_TEXTS = {
issue: __(
......
......@@ -17,12 +17,11 @@ import {
toggleSelectedLabel,
prepareTimeMetricsData,
prepareStageErrors,
timeSummaryForPathNavigation,
formatMedianValuesWithOverview,
medianTimeToParsedSeconds,
} from 'ee/analytics/cycle_analytics/utils';
import { toYmd } from 'ee/analytics/shared/utils';
import { rawStageMedians } from 'jest/cycle_analytics/mock_data';
import { medianTimeToParsedSeconds } from '~/cycle_analytics/utils';
import { getDatesInRange } from '~/lib/utils/datetime_utility';
import { slugify } from '~/lib/utils/text_utility';
import {
......@@ -364,37 +363,6 @@ describe('Value Stream Analytics utils', () => {
});
});
describe('timeSummaryForPathNavigation', () => {
it.each`
unit | value | result
${'months'} | ${1.5} | ${'1.5M'}
${'weeks'} | ${1.25} | ${'1.5w'}
${'days'} | ${2} | ${'2d'}
${'hours'} | ${10} | ${'10h'}
${'minutes'} | ${20} | ${'20m'}
${'seconds'} | ${10} | ${'<1m'}
${'seconds'} | ${0} | ${'-'}
`('will format $value $unit to $result', ({ unit, value, result }) => {
expect(timeSummaryForPathNavigation({ [unit]: value })).toEqual(result);
});
});
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)).toEqual(result);
});
});
describe('formatMedianValuesWithOverview', () => {
const calculatedMedians = formatMedianValuesWithOverview(rawStageMedians);
......
......@@ -29,6 +29,7 @@ export const summary = [
];
const issueStage = {
id: 'issue',
title: 'Issue',
name: 'issue',
legend: '',
......@@ -37,6 +38,7 @@ const issueStage = {
};
const planStage = {
id: 'plan',
title: 'Plan',
name: 'plan',
legend: '',
......@@ -45,6 +47,7 @@ const planStage = {
};
const codeStage = {
id: 'code',
title: 'Code',
name: 'code',
legend: '',
......@@ -53,6 +56,7 @@ const codeStage = {
};
const testStage = {
id: 'test',
title: 'Test',
name: 'test',
legend: '',
......@@ -61,6 +65,7 @@ const testStage = {
};
const reviewStage = {
id: 'review',
title: 'Review',
name: 'review',
legend: '',
......@@ -69,6 +74,7 @@ const reviewStage = {
};
const stagingStage = {
id: 'staging',
title: 'Staging',
name: 'staging',
legend: '',
......@@ -85,6 +91,7 @@ export const selectedStage = {
'The issue stage shows the time it takes from creating an issue to assigning the issue to a milestone, or add the issue to a list on your Issue Board. Begin creating issues to see data for this stage.',
component: 'stage-issue-component',
slug: 'issue',
id: 'issue',
};
export const stats = [issueStage, planStage, codeStage, testStage, reviewStage, stagingStage];
......@@ -206,7 +213,7 @@ export const convertedEvents = rawEvents.map((ev) =>
convertObjectPropsToCamelCase(ev, { deep: true }),
);
export const pathNavIssueMetric = 388800;
export const pathNavIssueMetric = 172800;
export const stageMediansWithNumericIds = rawStageMedians.reduce((acc, { id, value }) => {
const { id: stageId } = getStageByTitle(convertedData.stages, id);
......
......@@ -2,6 +2,9 @@ import {
decorateEvents,
decorateData,
transformStagesForPathNavigation,
timeSummaryForPathNavigation,
medianTimeToParsedSeconds,
formatMedianValues,
} from '~/cycle_analytics/utils';
import {
selectedStage,
......@@ -11,7 +14,7 @@ import {
allowedStages,
stageMediansWithNumericIds,
pathNavIssueMetric,
stageCounts,
rawStageMedians,
} from './mock_data';
describe('Value stream analytics utils', () => {
......@@ -94,7 +97,6 @@ describe('Value stream analytics utils', () => {
stages,
medians: stageMediansWithNumericIds,
selectedStage,
stageCounts,
});
describe('transforms the data as expected', () => {
......@@ -116,4 +118,45 @@ describe('Value stream analytics utils', () => {
});
});
});
describe('timeSummaryForPathNavigation', () => {
it.each`
unit | value | result
${'months'} | ${1.5} | ${'1.5M'}
${'weeks'} | ${1.25} | ${'1.5w'}
${'days'} | ${2} | ${'2d'}
${'hours'} | ${10} | ${'10h'}
${'minutes'} | ${20} | ${'20m'}
${'seconds'} | ${10} | ${'<1m'}
${'seconds'} | ${0} | ${'-'}
`('will format $value $unit to $result', ({ unit, value, result }) => {
expect(timeSummaryForPathNavigation({ [unit]: value })).toEqual(result);
});
});
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)).toEqual(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) });
});
});
});
});
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