Commit f9c64e5b authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Added additional specs

parent 58ae16f9
...@@ -379,6 +379,28 @@ export const transformStagesForPathNavigation = ({ stages, medians, selectedStag ...@@ -379,6 +379,28 @@ export const transformStagesForPathNavigation = ({ stages, medians, selectedStag
); );
}; };
/**
* @typedef {Object} MetricData
* @property {String} title - Title of the metric measured
* @property {String} value - String representing the decimal point value, e.g '1.5'
* @property {String} [unit] - String representing the decimal point value, e.g '1.5'
*
* @typedef {Object} TransformedMetricData
* @property {String} label - Title of the metric measured
* @property {String} value - String representing the decimal point value, e.g '1.5'
* @property {String} key - Slugified string based on the 'title'
* @property {String} [tooltipText] - String to display for aa tooltip
* @property {String} [unit] - String representing the decimal point value, e.g '1.5'
*/
/**
* Prepares metric data to be rendered in the metric_card component
*
* @param {MetricData[]} data - The metric data to be rendered
* @param {Object} [tooltipText] - Key value pair of strings to display in the tooltip
* @returns {TransformedMetricData[]} An array of metrics ready to render in the metric_card
*/
export const prepareTimeMetricsData = (data = [], tooltipText = {}) => export const prepareTimeMetricsData = (data = [], tooltipText = {}) =>
data.map(({ title: label, ...rest }) => { data.map(({ title: label, ...rest }) => {
const key = slugify(label); const key = slugify(label);
......
...@@ -17,6 +17,7 @@ import { ...@@ -17,6 +17,7 @@ import {
orderByDate, orderByDate,
toggleSelectedLabel, toggleSelectedLabel,
transformStagesForPathNavigation, transformStagesForPathNavigation,
prepareTimeMetricsData,
} 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 { import {
...@@ -38,6 +39,7 @@ import { ...@@ -38,6 +39,7 @@ import {
stageMediansWithNumericIds, stageMediansWithNumericIds,
totalStage, totalStage,
pathNavIssueMetric, pathNavIssueMetric,
timeMetricsData,
} from './mock_data'; } from './mock_data';
import { CAPITALIZED_STAGE_NAME, PATH_HOME_ICON } from 'ee/analytics/cycle_analytics/constants'; import { CAPITALIZED_STAGE_NAME, PATH_HOME_ICON } from 'ee/analytics/cycle_analytics/constants';
...@@ -368,4 +370,34 @@ describe('Cycle analytics utils', () => { ...@@ -368,4 +370,34 @@ describe('Cycle analytics utils', () => {
}); });
}); });
}); });
describe('prepareTimeMetricsData', () => {
let prepared;
beforeEach(() => {
prepared = prepareTimeMetricsData(timeMetricsData);
});
it('will add a `key` based on the title', () => {
expect(timeMetricsData).not.toMatchObject([{ key: 'lead-time' }, { key: 'cycle-time' }]);
expect(prepared).toMatchObject([{ key: 'lead-time' }, { key: 'cycle-time' }]);
});
it('will replace the title with a `label` key', () => {
expect(timeMetricsData).not.toMatchObject([{ label: 'Lead Time' }, { label: 'Cycle Time' }]);
expect(prepared).toMatchObject([{ label: 'Lead Time' }, { label: 'Cycle Time' }]);
});
it('will add tooltip text using the key if it is provided', () => {
prepared = prepareTimeMetricsData(timeMetricsData, {
'lead-time': 'Is a value that is good',
});
expect(timeMetricsData).not.toMatchObject([{ tooltipText: 'Is a value that is good' }]);
expect(prepared).toMatchObject([
{ tooltipText: 'Is a value that is good' },
{ tooltipText: '' },
]);
});
});
}); });
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