Commit 0c45ed30 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 6d8133bb
import { roundToNearestHalf, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { roundToNearestHalf, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { dasherize } from '~/lib/utils/text_utility';
import { unescape } from 'lodash'; import { unescape } from 'lodash';
import { sanitize } from '~/lib/dompurify'; import { sanitize } from '~/lib/dompurify';
import { import { parseSeconds } from '~/lib/utils/datetime_utility';
newDate, import { dasherize } from '~/lib/utils/text_utility';
dayAfter,
secondsToDays,
getDatesInRange,
parseSeconds,
} from '~/lib/utils/datetime_utility';
import { __, s__, sprintf } from '../locale'; import { __, s__, sprintf } from '../locale';
import DEFAULT_EVENT_OBJECTS from './default_event_objects'; import DEFAULT_EVENT_OBJECTS from './default_event_objects';
import { OVERVIEW_STAGE_ID } from './constants';
const EMPTY_STAGE_TEXTS = { const EMPTY_STAGE_TEXTS = {
issue: __( issue: __(
......
...@@ -17,12 +17,11 @@ import { ...@@ -17,12 +17,11 @@ import {
toggleSelectedLabel, toggleSelectedLabel,
prepareTimeMetricsData, prepareTimeMetricsData,
prepareStageErrors, prepareStageErrors,
timeSummaryForPathNavigation,
formatMedianValuesWithOverview, formatMedianValuesWithOverview,
medianTimeToParsedSeconds,
} from 'ee/analytics/cycle_analytics/utils'; } from 'ee/analytics/cycle_analytics/utils';
import { toYmd } from 'ee/analytics/shared/utils'; import { toYmd } from 'ee/analytics/shared/utils';
import { rawStageMedians } from 'jest/cycle_analytics/mock_data'; import { rawStageMedians } from 'jest/cycle_analytics/mock_data';
import { medianTimeToParsedSeconds } from '~/cycle_analytics/utils';
import { getDatesInRange } from '~/lib/utils/datetime_utility'; import { getDatesInRange } from '~/lib/utils/datetime_utility';
import { slugify } from '~/lib/utils/text_utility'; import { slugify } from '~/lib/utils/text_utility';
import { import {
...@@ -364,37 +363,6 @@ describe('Value Stream Analytics utils', () => { ...@@ -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', () => { describe('formatMedianValuesWithOverview', () => {
const calculatedMedians = formatMedianValuesWithOverview(rawStageMedians); const calculatedMedians = formatMedianValuesWithOverview(rawStageMedians);
......
...@@ -29,6 +29,7 @@ export const summary = [ ...@@ -29,6 +29,7 @@ export const summary = [
]; ];
const issueStage = { const issueStage = {
id: 'issue',
title: 'Issue', title: 'Issue',
name: 'issue', name: 'issue',
legend: '', legend: '',
...@@ -37,6 +38,7 @@ const issueStage = { ...@@ -37,6 +38,7 @@ const issueStage = {
}; };
const planStage = { const planStage = {
id: 'plan',
title: 'Plan', title: 'Plan',
name: 'plan', name: 'plan',
legend: '', legend: '',
...@@ -45,6 +47,7 @@ const planStage = { ...@@ -45,6 +47,7 @@ const planStage = {
}; };
const codeStage = { const codeStage = {
id: 'code',
title: 'Code', title: 'Code',
name: 'code', name: 'code',
legend: '', legend: '',
...@@ -53,6 +56,7 @@ const codeStage = { ...@@ -53,6 +56,7 @@ const codeStage = {
}; };
const testStage = { const testStage = {
id: 'test',
title: 'Test', title: 'Test',
name: 'test', name: 'test',
legend: '', legend: '',
...@@ -61,6 +65,7 @@ const testStage = { ...@@ -61,6 +65,7 @@ const testStage = {
}; };
const reviewStage = { const reviewStage = {
id: 'review',
title: 'Review', title: 'Review',
name: 'review', name: 'review',
legend: '', legend: '',
...@@ -69,6 +74,7 @@ const reviewStage = { ...@@ -69,6 +74,7 @@ const reviewStage = {
}; };
const stagingStage = { const stagingStage = {
id: 'staging',
title: 'Staging', title: 'Staging',
name: 'staging', name: 'staging',
legend: '', legend: '',
...@@ -85,6 +91,7 @@ export const selectedStage = { ...@@ -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.', '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', component: 'stage-issue-component',
slug: 'issue', slug: 'issue',
id: 'issue',
}; };
export const stats = [issueStage, planStage, codeStage, testStage, reviewStage, stagingStage]; export const stats = [issueStage, planStage, codeStage, testStage, reviewStage, stagingStage];
...@@ -206,7 +213,7 @@ export const convertedEvents = rawEvents.map((ev) => ...@@ -206,7 +213,7 @@ export const convertedEvents = rawEvents.map((ev) =>
convertObjectPropsToCamelCase(ev, { deep: true }), convertObjectPropsToCamelCase(ev, { deep: true }),
); );
export const pathNavIssueMetric = 388800; export const pathNavIssueMetric = 172800;
export const stageMediansWithNumericIds = rawStageMedians.reduce((acc, { id, value }) => { export const stageMediansWithNumericIds = rawStageMedians.reduce((acc, { id, value }) => {
const { id: stageId } = getStageByTitle(convertedData.stages, id); const { id: stageId } = getStageByTitle(convertedData.stages, id);
......
...@@ -2,6 +2,9 @@ import { ...@@ -2,6 +2,9 @@ import {
decorateEvents, decorateEvents,
decorateData, decorateData,
transformStagesForPathNavigation, transformStagesForPathNavigation,
timeSummaryForPathNavigation,
medianTimeToParsedSeconds,
formatMedianValues,
} from '~/cycle_analytics/utils'; } from '~/cycle_analytics/utils';
import { import {
selectedStage, selectedStage,
...@@ -11,7 +14,7 @@ import { ...@@ -11,7 +14,7 @@ import {
allowedStages, allowedStages,
stageMediansWithNumericIds, stageMediansWithNumericIds,
pathNavIssueMetric, pathNavIssueMetric,
stageCounts, rawStageMedians,
} from './mock_data'; } from './mock_data';
describe('Value stream analytics utils', () => { describe('Value stream analytics utils', () => {
...@@ -94,7 +97,6 @@ describe('Value stream analytics utils', () => { ...@@ -94,7 +97,6 @@ describe('Value stream analytics utils', () => {
stages, stages,
medians: stageMediansWithNumericIds, medians: stageMediansWithNumericIds,
selectedStage, selectedStage,
stageCounts,
}); });
describe('transforms the data as expected', () => { describe('transforms the data as expected', () => {
...@@ -116,4 +118,45 @@ describe('Value stream analytics utils', () => { ...@@ -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