leakPeriodDate: React.PropTypes.object
},
- renderNewCoverage () {
+ getCoverageMetric () {
+ if (this.props.measures['overall_coverage'] != null) {
+ return 'overall_coverage';
+ } else if (this.props.measures['coverage'] != null) {
+ return 'coverage';
+ } else {
+ return 'it_coverage';
+ }
+ },
+
+ getNewCoverageMetric () {
if (this.props.leak['new_overall_coverage'] != null) {
- return <DrilldownLink component={this.props.component.key} metric="new_overall_coverage" period="1">
- {formatMeasure(this.props.leak['new_overall_coverage'], 'PERCENT')}
+ return 'new_overall_coverage';
+ } else if (this.props.leak['new_coverage'] != null) {
+ return 'new_coverage';
+ } else {
+ return 'new_it_coverage';
+ }
+ },
+
+ renderNewCoverage () {
+ let newCoverageMetric = this.getNewCoverageMetric();
+
+ // FIXME fix period index
+ if (this.props.leak[newCoverageMetric] != null) {
+ return <DrilldownLink component={this.props.component.key} metric={newCoverageMetric} period="1">
+ <span className="js-overview-main-new-coverage">
+ {formatMeasure(this.props.leak[newCoverageMetric], 'PERCENT')}
+ </span>
</DrilldownLink>;
} else {
return <span>—</span>;
},
render () {
- if (this.props.measures['overall_coverage'] == null) {
+ let coverageMetric = this.getCoverageMetric();
+ if (this.props.measures[coverageMetric] == null) {
return null;
}
<DomainNutshell>
<MeasuresList>
<Measure label={getMetricName('coverage')}>
- <DrilldownLink component={this.props.component.key} metric="overall_coverage">
- {formatMeasure(this.props.measures['overall_coverage'], 'PERCENT')}
+ <DrilldownLink component={this.props.component.key} metric={coverageMetric}>
+ <span className="js-overview-main-coverage">
+ {formatMeasure(this.props.measures[coverageMetric], 'PERCENT')}
+ </span>
</DrilldownLink>
</Measure>
<Measure label={getMetricName('tests')}>
<DrilldownLink component={this.props.component.key} metric="tests">
- {formatMeasure(this.props.measures['tests'], 'SHORT_INT')}
+ <span className="js-overview-main-tests">
+ {formatMeasure(this.props.measures['tests'], 'SHORT_INT')}
+ </span>
</DrilldownLink>
</Measure>
</MeasuresList>
--- /dev/null
+import _ from 'underscore';
+import { expect } from 'chai';
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import { GeneralCoverage } from '../../../../src/main/js/apps/overview/main/coverage';
+
+
+const COMPONENT = { key: 'component-key' };
+
+const DATE = new Date(2015, 0, 1);
+
+const MEASURES = {
+ 'overall_coverage': 73.5,
+ 'coverage': 69.7,
+ 'it_coverage': 54.0,
+ 'tests': 137
+};
+const LEAK = {
+ 'new_overall_coverage': 72.5,
+ 'new_coverage': 68.7,
+ 'new_it_coverage': 53.0
+};
+const MEASURES_FOR_UT = _.omit(MEASURES, 'overall_coverage');
+const LEAK_FOR_UT = _.omit(LEAK, 'new_overall_coverage');
+const MEASURES_FOR_IT = _.omit(MEASURES_FOR_UT, 'coverage');
+const LEAK_FOR_IT = _.omit(LEAK_FOR_UT, 'new_coverage');
+
+
+describe('Overview :: GeneralCoverage', function () {
+ it('should display overall coverage', function () {
+ let component = <GeneralCoverage measures={MEASURES} leak={LEAK} component={COMPONENT}
+ leakPeriodDate={DATE}/>;
+ let output = TestUtils.renderIntoDocument(component);
+
+ let coverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-coverage');
+ expect(coverageElement.textContent).to.equal('73.5%');
+
+ let newCoverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-new-coverage');
+ expect(newCoverageElement.textContent).to.equal('72.5%');
+ });
+
+ it('should fall back to UT coverage', function () {
+ let component = <GeneralCoverage measures={MEASURES_FOR_UT} leak={LEAK_FOR_UT} component={COMPONENT}
+ leakPeriodDate={DATE}/>;
+ let output = TestUtils.renderIntoDocument(component);
+
+ let coverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-coverage');
+ expect(coverageElement.textContent).to.equal('69.7%');
+
+ let newCoverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-new-coverage');
+ expect(newCoverageElement.textContent).to.equal('68.7%');
+ });
+
+ it('should fall back to IT coverage', function () {
+ let component = <GeneralCoverage measures={MEASURES_FOR_IT} leak={LEAK_FOR_IT} component={COMPONENT}
+ leakPeriodDate={DATE}/>;
+ let output = TestUtils.renderIntoDocument(component);
+
+ let coverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-coverage');
+ expect(coverageElement.textContent).to.equal('54.0%');
+
+ let newCoverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-new-coverage');
+ expect(newCoverageElement.textContent).to.equal('53.0%');
+ });
+});