Welcome to mirror list, hosted at ThFree Co, Russian Federation.

single_stat_spec.js « charts « components « monitoring « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb0682d033885124710af768d762685318396473 (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
import { shallowMount } from '@vue/test-utils';
import SingleStatChart from '~/monitoring/components/charts/single_stat.vue';
import { graphDataPrometheusQuery } from '../../mock_data';

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

  beforeEach(() => {
    singleStatChart = shallowMount(SingleStatChart, {
      propsData: {
        graphData: graphDataPrometheusQuery,
      },
    });
  });

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

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

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

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

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

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

      it('should display NaN for missing query values', () => {
        singleStatChart.setProps({
          graphData: {
            ...graphDataPrometheusQuery,
            metrics: [
              {
                ...graphDataPrometheusQuery.metrics[0],
                result: [
                  {
                    ...graphDataPrometheusQuery.metrics[0].result[0],
                    value: [''],
                  },
                ],
              },
            ],
            maxValue: 120,
          },
        });

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