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

tracing_details_span_chart_spec.js « components « tracing « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0ca4288333b3f126a4f69082ee74613ed14e9877 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { GlButton } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import TracingDetailsSpansChart from '~/tracing/components/tracing_details_spans_chart.vue';

describe('TracingDetailsSpansChart', () => {
  const mockSpans = [
    {
      operation: 'operation-1',
      service: 'service-1',
      startTimeMs: 100,
      durationMs: 150,
      children: [
        {
          operation: 'operation-3',
          service: 'service-3',
          startTimeMs: 0,
          durationMs: 100,
          children: [],
        },
      ],
    },
    {
      operation: 'operation-2',
      service: 'service-2',
      startTimeMs: 100,
      durationMs: 200,
      children: [],
    },
  ];

  const mockProps = {
    spans: mockSpans,
    traceDurationMs: 300,
    serviceToColor: {
      'service-1': 'blue-500',
      'service-2': 'orange-500',
    },
  };

  let wrapper;

  const getSpan = (index, depth = 0) => wrapper.findByTestId(`span-container-${depth}-${index}`);
  const getSpanDetails = (index, depth = 0) =>
    getSpan(index, depth).find('[data-testid="span-details"]');

  const getToggleButton = (index, depth = 0) =>
    getSpanDetails(index, depth).findComponent(GlButton);

  const getSpanDuration = (index, depth = 0) =>
    getSpan(index, depth).find('[data-testid="span-duration"]');

  const getSpanDurationBar = (index, depth = 0) =>
    getSpanDuration(index, depth).find('[data-testid="span-duration-bar"]');

  beforeEach(() => {
    wrapper = shallowMountExtended(TracingDetailsSpansChart, {
      propsData: {
        ...mockProps,
      },
    });
  });

  it('renders the correct number of spans', () => {
    expect(wrapper.findAll('[data-testid^="span-container-"]')).toHaveLength(
      mockProps.spans.length,
    );
  });

  it('renders tracing-details-spans-chart only if span has children', () => {
    const childrenChart = getSpan(0).findComponent(TracingDetailsSpansChart);

    expect(childrenChart.exists()).toBe(true);
    expect(childrenChart.props('depth')).toBe(1);
    expect(childrenChart.props('traceDurationMs')).toBe(mockProps.traceDurationMs);
    expect(childrenChart.props('serviceToColor')).toBe(mockProps.serviceToColor);
    expect(childrenChart.props('spans')).toBe(mockProps.spans[0].children);

    // span with no children
    expect(getSpan(1).findComponent(TracingDetailsSpansChart).exists()).toBe(false);
  });

  it('toggle the children spans when clicking the expand button', async () => {
    await getToggleButton(0).vm.$emit('click');

    expect(getToggleButton(0).props('icon')).toBe('chevron-up');
    expect(getSpan(0).findComponent(TracingDetailsSpansChart).exists()).toBe(false);

    await getToggleButton(0).vm.$emit('click');

    expect(getToggleButton(0).props('icon')).toBe('chevron-down');
    expect(getSpan(0).findComponent(TracingDetailsSpansChart).exists()).toBe(true);
  });

  it('reset the expanded state when the spans change', async () => {
    await getToggleButton(0).vm.$emit('click');
    expect(getSpan(0).findComponent(TracingDetailsSpansChart).exists()).toBe(false);

    await wrapper.setProps({ spans: [...mockSpans] });
    expect(getSpan(0).findComponent(TracingDetailsSpansChart).exists()).toBe(true);
  });

  describe('span details', () => {
    it('renders the spans details with left padding based on depth', () => {
      wrapper = shallowMountExtended(TracingDetailsSpansChart, {
        propsData: {
          ...mockProps,
          depth: 2,
        },
      });
      expect(getSpanDetails(0, 2).element.style.paddingLeft).toBe('32px');
    });

    it('renders span operation and service name', () => {
      expect(getSpanDetails(0).text()).toBe('operation-1 service-1');
    });

    it('renders the expanded button', () => {
      expect(getToggleButton(0).props('icon')).toBe('chevron-down');
    });
  });

  describe('span duration', () => {
    it('renders the duration value', () => {
      expect(
        wrapper.findByTestId('span-container-0-0').find('[data-testid="span-duration"]').text(),
      ).toBe('150 ms');
    });

    it('renders the proper color based on service', () => {
      expect(
        wrapper
          .findByTestId('span-container-0-0')
          .find('[data-testid="span-duration-bar"]')
          .classes(),
      ).toContain('gl-bg-data-viz-blue-500');
    });

    it('renders the bar with the proper style', () => {
      expect(getSpanDuration(0).element.style.marginLeft).toBe('33%');
      expect(
        getSpanDurationBar(0).find('[data-testid="span-duration-bar"]').element.style.width,
      ).toBe('50%');
    });

    it('bar width should not be less than 0.5% and not bigger than 100%', () => {
      wrapper = shallowMountExtended(TracingDetailsSpansChart, {
        propsData: {
          serviceToColor: {
            'service-1': 'blue-500',
            'service-2': 'orange-500',
          },
          traceDurationMs: 300,
          spans: [
            {
              operation: 'operation-1',
              service: 'service-1',
              startTimeMs: 0,
              durationMs: 1,
              children: [],
            },
            {
              operation: 'operation-2',
              service: 'service-2',
              startTimeMs: 0,
              durationMs: 310,
              children: [],
            },
          ],
        },
      });
      expect(
        getSpanDurationBar(0).find('[data-testid="span-duration-bar"]').element.style.width,
      ).toBe('0.5%');
      expect(
        getSpanDurationBar(1).find('[data-testid="span-duration-bar"]').element.style.width,
      ).toBe('100%');
    });
  });
});