summaryrefslogtreecommitdiff
path: root/spec/javascripts/performance_bar/components/simple_metric_spec.js
blob: 98b843e9711db168eac0f962e856fb369d1522e3 (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
import Vue from 'vue';
import simpleMetric from '~/performance_bar/components/simple_metric.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

describe('simpleMetric', () => {
  let vm;

  afterEach(() => {
    vm.$destroy();
  });

  describe('when the current request has no details', () => {
    beforeEach(() => {
      vm = mountComponent(Vue.extend(simpleMetric), {
        currentRequest: {},
        metric: 'gitaly',
      });
    });

    it('does not display details', () => {
      expect(vm.$el.innerText).not.toContain('/');
    });

    it('displays the metric name', () => {
      expect(vm.$el.innerText).toContain('gitaly');
    });
  });

  describe('when the current request has details', () => {
    beforeEach(() => {
      vm = mountComponent(Vue.extend(simpleMetric), {
        currentRequest: {
          details: { gitaly: { duration: '123ms', calls: '456' } },
        },
        metric: 'gitaly',
      });
    });

    it('diplays details', () => {
      expect(vm.$el.innerText.replace(/\s+/g, ' ')).toContain('123ms / 456');
    });

    it('displays the metric name', () => {
      expect(vm.$el.innerText).toContain('gitaly');
    });
  });
});