-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathReviewConflicts.jsx
193 lines (179 loc) · 6.77 KB
/
ReviewConflicts.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
import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import TurndownService from 'turndown';
const Wrapper = styled.div`
& h2 {
margin-top: 0;
${props => props.hideHeadline && `display: none;`}
}
& ul li {
list-style: disc;
margin: 0 0 0.5em 2em;
}
`;
const ReviewConflicts = ({
testPlanReport,
test,
hideHeadline = false,
conflictMarkdownRef = null
}) => {
const contentRef = useRef();
useEffect(() => {
if (!contentRef.current || !conflictMarkdownRef) return;
const turndownService = new TurndownService({ headingStyle: 'atx' });
conflictMarkdownRef.current = turndownService.turndown(
contentRef.current.outerHTML
);
});
const conflicts = testPlanReport.conflicts.filter(
conflict => conflict.source.test.id === test.id
);
if (conflicts.length === 0) return null;
const commandString = scenario => {
return scenario.commands.map(command => command.text).join(', then ');
};
const renderConflict = conflict => {
const assertion = conflict.source.assertion;
if (assertion) return renderAssertionResultConflict(conflict);
return renderUnexpectedBehaviorConflict(conflict);
};
const renderAssertionResultConflict = ({
source: { scenario, assertion },
conflictingResults
}) => {
const results = conflictingResults.map(result => {
const { testPlanRun, scenarioResult, assertionResult } = result;
let assertionResultFormatted;
if (assertionResult.passed) {
assertionResultFormatted = 'passing';
} else {
const reasonFormatted =
assertionResult.failedReason === 'INCORRECT_OUTPUT'
? 'incorrect output'
: 'no output';
assertionResultFormatted = `failing with ${reasonFormatted}`;
}
return (
<li key={testPlanRun.id}>
Tester {testPlanRun.tester.username} recorded output "
{scenarioResult.output}" and marked assertion as{' '}
{assertionResultFormatted}.
</li>
);
});
return (
<li key={`${assertion.id}-${commandString(scenario)}`}>
<h3>
Assertion Results for "
{commandString(scenario)}" Command and "
{assertion.text}" Assertion
</h3>
<ul>{results}</ul>
</li>
);
};
const renderUnexpectedBehaviorConflict = ({
source: { scenario },
conflictingResults
}) => {
const results = conflictingResults.map(result => {
const { testPlanRun, scenarioResult } = result;
let resultFormatted;
if (scenarioResult.unexpectedBehaviors.length) {
resultFormatted =
'the unexpected behavior ' +
scenarioResult.unexpectedBehaviors
.map(({ text }) => `"${text.toLowerCase()}"`)
.join(' and ');
} else {
resultFormatted = 'no unexpected behavior';
}
let noteFormatted = scenarioResult.unexpectedBehaviorNote
? ` with the explanation ` +
`"${scenarioResult.unexpectedBehaviorNote}"`
: '';
return (
<li key={testPlanRun.id}>
Tester {testPlanRun.tester.username} recorded output "
{scenarioResult.output}" and noted
{resultFormatted + noteFormatted}.
</li>
);
});
return (
<li key={scenario.id}>
<h3>
Unexpected Behaviors for "{commandString(scenario)}
" Command
</h3>
<ul>{results}</ul>
</li>
);
};
return (
<Wrapper ref={contentRef} hideHeadline={hideHeadline}>
<h2>Review Conflicts for "{test.title}"</h2>
<ol>{conflicts.map(renderConflict)}</ol>
</Wrapper>
);
};
ReviewConflicts.propTypes = {
testPlanReport: PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
conflicts: PropTypes.arrayOf(
PropTypes.shape({
source: PropTypes.shape({
test: PropTypes.shape({
id: PropTypes.string.isRequired
}).isRequired,
scenario: PropTypes.shape({
id: PropTypes.string.isRequired,
commands: PropTypes.arrayOf(
PropTypes.shape({
text: PropTypes.string.isRequired
})
).isRequired
}).isRequired,
assertion: PropTypes.shape({
id: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
})
}).isRequired,
conflictingResults: PropTypes.arrayOf(
PropTypes.shape({
testPlanRun: PropTypes.shape({
id: PropTypes.string.isRequired,
tester: PropTypes.shape({
username: PropTypes.string.isRequired
}).isRequired
}).isRequired,
scenarioResult: PropTypes.shape({
output: PropTypes.string.isRequired,
unexpectedBehaviors: PropTypes.arrayOf(
PropTypes.shape({
text: PropTypes.string.isRequired
})
).isRequired,
unexpectedBehaviorNote: PropTypes.string
}),
assertionResult: PropTypes.shape({
passed: PropTypes.bool.isRequired,
failedReason: PropTypes.string
})
})
).isRequired
})
).isRequired
}),
test: PropTypes.shape({
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
rowNumber: PropTypes.number.isRequired
}),
hideHeadline: PropTypes.bool,
conflictMarkdownRef: PropTypes.shape({
current: PropTypes.string
})
};
export default ReviewConflicts;