diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-11-13 16:00:34 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-11-13 16:00:34 +0100 |
commit | f2265bb40755e31f983199204b6b24f88360f3ed (patch) | |
tree | 7821063f1eb70f6c0e8bdcbe1d95b3cb3709254c /server | |
parent | 32f0628b5399d2c2060f8b5c26e9534820185cee (diff) | |
download | sonarqube-f2265bb40755e31f983199204b6b24f88360f3ed.tar.gz sonarqube-f2265bb40755e31f983199204b6b24f88360f3ed.zip |
SONAR-6331 fall back to UT or IT coverage
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-web/src/main/js/apps/overview/main/coverage.js | 44 | ||||
-rw-r--r-- | server/sonar-web/tests/apps/overview/main/coverage-test.js | 66 |
2 files changed, 103 insertions, 7 deletions
diff --git a/server/sonar-web/src/main/js/apps/overview/main/coverage.js b/server/sonar-web/src/main/js/apps/overview/main/coverage.js index 09752ad62a8..eb0422c4bcb 100644 --- a/server/sonar-web/src/main/js/apps/overview/main/coverage.js +++ b/server/sonar-web/src/main/js/apps/overview/main/coverage.js @@ -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 index 00000000000..3883c69a8e6 --- /dev/null +++ b/server/sonar-web/tests/apps/overview/main/coverage-test.js @@ -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%'); + }); +}); |