|
| 1 | +import React from 'react'; |
| 2 | +import { Feedback, Fieldset } from '@components/TestRenderer'; |
| 3 | +import PropTypes from 'prop-types'; |
| 4 | + |
| 5 | +const UnexpectedBehaviorsFieldset = ({ |
| 6 | + commandIndex, |
| 7 | + unexpectedBehaviors, |
| 8 | + isSubmitted |
| 9 | +}) => { |
| 10 | + const severityOptions = ['Moderate', 'High']; |
| 11 | + |
| 12 | + return ( |
| 13 | + <Fieldset id={`cmd-${commandIndex}-problems`}> |
| 14 | + <legend>{unexpectedBehaviors.description[0]}</legend> |
| 15 | + {isSubmitted && ( |
| 16 | + <Feedback |
| 17 | + className={`${ |
| 18 | + unexpectedBehaviors.description[1].required && |
| 19 | + 'required' |
| 20 | + } ${ |
| 21 | + unexpectedBehaviors.description[1].highlightRequired && |
| 22 | + 'highlight-required' |
| 23 | + }`} |
| 24 | + > |
| 25 | + {unexpectedBehaviors.description[1].description} |
| 26 | + </Feedback> |
| 27 | + )} |
| 28 | + <div> |
| 29 | + <input |
| 30 | + key={`Problem__${commandIndex}__true`} |
| 31 | + type="radio" |
| 32 | + id={`problem-${commandIndex}-true`} |
| 33 | + name={`problem-${commandIndex}`} |
| 34 | + autoFocus={ |
| 35 | + isSubmitted && unexpectedBehaviors.passChoice.focus |
| 36 | + } |
| 37 | + defaultChecked={unexpectedBehaviors.passChoice.checked} |
| 38 | + onClick={unexpectedBehaviors.passChoice.click} |
| 39 | + /> |
| 40 | + <label |
| 41 | + id={`problem-${commandIndex}-true-label`} |
| 42 | + htmlFor={`problem-${commandIndex}-true`} |
| 43 | + > |
| 44 | + {unexpectedBehaviors.passChoice.label} |
| 45 | + </label> |
| 46 | + </div> |
| 47 | + <div> |
| 48 | + <input |
| 49 | + key={`Problem__${commandIndex}__false`} |
| 50 | + type="radio" |
| 51 | + id={`problem-${commandIndex}-false`} |
| 52 | + name={`problem-${commandIndex}`} |
| 53 | + autoFocus={ |
| 54 | + isSubmitted && unexpectedBehaviors.failChoice.focus |
| 55 | + } |
| 56 | + defaultChecked={unexpectedBehaviors.failChoice.checked} |
| 57 | + onClick={unexpectedBehaviors.failChoice.click} |
| 58 | + /> |
| 59 | + <label |
| 60 | + id={`problem-${commandIndex}-false-label`} |
| 61 | + htmlFor={`problem-${commandIndex}-false`} |
| 62 | + > |
| 63 | + {unexpectedBehaviors.failChoice.label} |
| 64 | + </label> |
| 65 | + </div> |
| 66 | + |
| 67 | + <Fieldset |
| 68 | + className="problem-select" |
| 69 | + hidden={!unexpectedBehaviors.failChoice.checked} |
| 70 | + > |
| 71 | + <legend>{unexpectedBehaviors.failChoice.options.header}</legend> |
| 72 | + {unexpectedBehaviors.failChoice.options.options.map( |
| 73 | + (option, optionIndex) => { |
| 74 | + const { |
| 75 | + checked, |
| 76 | + focus, |
| 77 | + description, |
| 78 | + more, |
| 79 | + severity, |
| 80 | + change, |
| 81 | + severitychange |
| 82 | + } = option; |
| 83 | + |
| 84 | + return ( |
| 85 | + <Fieldset |
| 86 | + key={`AssertionOptionsKey_${optionIndex}`} |
| 87 | + className="undesirable-fieldset" |
| 88 | + > |
| 89 | + <legend>{description}</legend> |
| 90 | + <div> |
| 91 | + <input |
| 92 | + key={`${description}__${commandIndex}`} |
| 93 | + type="checkbox" |
| 94 | + value={description} |
| 95 | + id={`${description}-${commandIndex}`} |
| 96 | + className={`undesirable-${commandIndex}`} |
| 97 | + tabIndex={optionIndex === 0 ? 0 : -1} |
| 98 | + autoFocus={isSubmitted && focus} |
| 99 | + defaultChecked={checked} |
| 100 | + onClick={e => change(e.target.checked)} |
| 101 | + /> |
| 102 | + <label |
| 103 | + htmlFor={`${description}-${commandIndex}`} |
| 104 | + > |
| 105 | + Behavior occurred |
| 106 | + </label> |
| 107 | + </div> |
| 108 | + <div> |
| 109 | + <label |
| 110 | + htmlFor={`${description}-${commandIndex}-severity`} |
| 111 | + > |
| 112 | + Impact: |
| 113 | + </label> |
| 114 | + <select |
| 115 | + id={`${description}-${commandIndex}-severity`} |
| 116 | + name={`${description}-${commandIndex}-severity`} |
| 117 | + onChange={e => |
| 118 | + severitychange(e.target.value) |
| 119 | + } |
| 120 | + disabled={!checked} |
| 121 | + defaultValue={severity} |
| 122 | + > |
| 123 | + {severityOptions.map(option => ( |
| 124 | + <option |
| 125 | + key={`${description}-${commandIndex}-severity-${option}`} |
| 126 | + value={option.toUpperCase()} |
| 127 | + > |
| 128 | + {option} |
| 129 | + </option> |
| 130 | + ))} |
| 131 | + </select> |
| 132 | + </div> |
| 133 | + {more && ( |
| 134 | + <div> |
| 135 | + <label |
| 136 | + htmlFor={`${description}-${commandIndex}-input`} |
| 137 | + > |
| 138 | + Details: |
| 139 | + </label> |
| 140 | + <input |
| 141 | + key={`${description}__${commandIndex}__input`} |
| 142 | + type="text" |
| 143 | + id={`${description}-${commandIndex}-input`} |
| 144 | + name={`${description}-${commandIndex}-input`} |
| 145 | + className={`undesirable-${description.toLowerCase()}-input`} |
| 146 | + autoFocus={ |
| 147 | + isSubmitted && more.focus |
| 148 | + } |
| 149 | + value={more.value} |
| 150 | + onChange={e => |
| 151 | + more.change(e.target.value) |
| 152 | + } |
| 153 | + disabled={!checked} |
| 154 | + /> |
| 155 | + {isSubmitted && ( |
| 156 | + <Feedback |
| 157 | + className={`${ |
| 158 | + more.description[1] |
| 159 | + .required && 'required' |
| 160 | + } ${ |
| 161 | + more.description[1] |
| 162 | + .highlightRequired && |
| 163 | + 'highlight-required' |
| 164 | + }`} |
| 165 | + > |
| 166 | + { |
| 167 | + more.description[1] |
| 168 | + .description |
| 169 | + } |
| 170 | + </Feedback> |
| 171 | + )} |
| 172 | + </div> |
| 173 | + )} |
| 174 | + </Fieldset> |
| 175 | + ); |
| 176 | + } |
| 177 | + )} |
| 178 | + </Fieldset> |
| 179 | + </Fieldset> |
| 180 | + ); |
| 181 | +}; |
| 182 | + |
| 183 | +UnexpectedBehaviorsFieldset.propTypes = { |
| 184 | + commandIndex: PropTypes.number.isRequired, |
| 185 | + unexpectedBehaviors: PropTypes.object.isRequired, |
| 186 | + isSubmitted: PropTypes.bool |
| 187 | +}; |
| 188 | + |
| 189 | +export default UnexpectedBehaviorsFieldset; |
0 commit comments