]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6331 fall back to UT or IT coverage
authorStas Vilchik <vilchiks@gmail.com>
Fri, 13 Nov 2015 15:00:34 +0000 (16:00 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 13 Nov 2015 15:00:34 +0000 (16:00 +0100)
server/sonar-web/src/main/js/apps/overview/main/coverage.js
server/sonar-web/tests/apps/overview/main/coverage-test.js [new file with mode: 0644]

index 09752ad62a83e3457de12f7b701ee15727c74111..eb0422c4bcb362d786a1d5ee7313af077abb7dd5 100644 (file)
@@ -16,10 +16,35 @@ export const GeneralCoverage = React.createClass({
     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>;
@@ -40,7 +65,8 @@ export const GeneralCoverage = React.createClass({
   },
 
   render () {
-    if (this.props.measures['overall_coverage'] == null) {
+    let coverageMetric = this.getCoverageMetric();
+    if (this.props.measures[coverageMetric] == null) {
       return null;
     }
 
@@ -51,13 +77,17 @@ export const GeneralCoverage = React.createClass({
         <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>
diff --git a/server/sonar-web/tests/apps/overview/main/coverage-test.js b/server/sonar-web/tests/apps/overview/main/coverage-test.js
new file mode 100644 (file)
index 0000000..3883c69
--- /dev/null
@@ -0,0 +1,66 @@
+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%');
+  });
+});