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
|
import MockAdapter from 'axios-mock-adapter';
import Vue, { nextTick } from 'vue';
import { GlModal, GlToast } from '@gitlab/ui';
import JobItem from '~/ci/pipeline_details/graph/components/job_item.vue';
import axios from '~/lib/utils/axios_utils';
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import ActionComponent from '~/ci/common/private/job_action_component.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
import {
delayedJob,
mockJob,
mockJobWithoutDetails,
mockJobWithUnauthorizedAction,
mockFailedJob,
triggerJob,
triggerJobWithRetryAction,
} from '../mock_data';
describe('pipeline graph job item', () => {
useLocalStorageSpy();
Vue.use(GlToast);
let wrapper;
let mockAxios;
const findJobWithoutLink = () => wrapper.findByTestId('job-without-link');
const findJobWithLink = () => wrapper.findByTestId('job-with-link');
const findActionVueComponent = () => wrapper.findComponent(ActionComponent);
const findActionComponent = () => wrapper.findByTestId('ci-action-button');
const findBadge = () => wrapper.findByTestId('job-bridge-badge');
const findJobLink = () => wrapper.findByTestId('job-with-link');
const findJobCiIcon = () => wrapper.findComponent(CiIcon);
const findModal = () => wrapper.findComponent(GlModal);
const clickOnModalPrimaryBtn = () => findModal().vm.$emit('primary');
const clickOnModalCancelBtn = () => findModal().vm.$emit('hide');
const clickOnModalCloseBtn = () => findModal().vm.$emit('close');
const myCustomClass1 = 'my-class-1';
const myCustomClass2 = 'my-class-2';
const defaultProps = {
job: mockJob,
};
const createWrapper = ({ props, data, mountFn = mountExtended, mocks = {} } = {}) => {
wrapper = mountFn(JobItem, {
data() {
return {
...data,
};
},
propsData: {
...defaultProps,
...props,
},
mocks: {
...mocks,
},
stubs: {
CiIcon,
},
});
};
const triggerActiveClass = 'gl-shadow-x0-y0-b3-s1-blue-500';
beforeEach(() => {
mockAxios = new MockAdapter(axios);
});
afterEach(() => {
mockAxios.restore();
});
describe('name with link', () => {
it('should render the job name and status with a link', async () => {
createWrapper();
await nextTick();
const link = findJobLink();
expect(link.attributes('href')).toBe(mockJob.status.detailsPath);
expect(link.attributes('title')).toBe(`${mockJob.name} - ${mockJob.status.label}`);
expect(findJobCiIcon().exists()).toBe(true);
expect(findJobCiIcon().find('.ci-status-icon-success').exists()).toBe(true);
expect(wrapper.text()).toBe(mockJob.name);
});
});
describe('name without link', () => {
beforeEach(() => {
createWrapper({
props: {
job: mockJobWithoutDetails,
cssClassJobName: 'css-class-job-name',
jobHovered: 'test',
},
});
});
it('should render status and name', () => {
expect(findJobCiIcon().exists()).toBe(true);
expect(findJobCiIcon().find('.ci-status-icon-success').exists()).toBe(true);
expect(findJobLink().exists()).toBe(false);
expect(wrapper.text()).toBe(mockJobWithoutDetails.name);
});
it('should apply hover class and provided class name', () => {
expect(findJobWithoutLink().classes()).toContain('css-class-job-name');
});
});
describe('CiIcon', () => {
it('should not render a link', () => {
createWrapper();
expect(findJobCiIcon().exists()).toBe(true);
expect(findJobCiIcon().props('useLink')).toBe(false);
});
});
describe('action icon', () => {
it('should render the action icon', () => {
createWrapper();
const actionComponent = findActionComponent();
expect(actionComponent.exists()).toBe(true);
expect(actionComponent.props('actionIcon')).toBe('retry');
expect(actionComponent.attributes('disabled')).toBeUndefined();
});
it('should render disabled action icon when user cannot run the action', () => {
createWrapper({
props: {
job: mockJobWithUnauthorizedAction,
},
});
const actionComponent = findActionComponent();
expect(actionComponent.exists()).toBe(true);
expect(actionComponent.props('actionIcon')).toBe('stop');
expect(actionComponent.attributes('disabled')).toBeDefined();
});
it('action icon tooltip text when job has passed but can be ran again', () => {
createWrapper({ props: { job: mockJob } });
expect(findActionComponent().props('tooltipText')).toBe('Run again');
});
it('action icon tooltip text when job has failed and can be retried', () => {
createWrapper({ props: { job: mockFailedJob } });
expect(findActionComponent().props('tooltipText')).toBe('Retry');
});
});
describe('job style', () => {
beforeEach(() => {
createWrapper({
props: {
job: mockJob,
cssClassJobName: 'css-class-job-name',
},
});
});
it('should render provided class name', () => {
expect(findJobLink().classes()).toContain('css-class-job-name');
});
it('does not show a badge on the job item', () => {
expect(findBadge().exists()).toBe(false);
});
it('does not apply the trigger job class', () => {
expect(findJobWithLink().classes()).not.toContain('gl-rounded-lg');
});
});
describe('status label', () => {
it('should not render status label when it is not provided', () => {
createWrapper({
props: {
job: {
id: 4258,
name: 'test',
status: {
icon: 'status_success',
},
},
},
});
expect(findJobWithoutLink().attributes('title')).toBe('test');
});
it('should not render status label when it is provided', () => {
createWrapper({
props: {
job: {
id: 4259,
name: 'test',
status: {
icon: 'status_success',
label: 'success',
tooltip: 'success',
},
},
},
});
expect(findJobWithoutLink().attributes('title')).toBe('test - success');
});
});
describe('for delayed job', () => {
it('displays remaining time in tooltip', () => {
createWrapper({
props: {
job: delayedJob,
},
});
expect(findJobWithLink().attributes('title')).toBe(
`delayed job - delayed manual action (00:00:00)`,
);
});
});
describe('trigger job', () => {
describe('card', () => {
beforeEach(() => {
createWrapper({
props: {
job: triggerJob,
},
});
});
it('shows a badge on the job item', () => {
expect(findBadge().exists()).toBe(true);
expect(findBadge().text()).toBe('Trigger job');
});
it('applies a rounded corner style instead of the usual pill shape', () => {
expect(findJobWithoutLink().classes()).toContain('gl-rounded-lg');
});
});
describe('when retrying', () => {
const mockToastShow = jest.fn();
beforeEach(async () => {
createWrapper({
mountFn: shallowMountExtended,
props: {
skipRetryModal: true,
job: triggerJobWithRetryAction,
},
mocks: {
$toast: {
show: mockToastShow,
},
},
});
await findActionVueComponent().vm.$emit('pipelineActionRequestComplete');
await nextTick();
});
it('shows a toast message that the downstream is being created', () => {
expect(mockToastShow).toHaveBeenCalledTimes(1);
});
});
describe('highlighting', () => {
it.each`
job | jobName | expanded | link
${mockJob} | ${mockJob.name} | ${true} | ${true}
${mockJobWithoutDetails} | ${mockJobWithoutDetails.name} | ${true} | ${false}
`(
`trigger job should stay highlighted when downstream is expanded`,
({ job, jobName, expanded, link }) => {
createWrapper({
props: {
job,
pipelineExpanded: { jobName, expanded },
},
});
const findJobEl = link ? findJobWithLink : findJobWithoutLink;
expect(findJobEl().classes()).toContain(triggerActiveClass);
},
);
it.each`
job | jobName | expanded | link
${mockJob} | ${mockJob.name} | ${false} | ${true}
${mockJobWithoutDetails} | ${mockJobWithoutDetails.name} | ${false} | ${false}
`(
`trigger job should not be highlighted when downstream is not expanded`,
({ job, jobName, expanded, link }) => {
createWrapper({
props: {
job,
pipelineExpanded: { jobName, expanded },
},
});
const findJobEl = link ? findJobWithLink : findJobWithoutLink;
expect(findJobEl().classes()).not.toContain(triggerActiveClass);
},
);
});
});
describe('job classes', () => {
it('job class is shown', () => {
createWrapper({
props: {
job: mockJob,
cssClassJobName: 'my-class',
},
});
const jobLinkEl = findJobLink();
expect(jobLinkEl.classes()).toContain('my-class');
expect(jobLinkEl.classes()).not.toContain(triggerActiveClass);
});
it('job class is shown, along with hover', () => {
createWrapper({
props: {
job: mockJob,
cssClassJobName: 'my-class',
sourceJobHovered: mockJob.name,
},
});
const jobLinkEl = findJobLink();
expect(jobLinkEl.classes()).toContain('my-class');
expect(jobLinkEl.classes()).toContain(triggerActiveClass);
});
it('multiple job classes are shown', () => {
createWrapper({
props: {
job: mockJob,
cssClassJobName: [myCustomClass1, myCustomClass2],
},
});
const jobLinkEl = findJobLink();
expect(jobLinkEl.classes()).toContain(myCustomClass1);
expect(jobLinkEl.classes()).toContain(myCustomClass2);
expect(jobLinkEl.classes()).not.toContain(triggerActiveClass);
});
it('multiple job classes are shown conditionally', () => {
createWrapper({
props: {
job: mockJob,
cssClassJobName: { [myCustomClass1]: true, [myCustomClass2]: true },
},
});
const jobLinkEl = findJobLink();
expect(jobLinkEl.classes()).toContain(myCustomClass1);
expect(jobLinkEl.classes()).toContain(myCustomClass2);
expect(jobLinkEl.classes()).not.toContain(triggerActiveClass);
});
it('multiple job classes are shown, along with a hover', () => {
createWrapper({
props: {
job: mockJob,
cssClassJobName: [myCustomClass1, myCustomClass2],
sourceJobHovered: mockJob.name,
},
});
const jobLinkEl = findJobLink();
expect(jobLinkEl.classes()).toContain(myCustomClass1);
expect(jobLinkEl.classes()).toContain(myCustomClass2);
expect(jobLinkEl.classes()).toContain(triggerActiveClass);
});
});
describe('confirmation modal', () => {
describe('when clicking on the action component', () => {
it.each`
skipRetryModal | exists | visibilityText
${false} | ${true} | ${'shows'}
${true} | ${false} | ${'hides'}
`(
'$visibilityText the modal when `skipRetryModal` is $skipRetryModal',
async ({ exists, skipRetryModal }) => {
createWrapper({
props: {
skipRetryModal,
job: triggerJobWithRetryAction,
},
});
await findActionComponent().trigger('click');
expect(findModal().exists()).toBe(exists);
},
);
});
describe('when showing the modal', () => {
it.each`
buttonName | shouldTriggerActionClick | actionBtn
${'primary'} | ${true} | ${clickOnModalPrimaryBtn}
${'cancel'} | ${false} | ${clickOnModalCancelBtn}
${'close'} | ${false} | ${clickOnModalCloseBtn}
`(
'clicking on $buttonName will pass down shouldTriggerActionClick as $shouldTriggerActionClick to the action component',
async ({ shouldTriggerActionClick, actionBtn }) => {
createWrapper({
props: {
skipRetryModal: false,
job: triggerJobWithRetryAction,
},
});
await findActionComponent().trigger('click');
await actionBtn();
expect(findActionComponent().props().shouldTriggerClick).toBe(shouldTriggerActionClick);
},
);
});
describe('when not checking the "do not show this again" checkbox', () => {
it.each`
actionName | actionBtn
${'closing'} | ${clickOnModalCloseBtn}
${'cancelling'} | ${clickOnModalCancelBtn}
${'confirming'} | ${clickOnModalPrimaryBtn}
`(
'does not emit any event and will not modify localstorage on $actionName',
async ({ actionBtn }) => {
createWrapper({
props: {
skipRetryModal: false,
job: triggerJobWithRetryAction,
},
});
await findActionComponent().trigger('click');
await actionBtn();
expect(wrapper.emitted().setSkipRetryModal).toBeUndefined();
expect(localStorage.setItem).not.toHaveBeenCalled();
},
);
});
describe('when checking the "do not show this again" checkbox', () => {
it.each`
actionName | actionBtn
${'closing'} | ${clickOnModalCloseBtn}
${'cancelling'} | ${clickOnModalCancelBtn}
${'confirming'} | ${clickOnModalPrimaryBtn}
`(
'emits "setSkipRetryModal" and set local storage key on $actionName the modal',
async ({ actionBtn }) => {
// We are passing the checkbox as a slot to the GlModal.
// The way GlModal is mounted, we can neither click on the box
// or emit an event directly. We therefore set the data property
// as it would be if the box was checked.
createWrapper({
data: {
currentSkipModalValue: true,
},
props: {
skipRetryModal: false,
job: triggerJobWithRetryAction,
},
});
await findActionComponent().trigger('click');
await actionBtn();
expect(wrapper.emitted().setSkipRetryModal).toHaveLength(1);
expect(localStorage.setItem).toHaveBeenCalledWith('skip_retry_modal', 'true');
},
);
});
});
});
|