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
|
import { GlSearchBoxByClick } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import JobLogControllers from '~/ci/job_details/components/job_log_controllers.vue';
import HelpPopover from '~/vue_shared/components/help_popover.vue';
import { backoffMockImplementation } from 'helpers/backoff_helper';
import * as commonUtils from '~/lib/utils/common_utils';
import { mockJobLog } from 'jest/ci/jobs_mock_data';
const mockToastShow = jest.fn();
describe('Job log controllers', () => {
let wrapper;
beforeEach(() => {
jest.spyOn(commonUtils, 'backOff').mockImplementation(backoffMockImplementation);
});
afterEach(() => {
commonUtils.backOff.mockReset();
});
const defaultProps = {
rawPath: '/raw',
size: 511952,
isScrollTopDisabled: false,
isScrollBottomDisabled: false,
isScrollingDown: true,
isJobLogSizeVisible: true,
isComplete: true,
jobLog: mockJobLog,
};
const createWrapper = (props) => {
wrapper = mount(JobLogControllers, {
propsData: {
...defaultProps,
...props,
},
data() {
return {
searchTerm: '82',
};
},
mocks: {
$toast: {
show: mockToastShow,
},
},
});
};
const findTruncatedInfo = () => wrapper.find('[data-testid="log-truncated-info"]');
const findRawLink = () => wrapper.find('[data-testid="raw-link"]');
const findRawLinkController = () => wrapper.find('[data-testid="job-raw-link-controller"]');
const findScrollTop = () => wrapper.find('[data-testid="job-controller-scroll-top"]');
const findScrollBottom = () => wrapper.find('[data-testid="job-controller-scroll-bottom"]');
const findJobLogSearch = () => wrapper.findComponent(GlSearchBoxByClick);
const findSearchHelp = () => wrapper.findComponent(HelpPopover);
const findScrollFailure = () => wrapper.find('[data-testid="job-controller-scroll-to-failure"]');
describe('Truncate information', () => {
describe('with isJobLogSizeVisible', () => {
beforeEach(() => {
createWrapper();
});
it('renders size information', () => {
expect(findTruncatedInfo().text()).toMatch('499.95 KiB');
});
it('renders link to raw job log', () => {
expect(findRawLink().attributes('href')).toBe(defaultProps.rawPath);
});
});
});
describe('links section', () => {
describe('with raw job log path', () => {
beforeEach(() => {
createWrapper();
});
it('renders raw job log link', () => {
expect(findRawLinkController().attributes('href')).toBe(defaultProps.rawPath);
});
});
describe('without raw job log path', () => {
beforeEach(() => {
createWrapper({
rawPath: null,
});
});
it('does not render raw job log link', () => {
expect(findRawLinkController().exists()).toBe(false);
});
});
});
describe('scroll buttons', () => {
describe('scroll top button', () => {
describe('when user can scroll top', () => {
beforeEach(() => {
createWrapper({
isScrollTopDisabled: false,
});
});
it('emits scrollJobLogTop event on click', async () => {
await findScrollTop().trigger('click');
expect(wrapper.emitted().scrollJobLogTop).toHaveLength(1);
});
});
describe('when user can not scroll top', () => {
beforeEach(() => {
createWrapper({
isScrollTopDisabled: true,
isScrollBottomDisabled: false,
isScrollingDown: false,
});
});
it('renders disabled scroll top button', () => {
expect(findScrollTop().attributes('disabled')).toBeDefined();
});
it('does not emit scrollJobLogTop event on click', async () => {
await findScrollTop().trigger('click');
expect(wrapper.emitted().scrollJobLogTop).toBeUndefined();
});
});
});
describe('scroll bottom button', () => {
describe('when user can scroll bottom', () => {
beforeEach(() => {
createWrapper();
});
it('emits scrollJobLogBottom event on click', async () => {
await findScrollBottom().trigger('click');
expect(wrapper.emitted().scrollJobLogBottom).toHaveLength(1);
});
});
describe('when user can not scroll bottom', () => {
beforeEach(() => {
createWrapper({
isScrollTopDisabled: false,
isScrollBottomDisabled: true,
isScrollingDown: false,
});
});
it('renders disabled scroll bottom button', () => {
expect(findScrollBottom().attributes('disabled')).toEqual('disabled');
});
it('does not emit scrollJobLogBottom event on click', async () => {
await findScrollBottom().trigger('click');
expect(wrapper.emitted().scrollJobLogBottom).toBeUndefined();
});
});
describe('while isScrollingDown is true', () => {
beforeEach(() => {
createWrapper();
});
it('renders animate class for the scroll down button', () => {
expect(findScrollBottom().classes()).toContain('animate');
});
});
describe('while isScrollingDown is false', () => {
beforeEach(() => {
createWrapper({
isScrollTopDisabled: true,
isScrollBottomDisabled: false,
isScrollingDown: false,
});
});
it('does not render animate class for the scroll down button', () => {
expect(findScrollBottom().classes()).not.toContain('animate');
});
});
});
describe('scroll to failure button', () => {
describe('with red text failures on the page', () => {
let firstFailure;
let secondFailure;
beforeEach(() => {
jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce(['mock-element']);
createWrapper();
firstFailure = document.createElement('div');
firstFailure.className = 'term-fg-l-red';
document.body.appendChild(firstFailure);
secondFailure = document.createElement('div');
secondFailure.className = 'term-fg-l-red';
document.body.appendChild(secondFailure);
});
afterEach(() => {
if (firstFailure) {
firstFailure.remove();
firstFailure = null;
}
if (secondFailure) {
secondFailure.remove();
secondFailure = null;
}
});
it('is enabled', () => {
expect(findScrollFailure().props('disabled')).toBe(false);
});
it('scrolls to each failure', async () => {
jest.spyOn(firstFailure, 'scrollIntoView');
await findScrollFailure().trigger('click');
expect(firstFailure.scrollIntoView).toHaveBeenCalled();
await findScrollFailure().trigger('click');
expect(secondFailure.scrollIntoView).toHaveBeenCalled();
await findScrollFailure().trigger('click');
expect(firstFailure.scrollIntoView).toHaveBeenCalled();
});
});
describe('with no red text failures on the page', () => {
beforeEach(() => {
jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce([]);
createWrapper();
});
it('is disabled', () => {
expect(findScrollFailure().props('disabled')).toBe(true);
});
});
describe('when the job log is not complete', () => {
beforeEach(() => {
jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce(['mock-element']);
createWrapper();
});
it('is enabled', () => {
expect(findScrollFailure().props('disabled')).toBe(false);
});
});
describe('on error', () => {
beforeEach(() => {
jest.spyOn(commonUtils, 'backOff').mockRejectedValueOnce();
createWrapper();
});
it('stays disabled', () => {
expect(findScrollFailure().props('disabled')).toBe(true);
});
});
});
});
describe('Job log search', () => {
beforeEach(() => {
createWrapper();
});
it('displays job log search', () => {
expect(findJobLogSearch().exists()).toBe(true);
expect(findSearchHelp().exists()).toBe(true);
});
it('emits search results', () => {
findJobLogSearch().vm.$emit('submit');
expect(wrapper.emitted('searchResults')).toHaveLength(1);
});
it('clears search results', () => {
findJobLogSearch().vm.$emit('clear');
expect(wrapper.emitted('searchResults')).toEqual([[[]]]);
});
});
});
|