Commit d4e88f6b authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Added additional specs

parent f9c64e5b
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
import Api from 'ee/api'; import Api from 'ee/api';
import { __ } from '~/locale'; import { __ } from '~/locale';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { slugify } from '~/lib/utils/text_utility';
import MetricCard from '../../shared/components/metric_card.vue'; import MetricCard from '../../shared/components/metric_card.vue';
import { removeFlash } from '../utils'; import { removeFlash, prepareTimeMetricsData } from '../utils';
export default { export default {
name: 'RecentActivityCard', name: 'RecentActivityCard',
...@@ -45,11 +44,7 @@ export default { ...@@ -45,11 +44,7 @@ export default {
this.additionalParams ? this.additionalParams : {}, this.additionalParams ? this.additionalParams : {},
) )
.then(({ data }) => { .then(({ data }) => {
this.data = data.map(({ title: label, value }) => ({ this.data = prepareTimeMetricsData(data);
value: value || '-',
label,
key: slugify(label),
}));
}) })
.catch(() => { .catch(() => {
createFlash( createFlash(
......
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
import { getDatesInRange } from '~/lib/utils/datetime_utility'; import { getDatesInRange } from '~/lib/utils/datetime_utility';
import { slugify } from '~/lib/utils/text_utility';
import { import {
isStartEvent, isStartEvent,
isLabelEvent, isLabelEvent,
...@@ -322,6 +323,7 @@ describe('Cycle analytics utils', () => { ...@@ -322,6 +323,7 @@ describe('Cycle analytics utils', () => {
it('will remove an id that exists', () => { it('will remove an id that exists', () => {
expect(toggleSelectedLabel({ selectedLabelIds, value: 2 })).toEqual([1, 3]); expect(toggleSelectedLabel({ selectedLabelIds, value: 2 })).toEqual([1, 3]);
}); });
it('will add an id that does not exist', () => { it('will add an id that does not exist', () => {
expect(toggleSelectedLabel({ selectedLabelIds, value: 4 })).toEqual([1, 2, 3, 4]); expect(toggleSelectedLabel({ selectedLabelIds, value: 4 })).toEqual([1, 2, 3, 4]);
}); });
...@@ -373,27 +375,25 @@ describe('Cycle analytics utils', () => { ...@@ -373,27 +375,25 @@ describe('Cycle analytics utils', () => {
describe('prepareTimeMetricsData', () => { describe('prepareTimeMetricsData', () => {
let prepared; let prepared;
const [{ title: firstTitle }, { title: secondTitle }] = timeMetricsData;
const firstKey = slugify(firstTitle);
const secondKey = slugify(secondTitle);
beforeEach(() => { beforeEach(() => {
prepared = prepareTimeMetricsData(timeMetricsData); prepared = prepareTimeMetricsData(timeMetricsData, {
[firstKey]: 'Is a value that is good',
});
}); });
it('will add a `key` based on the title', () => { it('will add a `key` based on the title', () => {
expect(timeMetricsData).not.toMatchObject([{ key: 'lead-time' }, { key: 'cycle-time' }]); expect(prepared).toMatchObject([{ key: firstKey }, { key: secondKey }]);
expect(prepared).toMatchObject([{ key: 'lead-time' }, { key: 'cycle-time' }]);
}); });
it('will replace the title with a `label` key', () => { it('will add a `label` key', () => {
expect(timeMetricsData).not.toMatchObject([{ label: 'Lead Time' }, { label: 'Cycle Time' }]);
expect(prepared).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', () => { it('will add a 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([ expect(prepared).toMatchObject([
{ tooltipText: 'Is a value that is good' }, { tooltipText: 'Is a value that is good' },
{ tooltipText: '' }, { 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