summaryrefslogtreecommitdiff
path: root/spec/javascripts/performance_bar/components/detailed_metric_spec.js
blob: 8a7aa057186c09179546acf8b34284d76e9f6aed (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
74
75
76
77
78
79
80
81
82
83
84
85
86
import Vue from 'vue';
import detailedMetric from '~/performance_bar/components/detailed_metric.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

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

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

  describe('when the current request has no details', () => {
    beforeEach(() => {
      vm = mountComponent(Vue.extend(detailedMetric), {
        currentRequest: {},
        metric: 'gitaly',
        header: 'Gitaly calls',
        details: 'details',
        keys: ['feature', 'request'],
      });
    });

    it('does not render the element', () => {
      expect(vm.$el.innerHTML).toEqual(undefined);
    });
  });

  describe('when the current request has details', () => {
    const requestDetails = [
      { duration: '100', feature: 'find_commit', request: 'abcdef', backtrace: ['hello', 'world'] },
      { duration: '23', feature: 'rebase_in_progress', request: '', backtrace: ['world', 'hello'] },
    ];

    beforeEach(() => {
      vm = mountComponent(Vue.extend(detailedMetric), {
        currentRequest: {
          details: {
            gitaly: {
              duration: '123ms',
              calls: '456',
              details: requestDetails,
            },
          },
        },
        metric: 'gitaly',
        header: 'Gitaly calls',
        details: 'details',
        keys: ['feature', 'request'],
      });
    });

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

    it('adds a modal with a table of the details', () => {
      vm.$el
        .querySelectorAll('.performance-bar-modal td:nth-child(1)')
        .forEach((duration, index) => {
          expect(duration.innerText).toContain(requestDetails[index].duration);
        });

      vm.$el
        .querySelectorAll('.performance-bar-modal td:nth-child(2)')
        .forEach((feature, index) => {
          expect(feature.innerText).toContain(requestDetails[index].feature);
        });

      vm.$el
        .querySelectorAll('.performance-bar-modal td:nth-child(2)')
        .forEach((request, index) => {
          expect(request.innerText).toContain(requestDetails[index].request);
        });

      expect(vm.$el.querySelector('.text-expander.js-toggle-button')).not.toBeNull();

      vm.$el.querySelectorAll('.performance-bar-modal td:nth-child(2)').forEach(request => {
        expect(request.innerText).toContain('world');
      });
    });

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