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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
|
import {
GlEmptyState,
GlLoadingIcon,
GlFormInput,
GlPagination,
GlDropdown,
GlDropdownItem,
} from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import Vuex from 'vuex';
import stubChildren from 'helpers/stub_children';
import ErrorTrackingActions from '~/error_tracking/components/error_tracking_actions.vue';
import ErrorTrackingList from '~/error_tracking/components/error_tracking_list.vue';
import Tracking from '~/tracking';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import errorsList from './list_mock.json';
jest.mock('~/tracking');
Vue.use(Vuex);
describe('ErrorTrackingList', () => {
let store;
let wrapper;
let actions;
const findErrorListTable = () => wrapper.find('table');
const findErrorListRows = () => wrapper.findAll('tbody tr');
const dropdownsArray = () => wrapper.findAllComponents(GlDropdown);
const findRecentSearchesDropdown = () => dropdownsArray().at(0).findComponent(GlDropdown);
const findStatusFilterDropdown = () => dropdownsArray().at(1).findComponent(GlDropdown);
const findSortDropdown = () => dropdownsArray().at(2).findComponent(GlDropdown);
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const findPagination = () => wrapper.findComponent(GlPagination);
const findErrorActions = () => wrapper.findComponent(ErrorTrackingActions);
const findIntegratedDisabledAlert = () => wrapper.findByTestId('integrated-disabled-alert');
function mountComponent({
errorTrackingEnabled = true,
userCanEnableErrorTracking = true,
showIntegratedTrackingDisabledAlert = false,
integratedErrorTrackingEnabled = false,
stubs = {},
} = {}) {
wrapper = extendedWrapper(
mount(ErrorTrackingList, {
store,
propsData: {
indexPath: '/path',
listPath: '/error_tracking',
projectPath: 'project/test',
enableErrorTrackingLink: '/link',
userCanEnableErrorTracking,
errorTrackingEnabled,
integratedErrorTrackingEnabled,
showIntegratedTrackingDisabledAlert,
illustrationPath: 'illustration/path',
},
stubs: {
...stubChildren(ErrorTrackingList),
...stubs,
},
}),
);
}
beforeEach(() => {
actions = {
startPolling: jest.fn(),
restartPolling: jest.fn().mockName('restartPolling'),
addRecentSearch: jest.fn(),
loadRecentSearches: jest.fn(),
setIndexPath: jest.fn(),
clearRecentSearches: jest.fn(),
setEndpoint: jest.fn(),
searchByQuery: jest.fn(),
sortByField: jest.fn(),
fetchPaginatedResults: jest.fn(),
updateStatus: jest.fn(),
removeIgnoredResolvedErrors: jest.fn(),
filterByStatus: jest.fn(),
};
const state = {
indexPath: '',
recentSearches: [],
errors: errorsList,
loading: true,
pagination: {
previous: {
cursor: 'previousCursor',
},
next: {
cursor: 'nextCursor',
},
},
};
store = new Vuex.Store({
modules: {
list: {
namespaced: true,
actions,
state,
},
},
});
});
describe('loading', () => {
beforeEach(() => {
store.state.list.loading = true;
mountComponent();
});
it('shows spinner', () => {
expect(findLoadingIcon().exists()).toBe(true);
expect(findErrorListTable().exists()).toBe(false);
});
});
describe('results', () => {
beforeEach(() => {
store.state.list.loading = false;
store.state.list.errors = errorsList;
mountComponent({
stubs: {
GlTable: false,
GlLink: false,
},
});
});
it('shows table', () => {
expect(findLoadingIcon().exists()).toBe(false);
expect(findErrorListTable().exists()).toBe(true);
expect(findSortDropdown().exists()).toBe(true);
});
it('shows list of errors in a table', () => {
expect(findErrorListRows().length).toEqual(store.state.list.errors.length);
});
it('each error in a list should have a link to the error page', () => {
const errorTitle = wrapper.findAll('tbody tr a');
errorTitle.wrappers.forEach((_, index) => {
expect(errorTitle.at(index).attributes('href')).toEqual(
expect.stringMatching(/error_tracking\/\d+\/details$/),
);
});
});
it('each error in the list should have an action button set', () => {
findErrorListRows().wrappers.forEach((row) => {
expect(row.findComponent(ErrorTrackingActions).exists()).toBe(true);
});
});
describe('filtering', () => {
const findSearchBox = () => wrapper.findComponent(GlFormInput);
it('shows search box & sort dropdown', () => {
expect(findSearchBox().exists()).toBe(true);
expect(findSortDropdown().exists()).toBe(true);
});
it('searches by query', () => {
findSearchBox().vm.$emit('input', 'search');
findSearchBox().trigger('keyup.enter');
expect(actions.searchByQuery.mock.calls[0][1]).toBe('search');
});
it('sorts by fields', () => {
const findSortItem = () => findSortDropdown().findComponent(GlDropdownItem);
findSortItem().vm.$emit('click');
expect(actions.sortByField).toHaveBeenCalled();
});
it('filters by status', () => {
const findStatusFilter = () => findStatusFilterDropdown().findComponent(GlDropdownItem);
findStatusFilter().vm.$emit('click');
expect(actions.filterByStatus).toHaveBeenCalled();
});
});
});
describe('no results', () => {
const findRefreshLink = () => wrapper.find('.js-try-again');
beforeEach(() => {
store.state.list.loading = false;
store.state.list.errors = [];
mountComponent({
stubs: {
GlTable: false,
GlDropdown: false,
GlDropdownItem: false,
},
});
});
it('shows empty table', () => {
expect(findLoadingIcon().exists()).toBe(false);
expect(findErrorListRows().length).toEqual(1);
expect(findSortDropdown().exists()).toBe(true);
});
it('shows a message prompting to refresh', () => {
expect(findRefreshLink().text()).toContain('Check again');
});
it('restarts polling', () => {
findRefreshLink().vm.$emit('click');
expect(actions.restartPolling).toHaveBeenCalled();
});
});
describe('error tracking feature disabled', () => {
beforeEach(() => {
mountComponent({ errorTrackingEnabled: false });
});
it('shows empty state', () => {
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
expect(findLoadingIcon().exists()).toBe(false);
expect(findErrorListTable().exists()).toBe(false);
expect(dropdownsArray().length).toBe(0);
});
});
describe('When the integrated tracking diabled alert should be shown', () => {
beforeEach(() => {
mountComponent({
showIntegratedTrackingDisabledAlert: true,
stubs: {
GlAlert: false,
},
});
});
it('shows the alert box', () => {
expect(findIntegratedDisabledAlert().exists()).toBe(true);
});
describe('when alert is dismissed', () => {
it('hides the alert box', async () => {
await findIntegratedDisabledAlert().vm.$emit('dismiss');
expect(findIntegratedDisabledAlert().exists()).toBe(false);
});
});
});
describe('When the ignore button on an error is clicked', () => {
beforeEach(() => {
store.state.list.loading = false;
store.state.list.errors = errorsList;
mountComponent({
stubs: {
GlTable: false,
GlLink: false,
},
});
});
it('sends the "ignored" status and error ID', () => {
findErrorActions().vm.$emit('update-issue-status', {
errorId: errorsList[0].id,
status: 'ignored',
});
expect(actions.updateStatus).toHaveBeenCalledWith(expect.anything(), {
endpoint: `/project/test/-/error_tracking/${errorsList[0].id}.json`,
status: 'ignored',
});
});
it('calls an action to remove the item from the list', () => {
findErrorActions().vm.$emit('update-issue-status', { errorId: '1', status: undefined });
expect(actions.removeIgnoredResolvedErrors).toHaveBeenCalledWith(expect.anything(), '1');
});
});
describe('When the resolve button on an error is clicked', () => {
beforeEach(() => {
store.state.list.loading = false;
store.state.list.errors = errorsList;
mountComponent({
stubs: {
GlTable: false,
GlLink: false,
},
});
});
it('sends "resolved" status and error ID', () => {
findErrorActions().vm.$emit('update-issue-status', {
errorId: errorsList[0].id,
status: 'resolved',
});
expect(actions.updateStatus).toHaveBeenCalledWith(expect.anything(), {
endpoint: `/project/test/-/error_tracking/${errorsList[0].id}.json`,
status: 'resolved',
});
});
it('calls an action to remove the item from the list', () => {
findErrorActions().vm.$emit('update-issue-status', { errorId: '1', status: undefined });
expect(actions.removeIgnoredResolvedErrors).toHaveBeenCalledWith(expect.anything(), '1');
});
});
describe('when the resolve button is clicked with non numberic error id', () => {
beforeEach(() => {
store.state.list.loading = false;
store.state.list.errors = [
{
id: 'abc',
title: 'PG::ConnectionBad: FATAL',
type: 'error',
userCount: 0,
count: '53',
firstSeen: '2019-05-30T07:21:46Z',
lastSeen: '2019-11-06T03:21:39Z',
status: 'unresolved',
},
];
mountComponent({
stubs: {
GlTable: false,
GlLink: false,
},
});
});
it('should show about:blank link', () => {
findErrorActions().vm.$emit('update-issue-status', {
errorId: 'abc',
status: 'resolved',
});
expect(actions.updateStatus).toHaveBeenCalledWith(expect.anything(), {
endpoint: 'about:blank',
status: 'resolved',
});
});
});
describe('When error tracking is disabled and user is not allowed to enable it', () => {
beforeEach(() => {
mountComponent({
errorTrackingEnabled: false,
userCanEnableErrorTracking: false,
stubs: {
GlLink: false,
GlEmptyState: false,
},
});
});
it('shows empty state', () => {
const emptyStateComponent = wrapper.findComponent(GlEmptyState);
const emptyStatePrimaryDescription = emptyStateComponent.find('span', {
exactText: 'Monitor your errors directly in GitLab.',
});
const emptyStateLinks = emptyStateComponent.findAll('a');
expect(emptyStateComponent.isVisible()).toBe(true);
expect(emptyStatePrimaryDescription.exists()).toBe(true);
expect(emptyStateLinks.at(0).attributes('href')).toBe(
'/help/operations/error_tracking.html#integrated-error-tracking',
);
});
});
describe('recent searches', () => {
beforeEach(() => {
mountComponent({
stubs: {
GlDropdown: false,
GlDropdownItem: false,
},
});
});
it('shows empty message', () => {
store.state.list.recentSearches = [];
expect(findRecentSearchesDropdown().text()).toContain("You don't have any recent searches");
});
it('shows items', async () => {
store.state.list.recentSearches = ['great', 'search'];
await nextTick();
const dropdownItems = wrapper.findAll('.filtered-search-box li');
expect(dropdownItems.length).toBe(3);
expect(dropdownItems.at(0).text()).toBe('great');
expect(dropdownItems.at(1).text()).toBe('search');
});
describe('clear', () => {
const clearRecentButton = () => wrapper.findComponent({ ref: 'clearRecentSearches' });
it('is hidden when list empty', () => {
store.state.list.recentSearches = [];
expect(clearRecentButton().exists()).toBe(false);
});
it('is visible when list has items', async () => {
store.state.list.recentSearches = ['some', 'searches'];
await nextTick();
expect(clearRecentButton().exists()).toBe(true);
expect(clearRecentButton().text()).toBe('Clear recent searches');
});
it('clears items on click', async () => {
store.state.list.recentSearches = ['some', 'searches'];
await nextTick();
clearRecentButton().vm.$emit('click');
expect(actions.clearRecentSearches).toHaveBeenCalledTimes(1);
});
});
});
describe('When pagination is not required', () => {
beforeEach(() => {
store.state.list.loading = false;
store.state.list.pagination = {};
mountComponent();
});
it('should not render the pagination component', () => {
expect(findPagination().exists()).toBe(false);
});
});
describe('When pagination is required', () => {
describe('and previous cursor is not available', () => {
beforeEach(() => {
store.state.list.loading = false;
delete store.state.list.pagination.previous;
mountComponent();
});
it('disables Prev button in the pagination', () => {
expect(findPagination().props('prevPage')).toBe(null);
expect(findPagination().props('nextPage')).not.toBe(null);
});
});
describe('and next cursor is not available', () => {
beforeEach(() => {
store.state.list.loading = false;
delete store.state.list.pagination.next;
mountComponent();
});
it('disables Next button in the pagination', () => {
expect(findPagination().props('prevPage')).not.toBe(null);
expect(findPagination().props('nextPage')).toBe(null);
});
});
describe('and the user is not on the first page', () => {
describe('and the previous button is clicked', () => {
const currentPage = 2;
beforeEach(() => {
store.state.list.loading = false;
mountComponent({
stubs: {
GlTable: false,
GlPagination: false,
},
});
findPagination().vm.$emit('input', currentPage);
});
it('fetches the previous page of results', () => {
expect(wrapper.find('.prev-page-item').attributes('aria-disabled')).toBe(undefined);
findPagination().vm.$emit('input', currentPage - 1);
expect(actions.fetchPaginatedResults).toHaveBeenCalled();
expect(actions.fetchPaginatedResults).toHaveBeenLastCalledWith(
expect.anything(),
'previousCursor',
);
});
});
describe('and the next page button is clicked', () => {
beforeEach(() => {
store.state.list.loading = false;
mountComponent();
});
it('fetches the next page of results', () => {
window.scrollTo = jest.fn();
findPagination().vm.$emit('input', 2);
expect(window.scrollTo).toHaveBeenCalledWith(0, 0);
expect(actions.fetchPaginatedResults).toHaveBeenCalled();
expect(actions.fetchPaginatedResults).toHaveBeenLastCalledWith(
expect.anything(),
'nextCursor',
);
});
});
});
});
describe('Snowplow tracking', () => {
beforeEach(() => {
store.state.list.loading = false;
store.state.list.errors = errorsList;
});
describe.each([true, false])(`when integratedErrorTracking is %s`, (integrated) => {
const category = 'Error Tracking';
beforeEach(() => {
mountComponent({
stubs: {
GlTable: false,
GlLink: false,
},
integratedErrorTrackingEnabled: integrated,
});
});
it('should track list views', () => {
expect(Tracking.event).toHaveBeenCalledWith(category, 'view_errors_list', {
extra: {
variant: integrated ? 'integrated' : 'external',
},
});
});
it('should track status updates', async () => {
const status = 'ignored';
findErrorActions().vm.$emit('update-issue-status', {
errorId: 1,
status,
});
await nextTick();
expect(Tracking.event).toHaveBeenCalledWith(category, 'update_ignored_status', {
extra: {
variant: integrated ? 'integrated' : 'external',
},
});
});
it('should track error filter', () => {
const findStatusFilter = () => findStatusFilterDropdown().findComponent(GlDropdownItem);
findStatusFilter().vm.$emit('click');
expect(Tracking.event).toHaveBeenCalledWith(category, 'filter_unresolved_status', {
extra: {
variant: integrated ? 'integrated' : 'external',
},
});
});
it('should track error sorting', () => {
const findSortItem = () => findSortDropdown().findComponent(GlDropdownItem);
findSortItem().vm.$emit('click');
expect(Tracking.event).toHaveBeenCalledWith(category, 'sort_by_last_seen', {
extra: {
variant: integrated ? 'integrated' : 'external',
},
});
});
});
});
});
|