Commit ab657894 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '232771-enable-unitless-single-stat' into 'master'

Enable unitless single stat

Closes #232771

See merge request gitlab-org/gitlab!39067
parents 4f27df25 9b4e17a4
...@@ -50,7 +50,7 @@ export default { ...@@ -50,7 +50,7 @@ export default {
} }
formatter = getFormatter(SUPPORTED_FORMATS.number); formatter = getFormatter(SUPPORTED_FORMATS.number);
return `${formatter(this.queryResult, defaultPrecision)}${this.queryInfo.unit}`; return `${formatter(this.queryResult, defaultPrecision)}${this.queryInfo.unit ?? ''}`;
}, },
graphTitle() { graphTitle() {
return this.queryInfo.label; return this.queryInfo.label;
......
---
title: Support unitless single stat chart in metrics dashboards
merge_request: 39067
author:
type: changed
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlSingleStat } from '@gitlab/ui/dist/charts';
import SingleStatChart from '~/monitoring/components/charts/single_stat.vue'; import SingleStatChart from '~/monitoring/components/charts/single_stat.vue';
import { singleStatGraphData } from '../../graph_data'; import { singleStatGraphData } from '../../graph_data';
describe('Single Stat Chart component', () => { describe('Single Stat Chart component', () => {
let singleStatChart; let wrapper;
beforeEach(() => { const createComponent = (props = {}) => {
singleStatChart = shallowMount(SingleStatChart, { wrapper = shallowMount(SingleStatChart, {
propsData: { propsData: {
graphData: singleStatGraphData({}, { unit: 'MB' }), graphData: singleStatGraphData({}, { unit: 'MB' }),
...props,
}, },
}); });
};
const findChart = () => wrapper.find(GlSingleStat);
beforeEach(() => {
createComponent();
}); });
afterEach(() => { afterEach(() => {
singleStatChart.destroy(); wrapper.destroy();
}); });
describe('computed', () => { describe('computed', () => {
describe('statValue', () => { describe('statValue', () => {
it('should interpolate the value and unit props', () => { it('should interpolate the value and unit props', () => {
expect(singleStatChart.vm.statValue).toBe('1.00MB'); expect(findChart().props('value')).toBe('1.00MB');
}); });
it('should change the value representation to a percentile one', () => { it('should change the value representation to a percentile one', () => {
singleStatChart.setProps({ createComponent({
graphData: singleStatGraphData({ max_value: 120 }, { value: 91 }), graphData: singleStatGraphData({ max_value: 120 }, { value: 91 }),
}); });
expect(singleStatChart.vm.statValue).toContain('75.83%'); expect(findChart().props('value')).toContain('75.83%');
}); });
it('should display NaN for non numeric maxValue values', () => { it('should display NaN for non numeric maxValue values', () => {
singleStatChart.setProps({ createComponent({
graphData: singleStatGraphData({ max_value: 'not a number' }), graphData: singleStatGraphData({ max_value: 'not a number' }),
}); });
expect(singleStatChart.vm.statValue).toContain('NaN'); expect(findChart().props('value')).toContain('NaN');
}); });
it('should display NaN for missing query values', () => { it('should display NaN for missing query values', () => {
singleStatChart.setProps({ createComponent({
graphData: singleStatGraphData({ max_value: 120 }, { value: 'NaN' }), graphData: singleStatGraphData({ max_value: 120 }, { value: 'NaN' }),
}); });
expect(singleStatChart.vm.statValue).toContain('NaN'); expect(findChart().props('value')).toContain('NaN');
});
it('should not display `unit` when `unit` is undefined', () => {
createComponent({
graphData: singleStatGraphData({}, { unit: undefined }),
});
expect(findChart().props('value')).not.toContain('undefined');
}); });
describe('field attribute', () => { it('should not display `unit` when `unit` is null', () => {
createComponent({
graphData: singleStatGraphData({}, { unit: null }),
});
expect(findChart().props('value')).not.toContain('null');
});
describe('when a field attribute is set', () => {
it('displays a label value instead of metric value when field attribute is used', () => { it('displays a label value instead of metric value when field attribute is used', () => {
singleStatChart.setProps({ createComponent({
graphData: singleStatGraphData({ field: 'job' }, { isVector: true }), graphData: singleStatGraphData({ field: 'job' }, { isVector: true }),
}); });
return singleStatChart.vm.$nextTick(() => { expect(findChart().props('value')).toContain('prometheus');
expect(singleStatChart.vm.statValue).toContain('prometheus');
});
}); });
it('displays No data to display if field attribute is not present', () => { it('displays No data to display if field attribute is not present', () => {
singleStatChart.setProps({ createComponent({
graphData: singleStatGraphData({ field: 'this-does-not-exist' }), graphData: singleStatGraphData({ field: 'this-does-not-exist' }),
}); });
return singleStatChart.vm.$nextTick(() => { expect(findChart().props('value')).toContain('No data to display');
expect(singleStatChart.vm.statValue).toContain('No data to display');
});
}); });
}); });
}); });
......
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