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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { trimText } from 'helpers/text_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import DetailedMetric from '~/performance_bar/components/detailed_metric.vue';
import RequestWarning from '~/performance_bar/components/request_warning.vue';
import { sortOrders, sortOrderOptions } from '~/performance_bar/constants';
describe('detailedMetric', () => {
let wrapper;
const defaultProps = {
currentRequest: {},
metric: 'gitaly',
header: 'Gitaly calls',
keys: ['feature', 'request'],
};
const createComponent = (props = {}) => {
wrapper = extendedWrapper(
shallowMount(DetailedMetric, {
propsData: { ...defaultProps, ...props },
}),
);
};
const findAllTraceBlocks = () => wrapper.findAll('pre');
const findTraceBlockAtIndex = (index) => findAllTraceBlocks().at(index);
const findExpandBacktraceBtns = () => wrapper.findAllByTestId('backtrace-expand-btn');
const findExpandedBacktraceBtnAtIndex = (index) => findExpandBacktraceBtns().at(index);
const findDetailsLabel = () => wrapper.findByTestId('performance-bar-details-label');
const findSortOrderDropdown = () => wrapper.findByTestId('performance-bar-sort-order');
const selectSortOrder = (sortOrder) =>
findSortOrderDropdown().vm.$emit('select', sortOrderOptions[sortOrder].value);
const findEmptyDetailNotice = () => wrapper.findByTestId('performance-bar-empty-detail-notice');
const findAllDetailDurations = () =>
wrapper.findAllByTestId('performance-item-duration').wrappers.map((w) => w.text());
const findAllSummaryItems = () =>
wrapper.findAllByTestId('performance-bar-summary-item').wrappers.map((w) => w.text());
afterEach(() => {
wrapper.destroy();
});
describe('when the current request has no details', () => {
beforeEach(() => {
createComponent();
});
it('does not render the element', () => {
expect(wrapper.html()).toBe('');
});
});
describe('when the current request has details', () => {
const requestDetails = [
{
duration: 23,
feature: 'rebase_in_progress',
request: '',
backtrace: ['other', 'example'],
},
{ duration: 100, feature: 'find_commit', request: 'abcdef', backtrace: ['hello', 'world'] },
];
describe('with an empty detail', () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
duration: '0ms',
calls: 0,
details: [],
warnings: [],
},
},
},
});
});
it('displays an empty title', () => {
expect(findDetailsLabel().text()).toBe('0');
});
it('displays an empty modal', () => {
expect(findEmptyDetailNotice().text()).toContain('No gitaly calls for this request');
});
it('does not display sort by switcher', () => {
expect(findSortOrderDropdown().exists()).toBe(false);
});
});
describe('when the details have a summary field', () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
duration: '123ms',
calls: 456,
details: requestDetails,
warnings: ['gitaly calls: 456 over 30'],
summary: {
'In controllers': 100,
'In middlewares': 20,
},
},
},
},
});
});
it('displays a summary section', () => {
expect(findAllSummaryItems()).toEqual([
'Total 456',
'Total duration 123ms',
'In controllers 100',
'In middlewares 20',
]);
});
});
describe('when the details have summaryOptions option', () => {
const gitalyDetails = {
duration: '123ms',
calls: 456,
details: requestDetails,
warnings: ['gitaly calls: 456 over 30'],
};
describe('when the details have summaryOptions > hideTotal option', () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: { ...gitalyDetails, summaryOptions: { hideTotal: true } },
},
},
});
});
it('displays a summary section', () => {
expect(findAllSummaryItems()).toEqual(['Total duration 123ms']);
});
});
describe('when the details have summaryOptions > hideDuration option', () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: { ...gitalyDetails, summaryOptions: { hideDuration: true } },
},
},
});
});
it('displays a summary section', () => {
expect(findAllSummaryItems()).toEqual(['Total 456']);
});
});
describe('when the details have both summary and summaryOptions field', () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
...gitalyDetails,
summary: {
'In controllers': 100,
'In middlewares': 20,
},
summaryOptions: {
hideDuration: true,
hideTotal: true,
},
},
},
},
});
});
it('displays a summary section', () => {
expect(findAllSummaryItems()).toEqual(['In controllers 100', 'In middlewares 20']);
});
});
});
describe("when the details don't have a start field", () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
duration: '123ms',
calls: 456,
details: requestDetails,
warnings: ['gitaly calls: 456 over 30'],
},
},
},
});
});
it('displays details header', () => {
expect(findDetailsLabel().text()).toBe('123ms / 456');
});
it('displays a basic summary section', () => {
expect(findAllSummaryItems()).toEqual(['Total 456', 'Total duration 123ms']);
});
it('sorts the details by descending duration order', () => {
expect(findAllDetailDurations()).toEqual(['100ms', '23ms']);
});
it('does not display sort by switcher', () => {
expect(findSortOrderDropdown().exists()).toBe(false);
});
it('adds a modal with a table of the details', () => {
wrapper
.findAll('.performance-bar-modal td:nth-child(1)')
.wrappers.forEach((duration, index) => {
expect(duration.text()).toContain(requestDetails[index].duration);
});
wrapper
.findAll('.performance-bar-modal td:nth-child(2)')
.wrappers.forEach((feature, index) => {
expect(feature.text()).toContain(requestDetails[index].feature);
});
wrapper
.findAll('.performance-bar-modal td:nth-child(2)')
.wrappers.forEach((request, index) => {
expect(request.text()).toContain(requestDetails[index].request);
});
expect(wrapper.find('.js-toggle-button')).not.toBeNull();
wrapper.findAll('.performance-bar-modal td:nth-child(2)').wrappers.forEach((request) => {
expect(request.text()).toContain('world');
});
});
it('displays the metric title', () => {
expect(wrapper.text()).toContain('gitaly');
});
it('displays request warnings', () => {
expect(wrapper.findComponent(RequestWarning).exists()).toBe(true);
});
it('can open and close traces', async () => {
expect(findAllTraceBlocks()).toHaveLength(0);
// Each block click on a new trace and assert that the correct
// count is open and that the content is what we expect to ensure
// we opened or closed the right one
const secondExpandButton = findExpandedBacktraceBtnAtIndex(1);
findExpandedBacktraceBtnAtIndex(0).vm.$emit('click');
await nextTick();
expect(findAllTraceBlocks()).toHaveLength(1);
expect(findTraceBlockAtIndex(0).text()).toContain(requestDetails[1].backtrace[0]);
secondExpandButton.vm.$emit('click');
await nextTick();
expect(findAllTraceBlocks()).toHaveLength(2);
expect(findTraceBlockAtIndex(1).text()).toContain(requestDetails[0].backtrace[0]);
secondExpandButton.vm.$emit('click');
await nextTick();
expect(findAllTraceBlocks()).toHaveLength(1);
expect(findTraceBlockAtIndex(0).text()).toContain(requestDetails[1].backtrace[0]);
});
});
describe('when the details have a start field', () => {
const requestDetailsWithStart = [
{
start: '2021-03-18 11:41:49.846356 +0700',
duration: 23,
feature: 'rebase_in_progress',
request: '',
},
{
start: '2021-03-18 11:42:11.645711 +0700',
duration: 75,
feature: 'find_commit',
request: 'abcdef',
},
{
start: '2021-03-18 11:42:10.645711 +0700',
duration: 100,
feature: 'find_commit',
request: 'abcdef',
},
];
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
duration: '123ms',
calls: 456,
details: requestDetailsWithStart,
warnings: ['gitaly calls: 456 over 30'],
},
},
},
metric: 'gitaly',
header: 'Gitaly calls',
keys: ['feature', 'request'],
});
});
it('sorts the details by descending duration order', () => {
expect(findAllDetailDurations()).toEqual(['100ms', '75ms', '23ms']);
});
it('displays sort by switcher', () => {
expect(findSortOrderDropdown().exists()).toBe(true);
});
it('changes sortOrder on select', async () => {
selectSortOrder(sortOrders.CHRONOLOGICAL);
await nextTick();
expect(findAllDetailDurations()).toEqual(['23ms', '100ms', '75ms']);
selectSortOrder(sortOrders.DURATION);
await nextTick();
expect(findAllDetailDurations()).toEqual(['100ms', '75ms', '23ms']);
});
});
describe('when using a custom metric title', () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
duration: '123ms',
calls: '456',
details: requestDetails,
},
},
},
title: 'custom',
});
});
it('displays the custom title', () => {
expect(wrapper.text()).toContain('custom');
});
});
describe('when the details has no duration', () => {
beforeEach(() => {
createComponent({
currentRequest: {
details: {
bullet: {
calls: '456',
details: [{ notification: 'notification', backtrace: 'backtrace' }],
},
},
},
metric: 'bullet',
header: 'Bullet notifications',
keys: ['notification'],
});
});
it('displays calls in the label', () => {
expect(findDetailsLabel().text()).toBe('456');
});
it('displays a basic summary section', () => {
expect(findAllSummaryItems()).toEqual(['Total 456']);
});
it('renders only the number of calls', async () => {
expect(trimText(wrapper.text())).toContain('notification bullet');
findExpandedBacktraceBtnAtIndex(0).vm.$emit('click');
await nextTick();
expect(trimText(wrapper.text())).toContain('notification backtrace bullet');
});
});
});
});
|