|
| 1 | +import React, { useMemo } from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { Fieldset } from '..'; |
| 4 | +import styled from '@emotion/styled'; |
| 5 | +import supportJson from '../../../resources/support.json'; |
| 6 | + |
| 7 | +const Label = styled.label` |
| 8 | + display: block; |
| 9 | +
|
| 10 | + input { |
| 11 | + margin-right: 0.25rem; |
| 12 | + } |
| 13 | +`; |
| 14 | + |
| 15 | +const AssertionsFieldset = ({ assertions, commandIndex, assertionsHeader }) => { |
| 16 | + // Handle case where build process didn't include assertionResponseQuestion |
| 17 | + const normalizedHeader = useMemo(() => { |
| 18 | + return assertionsHeader?.descriptionHeader?.replace( |
| 19 | + 'undefined', |
| 20 | + supportJson.testPlanStrings.assertionResponseQuestion |
| 21 | + ); |
| 22 | + }, [assertionsHeader]); |
| 23 | + |
| 24 | + return ( |
| 25 | + <Fieldset> |
| 26 | + <legend id={`command-${commandIndex}-assertions-heading`}> |
| 27 | + {normalizedHeader} |
| 28 | + </legend> |
| 29 | + {assertions.map((assertion, assertionIndex) => { |
| 30 | + const { description, passed, click } = assertion; |
| 31 | + |
| 32 | + return ( |
| 33 | + <Label key={`AssertionKey_${assertionIndex}`}> |
| 34 | + <input |
| 35 | + type="checkbox" |
| 36 | + id={`pass-${commandIndex}-${assertionIndex}`} |
| 37 | + name={`assertion-${commandIndex}-${assertionIndex}`} |
| 38 | + defaultChecked={passed} |
| 39 | + onClick={click} |
| 40 | + /> |
| 41 | + {description[0]} |
| 42 | + </Label> |
| 43 | + ); |
| 44 | + })} |
| 45 | + </Fieldset> |
| 46 | + ); |
| 47 | +}; |
| 48 | + |
| 49 | +AssertionsFieldset.propTypes = { |
| 50 | + assertions: PropTypes.array.isRequired, |
| 51 | + commandIndex: PropTypes.number.isRequired, |
| 52 | + assertionsHeader: PropTypes.object.isRequired |
| 53 | +}; |
| 54 | + |
| 55 | +export default AssertionsFieldset; |
0 commit comments