summaryrefslogtreecommitdiff
path: root/spec/frontend/monitoring/components/charts/single_stat_spec.js
blob: 3783b1eebd2b3ca9642bcfd5be3da9996cce1978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { shallowMount } from '@vue/test-utils';
import SingleStatChart from '~/monitoring/components/charts/single_stat.vue';
import { singleStatGraphData } from '../../graph_data';

describe('Single Stat Chart component', () => {
  let singleStatChart;

  beforeEach(() => {
    singleStatChart = shallowMount(SingleStatChart, {
      propsData: {
        graphData: singleStatGraphData({}, { unit: 'MB' }),
      },
    });
  });

  afterEach(() => {
    singleStatChart.destroy();
  });

  describe('computed', () => {
    describe('statValue', () => {
      it('should interpolate the value and unit props', () => {
        expect(singleStatChart.vm.statValue).toBe('1.00MB');
      });

      it('should change the value representation to a percentile one', () => {
        singleStatChart.setProps({
          graphData: singleStatGraphData({ max_value: 120 }, { value: 91 }),
        });

        expect(singleStatChart.vm.statValue).toContain('75.83%');
      });

      it('should display NaN for non numeric maxValue values', () => {
        singleStatChart.setProps({
          graphData: singleStatGraphData({ max_value: 'not a number' }),
        });

        expect(singleStatChart.vm.statValue).toContain('NaN');
      });

      it('should display NaN for missing query values', () => {
        singleStatChart.setProps({
          graphData: singleStatGraphData({ max_value: 120 }, { value: 'NaN' }),
        });

        expect(singleStatChart.vm.statValue).toContain('NaN');
      });

      describe('field attribute', () => {
        it('displays a label value instead of metric value when field attribute is used', () => {
          singleStatChart.setProps({
            graphData: singleStatGraphData({ field: 'job' }, { isVector: true }),
          });

          return singleStatChart.vm.$nextTick(() => {
            expect(singleStatChart.vm.statValue).toContain('prometheus');
          });
        });

        it('displays No data to display if field attribute is not present', () => {
          singleStatChart.setProps({
            graphData: singleStatGraphData({ field: 'this-does-not-exist' }),
          });

          return singleStatChart.vm.$nextTick(() => {
            expect(singleStatChart.vm.statValue).toContain('No data to display');
          });
        });
      });
    });
  });
});