kitchensink
Version:
Dispatch's awesome components and style guide
125 lines (93 loc) • 4.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
require('mocha/mocha.js');
var _radium = require('radium');
var _radium2 = _interopRequireDefault(_radium);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _Test = require('./Test');
var _Test2 = _interopRequireDefault(_Test);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var TestStatus = function (_React$Component) {
_inherits(TestStatus, _React$Component);
function TestStatus(props) {
_classCallCheck(this, TestStatus);
var _this = _possibleConstructorReturn(this, (TestStatus.__proto__ || Object.getPrototypeOf(TestStatus)).call(this, props));
_this.state = {
tests: {}
};
// Prevent getting errors about needing StyleRoot wrapper
_radium2.default.TestMode.enable();
mocha.setup('bdd');
return _this;
}
_createClass(TestStatus, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.runTests(this.props.test);
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
this.runTests(nextProps.test);
}
}, {
key: 'runTests',
value: function runTests(testToRun) {
var _this2 = this;
// Clear all previous tests.
this.setState({ tests: {} });
mocha.suite.suites = [];
// Run new tests if they exits.
if (typeof testToRun === 'function') {
testToRun();
mocha.run().on('test', function (test) {
_this2.setState({ tests: Object.assign({}, _this2.state.tests, _defineProperty({}, test.title, 'yellow')) });
}).on('pass', function (test) {
_this2.setState({ tests: Object.assign({}, _this2.state.tests, _defineProperty({}, test.title, 'lightgreen')) });
}).on('fail', function (test, err) {
console.log(err);
_this2.setState({ tests: Object.assign({}, _this2.state.tests, _defineProperty({}, test.title, 'red')) });
});
}
}
}, {
key: 'renderTests',
value: function renderTests() {
return _lodash2.default.map(this.state.tests, function (status, label) {
return _react2.default.createElement(_Test2.default, { status: status, label: label, key: label });
});
}
}, {
key: 'render',
value: function render() {
var tests = _lodash2.default.isEmpty(this.state.tests) ? _react2.default.createElement(_Test2.default, { status: 'gray', label: 'No Tests' }) : this.renderTests();
return _react2.default.createElement(
'div',
{ style: Object.assign({}, TestStatus.baseStyles, this.props.style) },
_react2.default.createElement('div', { id: 'mocha', style: { display: 'none' } }),
tests
);
}
}]);
return TestStatus;
}(_react2.default.Component);
TestStatus.propTypes = {
style: _propTypes2.default.object,
test: _propTypes2.default.func
};
TestStatus.baseStyles = {
display: 'inline-block'
};
exports.default = TestStatus;