Commit ad8cfd3b authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Fix empty unit display of time metrics

The unit should only display when we
have a value > 0

Added changelog entry
parent 0655ca2a
...@@ -25,7 +25,7 @@ export default { ...@@ -25,7 +25,7 @@ export default {
methods: { methods: {
valueText(metric) { valueText(metric) {
const { value = null, unit = null } = metric; const { value = null, unit = null } = metric;
if (!value) return '-'; if (!value || value === '-') return '-';
return unit && value ? `${value} ${unit}` : value; return unit && value ? `${value} ${unit}` : value;
}, },
}, },
......
---
title: Fix empty unit display of time metrics
merge_request: 32388
author:
type: fixed
...@@ -2,14 +2,17 @@ import { mount } from '@vue/test-utils'; ...@@ -2,14 +2,17 @@ import { mount } from '@vue/test-utils';
import { GlSkeletonLoading } from '@gitlab/ui'; import { GlSkeletonLoading } from '@gitlab/ui';
import MetricCard from 'ee/analytics/shared/components/metric_card.vue'; import MetricCard from 'ee/analytics/shared/components/metric_card.vue';
const defaultProps = { const metrics = [
title: 'My fancy title',
metrics: [
{ key: 'first_metric', value: 10, label: 'First metric', unit: 'days' }, { key: 'first_metric', value: 10, label: 'First metric', unit: 'days' },
{ key: 'second_metric', value: 20, label: 'Yet another metric' }, { key: 'second_metric', value: 20, label: 'Yet another metric' },
{ key: 'third_metric', value: null, label: 'Metric without value', unit: 'parsecs' }, { key: 'third_metric', value: null, label: 'Null metric without value', unit: 'parsecs' },
], { key: 'fourth_metric', value: '-', label: 'Metric without value', unit: 'parsecs' },
];
const defaultProps = {
title: 'My fancy title',
isLoading: false, isLoading: false,
metrics,
}; };
describe('MetricCard', () => { describe('MetricCard', () => {
...@@ -68,47 +71,22 @@ describe('MetricCard', () => { ...@@ -68,47 +71,22 @@ describe('MetricCard', () => {
}); });
it('renders two metrics', () => { it('renders two metrics', () => {
expect(findMetricItem()).toHaveLength(3); expect(findMetricItem()).toHaveLength(metrics.length);
}); });
describe.each` describe.each`
columnIndex | label | value columnIndex | label | value | unit
${0} | ${'First metric'} | ${10} ${0} | ${'First metric'} | ${10} | ${' days'}
${1} | ${'Yet another metric'} | ${20} ${1} | ${'Yet another metric'} | ${20} | ${''}
${2} | ${'Metric without value'} | ${'-'} ${2} | ${'Null metric without value'} | ${'-'} | ${''}
`('metric columns', ({ columnIndex, label, value }) => { ${3} | ${'Metric without value'} | ${'-'} | ${''}
it(`renders "${label}" as label`, () => { `('metric columns', ({ columnIndex, label, value, unit }) => {
expect( it(`renders ${value}${unit} ${label}`, () => {
findMetricItem()
.at(columnIndex)
.text(),
).toContain(label);
});
it(`renders ${value} as value`, () => {
expect( expect(
findMetricItem() findMetricItem()
.at(columnIndex) .at(columnIndex)
.text(), .text(),
).toContain(value); ).toEqual(`${value}${unit} ${label}`);
});
});
describe('units', () => {
it(`renders when there is a value`, () => {
expect(
findMetricItem()
.at(0)
.text(),
).toContain('10 days');
});
it(`does not render without a value`, () => {
expect(
findMetricItem()
.at(2)
.text(),
).toContain('-');
}); });
}); });
}); });
......
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