This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathbuild-status.test.js
301 lines (264 loc) · 8.77 KB
/
build-status.test.js
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
import {
buildStatusFromStatusContext,
buildStatusFromCheckResult,
combineBuildStatuses,
} from '../../lib/models/build-status';
describe('BuildStatus', function() {
it('interprets an EXPECTED status context', function() {
assert.deepEqual(buildStatusFromStatusContext({state: 'EXPECTED'}), {
icon: 'primitive-dot',
classSuffix: 'pending',
});
});
it('interprets a PENDING status context', function() {
assert.deepEqual(buildStatusFromStatusContext({state: 'PENDING'}), {
icon: 'primitive-dot',
classSuffix: 'pending',
});
});
it('interprets a SUCCESS status context', function() {
assert.deepEqual(buildStatusFromStatusContext({state: 'SUCCESS'}), {
icon: 'check',
classSuffix: 'success',
});
});
it('interprets an ERROR status context', function() {
assert.deepEqual(buildStatusFromStatusContext({state: 'ERROR'}), {
icon: 'alert',
classSuffix: 'failure',
});
});
it('interprets a FAILURE status context', function() {
assert.deepEqual(buildStatusFromStatusContext({state: 'FAILURE'}), {
icon: 'x',
classSuffix: 'failure',
});
});
it('interprets an unexpected status context', function() {
assert.deepEqual(buildStatusFromStatusContext({state: 'UNEXPECTED'}), {
icon: 'unverified',
classSuffix: 'pending',
});
});
it('interprets a QUEUED check result', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'QUEUED'}), {
icon: 'primitive-dot',
classSuffix: 'pending',
});
});
it('interprets a REQUESTED check result', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'REQUESTED'}), {
icon: 'primitive-dot',
classSuffix: 'pending',
});
});
it('interprets an IN_PROGRESS check result', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'IN_PROGRESS'}), {
icon: 'primitive-dot',
classSuffix: 'pending',
});
});
it('interprets a SUCCESS check conclusion', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'SUCCESS'}), {
icon: 'check',
classSuffix: 'success',
});
});
it('interprets a FAILURE check conclusion', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'FAILURE'}), {
icon: 'x',
classSuffix: 'failure',
});
});
it('interprets a TIMED_OUT check conclusion', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'TIMED_OUT'}), {
icon: 'alert',
classSuffix: 'failure',
});
});
it('interprets a CANCELLED check conclusion', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'CANCELLED'}), {
icon: 'alert',
classSuffix: 'failure',
});
});
it('interprets an ACTION_REQUIRED check conclusion', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'ACTION_REQUIRED'}), {
icon: 'bell',
classSuffix: 'failure',
});
});
it('interprets a NEUTRAL check conclusion', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'NEUTRAL'}), {
icon: 'dash',
classSuffix: 'neutral',
});
});
it('interprets an unexpected check status', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'WAT'}), {
icon: 'unverified',
classSuffix: 'pending',
});
});
it('interprets an unexpected check conclusion', function() {
assert.deepEqual(buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'HUH'}), {
icon: 'unverified',
classSuffix: 'pending',
});
});
describe('combine', function() {
const actionRequireds = [
buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'ACTION_REQUIRED'}),
];
const pendings = [
buildStatusFromCheckResult({status: 'QUEUED'}),
buildStatusFromCheckResult({status: 'IN_PROGRESS'}),
buildStatusFromCheckResult({status: 'REQUESTED'}),
buildStatusFromStatusContext({state: 'EXPECTED'}),
buildStatusFromStatusContext({state: 'PENDING'}),
];
const errors = [
buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'TIMED_OUT'}),
buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'CANCELLED'}),
buildStatusFromStatusContext({state: 'ERROR'}),
];
const failures = [
buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'FAILURE'}),
buildStatusFromStatusContext({state: 'FAILURE'}),
];
const successes = [
buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'SUCCESS'}),
buildStatusFromStatusContext({state: 'SUCCESS'}),
];
const neutrals = [
buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'NEUTRAL'}),
];
it('combines nothing into NEUTRAL', function() {
assert.deepEqual(combineBuildStatuses(), {
icon: 'dash',
classSuffix: 'neutral',
});
});
it('combines anything and ACTION_REQUIRED into ACTION_REQUIRED', function() {
const all = [
...actionRequireds,
...pendings,
...errors,
...failures,
...successes,
...neutrals,
];
const actionRequired = buildStatusFromCheckResult({status: 'COMPLETED', conclusion: 'ACTION_REQUIRED'});
for (const buildStatus of all) {
assert.deepEqual(combineBuildStatuses(buildStatus, actionRequired), {
icon: 'bell',
classSuffix: 'failure',
});
assert.deepEqual(combineBuildStatuses(actionRequired, buildStatus), {
icon: 'bell',
classSuffix: 'failure',
});
}
});
it('combines anything but ACTION_REQUIRED and ERROR into ERROR', function() {
const rest = [
...errors,
...pendings,
...failures,
...successes,
...neutrals,
];
for (const errorStatus of errors) {
for (const otherStatus of rest) {
assert.deepEqual(combineBuildStatuses(otherStatus, errorStatus), {
icon: 'alert',
classSuffix: 'failure',
});
assert.deepEqual(combineBuildStatuses(errorStatus, otherStatus), {
icon: 'alert',
classSuffix: 'failure',
});
}
}
});
it('combines anything but ACTION_REQUIRED or ERROR and FAILURE into FAILURE', function() {
const rest = [
...pendings,
...failures,
...successes,
...neutrals,
];
for (const failureStatus of failures) {
for (const otherStatus of rest) {
assert.deepEqual(combineBuildStatuses(otherStatus, failureStatus), {
icon: 'x',
classSuffix: 'failure',
});
assert.deepEqual(combineBuildStatuses(failureStatus, otherStatus), {
icon: 'x',
classSuffix: 'failure',
});
}
}
});
it('combines anything but ACTION_REQUIRED, ERROR, or FAILURE and PENDING into PENDING', function() {
const rest = [
...pendings,
...successes,
...neutrals,
];
for (const pendingStatus of pendings) {
for (const otherStatus of rest) {
assert.deepEqual(combineBuildStatuses(otherStatus, pendingStatus), {
icon: 'primitive-dot',
classSuffix: 'pending',
});
assert.deepEqual(combineBuildStatuses(pendingStatus, otherStatus), {
icon: 'primitive-dot',
classSuffix: 'pending',
});
}
}
});
it('combines SUCCESSes into SUCCESS', function() {
const rest = [
...successes,
...neutrals,
];
for (const successStatus of successes) {
for (const otherStatus of rest) {
assert.deepEqual(combineBuildStatuses(otherStatus, successStatus), {
icon: 'check',
classSuffix: 'success',
});
assert.deepEqual(combineBuildStatuses(successStatus, otherStatus), {
icon: 'check',
classSuffix: 'success',
});
}
}
});
it('ignores NEUTRAL', function() {
const all = [
...actionRequireds,
...pendings,
...errors,
...failures,
...successes,
...neutrals,
];
for (const neutralStatus of neutrals) {
for (const otherStatus of all) {
assert.deepEqual(combineBuildStatuses(otherStatus, neutralStatus), otherStatus);
assert.deepEqual(combineBuildStatuses(neutralStatus, otherStatus), otherStatus);
}
}
});
it('combines NEUTRALs into NEUTRAL', function() {
assert.deepEqual(combineBuildStatuses(neutrals[0], neutrals[0]), {
icon: 'dash',
classSuffix: 'neutral',
});
});
});
});