-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.jsx
556 lines (519 loc) · 21.8 KB
/
index.jsx
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
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { useMutation } from '@apollo/client';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faCheck,
faTrashAlt,
faUserPlus
} from '@fortawesome/free-solid-svg-icons';
import nextId from 'react-id-generator';
import { Button, Dropdown } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import ATAlert from '../ATAlert';
import { capitalizeEachWord } from '../../utils/formatter';
import './TestQueueRow.css';
import {
ASSIGN_TESTER_MUTATION,
UPDATE_TEST_PLAN_REPORT_MUTATION,
REMOVE_TEST_PLAN_REPORT_MUTATION,
REMOVE_TESTER_MUTATION,
REMOVE_TESTER_RESULTS_MUTATION
} from '../TestQueue/queries';
const TestQueueRow = ({
user = {},
testers = [],
testPlanReport = {},
triggerDeleteTestPlanReportModal = () => {},
triggerDeleteResultsModal = () => {},
triggerTestPlanReportUpdate = () => {}
}) => {
const [alertMessage, setAlertMessage] = useState('');
const [assignTester] = useMutation(ASSIGN_TESTER_MUTATION);
const [updateTestPlanReportStatus] = useMutation(
UPDATE_TEST_PLAN_REPORT_MUTATION
);
const [removeTestPlanReport] = useMutation(
REMOVE_TEST_PLAN_REPORT_MUTATION
);
const [removeTester] = useMutation(REMOVE_TESTER_MUTATION);
const [removeTesterResults] = useMutation(REMOVE_TESTER_RESULTS_MUTATION);
const { id, isAdmin, username } = user;
const {
testPlanTarget,
testPlanVersion,
draftTestPlanRuns,
runnableTests
} = testPlanReport;
const isSignedIn = !!id;
const checkIsTesterAssigned = username => {
return draftTestPlanRuns.some(
testPlanRun => testPlanRun.tester.username === username
);
};
const currentUserAssigned = checkIsTesterAssigned(username);
const currentUserTestPlanRun = currentUserAssigned
? draftTestPlanRuns.find(({ tester }) => tester.username === username)
: {};
const testPlanRunsWithResults = draftTestPlanRuns.filter(
({ testResults }) => testResults.length > 0
);
const getTestPlanRunIdByUserId = userId => {
return draftTestPlanRuns.find(({ tester }) => tester.id === userId).id;
};
const toggleTesterAssign = async username => {
const isTesterAssigned = checkIsTesterAssigned(username);
const tester = testers.find(tester => tester.username === username);
if (isTesterAssigned) {
await removeTester({
variables: {
testReportId: testPlanReport.id,
testerId: tester.id
}
});
} else {
await assignTester({
variables: {
testReportId: testPlanReport.id,
testerId: tester.id
}
});
}
await triggerTestPlanReportUpdate();
};
const handleRemoveTestPlanReport = async () => {
await removeTestPlanReport({
variables: {
testReportId: testPlanReport.id
}
});
await triggerTestPlanReportUpdate();
};
const handleRemoveTesterResults = async testPlanRunId => {
await removeTesterResults({
variables: {
testPlanRunId
}
});
// force data after assignment changes
await triggerTestPlanReportUpdate();
};
const renderAssignedUserToTestPlan = () => {
// Determine if current user is assigned to testPlan
if (currentUserAssigned)
return (
<Link to={`/run/${currentUserTestPlanRun.id}`}>
{testPlanVersion.title ||
`"${testPlanVersion.testPlan.directory}"`}
</Link>
);
if (!isSignedIn)
return (
<Link to={`/test-plan-report/${testPlanReport.id}`}>
{testPlanVersion.title ||
`"${testPlanVersion.testPlan.directory}"`}
</Link>
);
return (
testPlanVersion.title || `"${testPlanVersion.testPlan.directory}"`
);
};
const renderAssignMenu = () => {
return (
<>
<Dropdown aria-label="Assign testers menu">
<Dropdown.Toggle
aria-label="Assign testers"
className="assign-tester"
variant="secondary"
>
<FontAwesomeIcon icon={faUserPlus} />
</Dropdown.Toggle>
<Dropdown.Menu role="menu">
{testers.length ? (
testers.map(({ username }) => {
const isTesterAssigned = checkIsTesterAssigned(
username
);
let classname = isTesterAssigned
? 'assigned'
: 'not-assigned';
return (
<Dropdown.Item
role="menuitem"
variant="secondary"
as="button"
key={nextId()}
onClick={async () => {
await toggleTesterAssign(username);
setAlertMessage(
`You have been ${
classname.includes('not')
? 'removed from'
: 'assigned to'
} this test run.`
);
}}
aria-checked={isTesterAssigned}
>
{isTesterAssigned && (
<FontAwesomeIcon icon={faCheck} />
)}
<span className={classname}>
{`${username}`}
</span>
</Dropdown.Item>
);
})
) : (
<span className="not-assigned">
No testers to assign
</span>
)}
</Dropdown.Menu>
</Dropdown>
</>
);
};
const evaluateTestPlanRunTitle = () => {
const { title: testPlanTargetName } = testPlanTarget;
const { title: apgExampleName, directory } = testPlanVersion;
return `${apgExampleName || directory} for ${testPlanTargetName}`;
};
const renderOpenAsDropdown = () => {
return (
<Dropdown className="open-run-as">
<Dropdown.Toggle
id={nextId()}
variant="secondary"
aria-label="Run as other tester"
disabled={!draftTestPlanRuns.length}
>
Open run as...
</Dropdown.Toggle>
<Dropdown.Menu role="menu">
{draftTestPlanRuns.map(({ tester }) => {
return (
<Dropdown.Item
role="menuitem"
href={`/run/${getTestPlanRunIdByUserId(
tester.id
)}?user=${tester.id}`}
key={nextId()}
>
{tester.username}
</Dropdown.Item>
);
})}
</Dropdown.Menu>
</Dropdown>
);
};
const renderDeleteMenu = () => {
if (testPlanRunsWithResults.length) {
return (
<>
<Dropdown aria-label="Delete results menu">
<Dropdown.Toggle variant="danger">
<FontAwesomeIcon icon={faTrashAlt} />
Delete for...
</Dropdown.Toggle>
<Dropdown.Menu role="menu">
{testPlanRunsWithResults.map(({ id, tester }) => {
return (
<Dropdown.Item
role="menuitem"
variant="secondary"
as="button"
key={nextId()}
onClick={() => {
triggerDeleteResultsModal(
evaluateTestPlanRunTitle(),
tester.username,
() =>
handleRemoveTesterResults(
id
)
);
}}
>
<FontAwesomeIcon icon={faTrashAlt} />
{tester.username}
</Dropdown.Item>
);
})}
</Dropdown.Menu>
</Dropdown>
</>
);
}
};
const updateReportStatus = async status => {
await updateTestPlanReportStatus({
variables: {
testReportId: testPlanReport.id,
status: status
}
});
await triggerTestPlanReportUpdate();
};
const evaluateStatusAndResults = () => {
const { status: runStatus, conflicts } = testPlanReport;
let status, results;
const conflictCount = conflicts.length;
if (conflictCount > 0) {
let pluralizedStatus = `${conflictCount} Conflict${
conflictCount === 1 ? '' : 's'
}`;
status = (
<span className="status-label conflicts">
{pluralizedStatus}
</span>
);
} else if (runStatus === 'DRAFT' || !runStatus) {
status = <span className="status-label not-started">Draft</span>;
} else if (runStatus === 'IN_REVIEW') {
status = (
<span className="status-label in-progress">In Review</span>
);
}
return { status, results };
};
const evaluateNewReportStatus = () => {
const { status, conflicts } = testPlanReport;
const conflictCount = conflicts.length;
// If there are no conflicts OR the test has been marked as "final",
// and admin can mark a test run as "draft"
let newStatus;
if (
(status !== 'IN_REVIEW' &&
conflictCount === 0 &&
testPlanRunsWithResults.length > 0) ||
status === 'FINALIZED'
) {
newStatus = 'IN_REVIEW';
}
// If the results have been marked as draft and there is no conflict,
// they can be marked as "final"
else if (
status === 'IN_REVIEW' &&
conflictCount === 0 &&
testPlanRunsWithResults.length > 0
) {
newStatus = 'FINALIZED';
}
return newStatus;
};
const { status, results } = evaluateStatusAndResults();
const nextReportStatus = evaluateNewReportStatus();
return (
<tr className="test-queue-run-row">
<th>{renderAssignedUserToTestPlan()}</th>
<td>
{isSignedIn && (
<div className="testers-wrapper">
{isAdmin && renderAssignMenu()}
<div className="assign-actions">
<Button
variant="secondary"
onClick={() => toggleTesterAssign(username)}
aria-label={
!currentUserAssigned
? 'Assign Yourself'
: 'Unassign Yourself'
}
className="assign-self"
>
{!currentUserAssigned
? 'Assign Yourself'
: 'Unassign Yourself'}
</Button>
</div>
</div>
)}
<div className={(isSignedIn && 'secondary-actions') || ''}>
{draftTestPlanRuns.length !== 0 ? (
<ul className="assignees">
{draftTestPlanRuns.map(
({ tester, testResults }) => (
<li key={nextId()}>
<a
href={
`https://github.com/` +
`${tester.username}`
}
target="_blank"
rel="noopener noreferrer"
// Allows ATs to read the number of
// completed tests when tabbing to this
// link
aria-describedby={
`assignee-${tester.username}-` +
`completed`
}
>
{tester.username}
</a>
<div
id={
`assignee-${tester.username}-` +
`completed`
}
>
{`(${testResults.reduce(
(acc, { completedAt }) =>
acc + (completedAt ? 1 : 0),
0
)} of ${
runnableTests.length
} tests complete)`}
</div>
</li>
)
)}
</ul>
) : (
<div className="no-assignees">No testers assigned</div>
)}
</div>
</td>
<td>
<div className="status-wrapper">{status}</div>
{isSignedIn && (
<div className="secondary-actions">
{isAdmin && nextReportStatus && (
<>
<Button
variant="secondary"
onClick={() =>
updateReportStatus(nextReportStatus)
}
>
Mark as{' '}
{capitalizeEachWord(nextReportStatus, {
splitChar: '_'
})}
</Button>
{nextReportStatus === 'Final' ? (
<Button
variant="link"
className="mt-1"
onClick={() =>
updateReportStatus('DRAFT')
}
>
Mark as Draft
</Button>
) : (
<></>
)}
</>
)}
{results}
</div>
)}
</td>
<td className="actions">
<div className="test-cta-wrapper">
{currentUserAssigned && (
<>
<Button
variant="primary"
href={`/run/${currentUserTestPlanRun.id}`}
disabled={!currentUserAssigned}
>
{currentUserTestPlanRun.testResults.length >
0 &&
currentUserTestPlanRun.testResults.length <
runnableTests.length
? 'Continue testing'
: 'Start testing'}
</Button>
<Button
variant="secondary"
onClick={() => toggleTesterAssign(username)}
className="assign-self"
>
Un-assign Yourself
</Button>
</>
)}
{!currentUserAssigned && (
<Button
variant="secondary"
onClick={() => toggleTesterAssign(username)}
className="assign-self"
>
Assign Yourself
</Button>
)}
{isAdmin && (
<Button
variant="danger"
onClick={() => {
triggerDeleteTestPlanReportModal(
testPlanReport.id,
evaluateTestPlanRunTitle(),
() => handleRemoveTestPlanReport()
);
}}
>
Remove Plan
</Button>
)}
{!isSignedIn && (
<Button
variant="primary"
href={`/test-plan-report/${testPlanReport.id}`}
>
View tests
</Button>
)}
</div>
{isSignedIn && (
<div className="secondary-actions">
{isAdmin && renderOpenAsDropdown()}
{isAdmin && renderDeleteMenu()}
{(!isAdmin &&
currentUserTestPlanRun.testResults &&
currentUserTestPlanRun.testResults.length && (
<Button
variant="danger"
onClick={() => {
triggerDeleteResultsModal(
evaluateTestPlanRunTitle(),
username,
async () =>
await handleRemoveTesterResults(
currentUserTestPlanRun.id
)
);
}}
aria-label="Delete my results"
>
<FontAwesomeIcon icon={faTrashAlt} />
Delete Results
</Button>
)) ||
null}
{alertMessage && (
<ATAlert
key={`${testPlanVersion.id}-${testPlanVersion.gitSha}-${testPlanVersion.directory}`}
message={alertMessage}
/>
)}
</div>
)}
</td>
</tr>
);
};
TestQueueRow.propTypes = {
user: PropTypes.object,
testers: PropTypes.array,
testPlanReport: PropTypes.object,
triggerDeleteTestPlanReportModal: PropTypes.func,
triggerDeleteResultsModal: PropTypes.func,
triggerTestPlanReportUpdate: PropTypes.func
};
export default TestQueueRow;