]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6331 do not display tests block if there is no data
authorStas Vilchik <vilchiks@gmail.com>
Fri, 13 Nov 2015 15:27:29 +0000 (16:27 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 13 Nov 2015 15:27:29 +0000 (16:27 +0100)
server/sonar-web/src/main/js/apps/overview/main/coverage.js
server/sonar-web/tests/apps/overview/main/coverage-test.js

index 0c00feb7a4bcd20b1152df1568f38094c758ddfe..0c964a6c63c268a57430806313156f422a125484 100644 (file)
@@ -64,6 +64,18 @@ export const GeneralCoverage = React.createClass({
     </DomainLeak>;
   },
 
+  renderTests() {
+    let tests = this.props.measures['tests'];
+    if (tests == null) {
+      return null;
+    }
+    return <Measure label={getMetricName('tests')}>
+      <DrilldownLink component={this.props.component.key} metric="tests">
+        <span className="js-overview-main-tests">{formatMeasure(tests, 'SHORT_INT')}</span>
+      </DrilldownLink>
+    </Measure>;
+  },
+
   render () {
     let coverageMetric = this.getCoverageMetric();
     if (this.props.measures[coverageMetric] == null) {
@@ -83,13 +95,7 @@ export const GeneralCoverage = React.createClass({
                 </span>
               </DrilldownLink>
             </Measure>
-            <Measure label={getMetricName('tests')}>
-              <DrilldownLink component={this.props.component.key} metric="tests">
-                <span className="js-overview-main-tests">
-                  {formatMeasure(this.props.measures['tests'], 'SHORT_INT')}
-                </span>
-              </DrilldownLink>
-            </Measure>
+            {this.renderTests()}
           </MeasuresList>
           {this.renderTimeline('before')}
         </DomainNutshell>
index 3883c69a8e676a78cce5bad91ae8d5f2072e45c7..616016322dd6facd1af093cc771ece15b856f8af 100644 (file)
@@ -40,6 +40,21 @@ describe('Overview :: GeneralCoverage', function () {
     expect(newCoverageElement.textContent).to.equal('72.5%');
   });
 
+  it('should display tests', function () {
+    let component = <GeneralCoverage measures={MEASURES} component={COMPONENT}/>;
+    let output = TestUtils.renderIntoDocument(component);
+    let coverageElement = TestUtils.findRenderedDOMComponentWithClass(output, 'js-overview-main-tests');
+    expect(coverageElement.textContent).to.equal('137');
+  });
+
+  it('should not display tests', function () {
+    let measuresWithoutTests = _.omit(MEASURES, 'tests');
+    let component = <GeneralCoverage measures={measuresWithoutTests} component={COMPONENT}/>;
+    let output = TestUtils.renderIntoDocument(component);
+    let coverageElements = TestUtils.scryRenderedDOMComponentsWithClass(output, 'js-overview-main-tests');
+    expect(coverageElements).to.be.empty;
+  });
+
   it('should fall back to UT coverage', function () {
     let component = <GeneralCoverage measures={MEASURES_FOR_UT} leak={LEAK_FOR_UT} component={COMPONENT}
                                      leakPeriodDate={DATE}/>;