Files
freeCodeCamp/common/app/routes/challenges/Test-Suite.jsx

80 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { PropTypes, PureComponent } from 'react';
2016-05-13 20:04:56 -07:00
import classnames from 'classnames';
2016-03-05 21:06:04 -08:00
import { Col, Row } from 'react-bootstrap';
import ns from './ns.json';
const propTypes = {
tests: PropTypes.arrayOf(PropTypes.object)
};
2016-03-05 21:06:04 -08:00
function getAccessibleText(err, pass, text) {
let accessibleText = 'Waiting';
// Determine test status (i.e. icon)
if (err) {
accessibleText = 'Error';
} else if (pass) {
accessibleText = 'Pass';
}
// Append the text itself
return accessibleText + ' - ' + text;
}
export default class TestSuite extends PureComponent {
renderTests(tests = []) {
// err && pass > invalid state
// err && !pass > failed tests
// !err && pass > passed tests
// !err && !pass > in-progress
return tests.map(({ err, pass = false, text = '' }, index)=> {
2016-05-13 20:04:56 -07:00
const iconClass = classnames({
'big-icon': true,
'ion-close-circled error-icon': err && !pass,
'ion-checkmark-circled success-icon': !err && pass,
'ion-refresh refresh-icon': !err && !pass
2016-05-13 20:04:56 -07:00
});
2016-03-05 21:06:04 -08:00
return (
<Row
aria-label={ getAccessibleText(err, pass, text) }
key={ text.slice(-6) + index }
tabIndex='0'
>
2016-03-05 21:06:04 -08:00
<Col
className='text-center'
xs={ 2 }
>
<i
aria-hidden='true'
className={ iconClass }
/>
2016-03-05 21:06:04 -08:00
</Col>
<Col
aria-hidden='true'
2016-03-05 21:06:04 -08:00
className='test-output'
2016-05-13 20:04:56 -07:00
dangerouslySetInnerHTML={{ __html: text }}
xs={ 10 }
/>
2016-03-05 21:06:04 -08:00
</Row>
);
});
}
render() {
const { tests } = this.props;
2016-03-05 21:06:04 -08:00
return (
<div
className={ `${ns}-test-suite` }
style={{ marginTop: '10px' }}
>
{ this.renderTests(tests) }
<div className='big-spacer' />
2016-03-05 21:06:04 -08:00
</div>
);
}
}
TestSuite.displayName = 'TestSuite';
TestSuite.propTypes = propTypes;