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
|
import * as types from '~/ci/job_details/store/mutation_types';
import mutations from '~/ci/job_details/store/mutations';
import state from '~/ci/job_details/store/state';
describe('Jobs Store Mutations', () => {
let stateCopy;
const html =
'I, [2018-08-17T22:57:45.707325 #1841] INFO -- : Writing /builds/ab89e95b0fa0b9272ea0c797b76908f24d36992630e9325273a4ce3.png<br>I';
beforeEach(() => {
stateCopy = state();
});
describe('SET_JOB_LOG_OPTIONS', () => {
it('should set jobEndpoint', () => {
mutations[types.SET_JOB_LOG_OPTIONS](stateCopy, {
endpoint: '/group1/project1/-/jobs/99.json',
pagePath: '/group1/project1/-/jobs/99',
});
expect(stateCopy).toMatchObject({
jobLogEndpoint: '/group1/project1/-/jobs/99',
jobEndpoint: '/group1/project1/-/jobs/99.json',
});
});
});
describe('HIDE_SIDEBAR', () => {
it('should set isSidebarOpen to false', () => {
mutations[types.HIDE_SIDEBAR](stateCopy);
expect(stateCopy.isSidebarOpen).toEqual(false);
});
});
describe('SHOW_SIDEBAR', () => {
it('should set isSidebarOpen to true', () => {
mutations[types.SHOW_SIDEBAR](stateCopy);
expect(stateCopy.isSidebarOpen).toEqual(true);
});
});
describe('RECEIVE_JOB_LOG_SUCCESS', () => {
describe('when job log has state', () => {
it('sets jobLogState', () => {
const logState =
'eyJvZmZzZXQiOjczNDQ1MSwibl9vcGVuX3RhZ3MiOjAsImZnX2NvbG9yIjpudWxsLCJiZ19jb2xvciI6bnVsbCwic3R5bGVfbWFzayI6MH0=';
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
state: logState,
});
expect(stateCopy.jobLogState).toEqual(logState);
});
});
describe('when jobLogSize is smaller than the total size', () => {
it('sets isJobLogSizeVisible to true', () => {
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, { total: 51184600, size: 1231 });
expect(stateCopy.isJobLogSizeVisible).toEqual(true);
});
});
describe('when jobLogSize is bigger than the total size', () => {
it('sets isJobLogSizeVisible to false', () => {
const copy = { ...stateCopy, jobLogSize: 5118460, size: 2321312 };
mutations[types.RECEIVE_JOB_LOG_SUCCESS](copy, { total: 511846 });
expect(copy.isJobLogSizeVisible).toEqual(false);
});
});
it('sets job log size and isJobLogComplete', () => {
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
append: true,
html,
size: 511846,
complete: true,
lines: [],
});
expect(stateCopy.jobLogSize).toEqual(511846);
expect(stateCopy.isJobLogComplete).toEqual(true);
});
describe('with new job log', () => {
describe('log.lines', () => {
describe('when append is true', () => {
it('sets the parsed log', () => {
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
append: true,
size: 511846,
complete: true,
lines: [
{
offset: 1,
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
},
],
});
expect(stateCopy.jobLog).toEqual([
{
offset: 1,
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
lineNumber: 1,
},
]);
});
});
describe('when it is defined', () => {
it('sets the parsed log', () => {
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
append: false,
size: 511846,
complete: true,
lines: [
{ offset: 0, content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }] },
],
});
expect(stateCopy.jobLog).toEqual([
{
offset: 0,
content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }],
lineNumber: 1,
},
]);
});
});
describe('when it is null', () => {
it('sets the default value', () => {
mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, {
append: true,
html,
size: 511846,
complete: false,
lines: null,
});
expect(stateCopy.jobLog).toEqual([]);
});
});
});
});
});
describe('SET_JOB_LOG_TIMEOUT', () => {
it('sets the jobLogTimeout id', () => {
const id = 7;
expect(stateCopy.jobLogTimeout).not.toEqual(id);
mutations[types.SET_JOB_LOG_TIMEOUT](stateCopy, id);
expect(stateCopy.jobLogTimeout).toEqual(id);
});
});
describe('STOP_POLLING_JOB_LOG', () => {
it('sets isJobLogComplete to true', () => {
mutations[types.STOP_POLLING_JOB_LOG](stateCopy);
expect(stateCopy.isJobLogComplete).toEqual(true);
});
});
describe('TOGGLE_COLLAPSIBLE_LINE', () => {
it('toggles the `isClosed` property of the provided object', () => {
const section = { isClosed: true };
mutations[types.TOGGLE_COLLAPSIBLE_LINE](stateCopy, section);
expect(section.isClosed).toEqual(false);
});
});
describe('REQUEST_JOB', () => {
it('sets isLoading to true', () => {
mutations[types.REQUEST_JOB](stateCopy);
expect(stateCopy.isLoading).toEqual(true);
});
});
describe('RECEIVE_JOB_SUCCESS', () => {
it('sets is loading to false', () => {
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321 });
expect(stateCopy.isLoading).toEqual(false);
});
it('sets hasError to false', () => {
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321 });
expect(stateCopy.hasError).toEqual(false);
});
it('sets job data', () => {
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321 });
expect(stateCopy.job).toEqual({ id: 1312321 });
});
it('sets selectedStage when the selectedStage is empty', () => {
expect(stateCopy.selectedStage).toEqual('');
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321, stage: 'deploy' });
expect(stateCopy.selectedStage).toEqual('deploy');
});
it('does not set selectedStage when the selectedStage is not More', () => {
stateCopy.selectedStage = 'notify';
expect(stateCopy.selectedStage).toEqual('notify');
mutations[types.RECEIVE_JOB_SUCCESS](stateCopy, { id: 1312321, stage: 'deploy' });
expect(stateCopy.selectedStage).toEqual('notify');
});
});
describe('RECEIVE_JOB_ERROR', () => {
it('resets job data', () => {
mutations[types.RECEIVE_JOB_ERROR](stateCopy);
expect(stateCopy.isLoading).toEqual(false);
expect(stateCopy.job).toEqual({});
});
});
describe('REQUEST_JOBS_FOR_STAGE', () => {
it('sets isLoadingJobs to true', () => {
mutations[types.REQUEST_JOBS_FOR_STAGE](stateCopy, { name: 'deploy' });
expect(stateCopy.isLoadingJobs).toEqual(true);
});
it('sets selectedStage', () => {
mutations[types.REQUEST_JOBS_FOR_STAGE](stateCopy, { name: 'deploy' });
expect(stateCopy.selectedStage).toEqual('deploy');
});
});
describe('RECEIVE_JOBS_FOR_STAGE_SUCCESS', () => {
beforeEach(() => {
mutations[types.RECEIVE_JOBS_FOR_STAGE_SUCCESS](stateCopy, [{ name: 'karma' }]);
});
it('sets isLoadingJobs to false', () => {
expect(stateCopy.isLoadingJobs).toEqual(false);
});
it('sets jobs', () => {
expect(stateCopy.jobs).toEqual([{ name: 'karma' }]);
});
});
describe('RECEIVE_JOBS_FOR_STAGE_ERROR', () => {
beforeEach(() => {
mutations[types.RECEIVE_JOBS_FOR_STAGE_ERROR](stateCopy);
});
it('sets isLoadingJobs to false', () => {
expect(stateCopy.isLoadingJobs).toEqual(false);
});
it('resets jobs', () => {
expect(stateCopy.jobs).toEqual([]);
});
});
});
|