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

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-03-05 21:06:04 -08:00
import React, { PropTypes } from 'react';
2016-05-13 20:04:56 -07:00
import classnames from 'classnames';
2016-03-05 21:06:04 -08:00
import PureComponent from 'react-pure-render/component';
import { Col, Row } from 'react-bootstrap';
export default class extends PureComponent {
static displayName = 'TestSuite';
static propTypes = {
tests: PropTypes.arrayOf(PropTypes.object)
2016-03-05 21:06:04 -08:00
};
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 key={ text.slice(-6) + index }>
<Col
className='text-center'
xs={ 2 }
>
2016-03-05 21:06:04 -08:00
<i className={ iconClass } />
</Col>
<Col
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='challenge-test-suite'
style={{ marginTop: '10px' }}
>
{ this.renderTests(tests) }
<div className='big-spacer' />
2016-03-05 21:06:04 -08:00
</div>
);
}
}