aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/overview/coverage/coverage-details.js
blob: 403d8b69120c9d6e00a446d2df17ee7c61d6d25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React from 'react';
import { getMeasures } from '../../../api/measures';


const METRICS = [
  'coverage',
  'line_coverage',
  'branch_coverage',
  'it_coverage',
  'it_line_coverage',
  'it_branch_coverage',
  'overall_coverage',
  'overall_line_coverage',
  'overall_branch_coverage'
];


function formatCoverage (value) {
  return value != null ? window.formatMeasure(value, 'PERCENT') : '—';
}


export class CoverageDetails extends React.Component {
  constructor () {
    super();
    this.state = { measures: {} };
  }

  componentDidMount () {
    this.requestDetails();
  }

  requestDetails () {
    return getMeasures(this.props.component.key, METRICS).then(measures => {
      this.setState({ measures });
    });
  }

  renderCoverage (coverage, lineCoverage, branchCoverage) {
    return <table className="data zebra">
      <tbody>
      <tr>
        <td>Coverage</td>
        <td className="thin nowrap text-right">
          {formatCoverage(coverage)}
        </td>
      </tr>
      <tr>
        <td>Line Coverage</td>
        <td className="thin nowrap text-right">
          {formatCoverage(lineCoverage)}
        </td>
      </tr>
      <tr>
        <td>Branch Coverage</td>
        <td className="thin nowrap text-right">
          {formatCoverage(branchCoverage)}
        </td>
      </tr>
      </tbody>
    </table>;
  }

  renderUTCoverage () {
    if (this.state.measures['coverage'] == null) {
      return null;
    }
    return <div className="big-spacer-top">
      <h4 className="spacer-bottom">Unit Tests</h4>
      {this.renderCoverage(
          this.state.measures['coverage'],
          this.state.measures['line_coverage'],
          this.state.measures['branch_coverage'])}
    </div>;
  }

  renderITCoverage () {
    if (this.state.measures['it_coverage'] == null) {
      return null;
    }
    return <div className="big-spacer-top">
      <h4 className="spacer-bottom">Integration Tests</h4>
      {this.renderCoverage(
          this.state.measures['it_coverage'],
          this.state.measures['it_line_coverage'],
          this.state.measures['it_branch_coverage'])}
    </div>;
  }

  renderOverallCoverage () {
    if (this.state.measures['coverage'] == null ||
        this.state.measures['it_coverage'] == null ||
        this.state.measures['overall_coverage'] == null) {
      return null;
    }
    return <div className="big-spacer-top">
      <h4 className="spacer-bottom">Overall</h4>
      {this.renderCoverage(
          this.state.measures['overall_coverage'],
          this.state.measures['overall_line_coverage'],
          this.state.measures['overall_branch_coverage'])}
    </div>;
  }

  render () {
    return <div className="overview-domain-section">
      <h2 className="overview-title">Coverage Details</h2>
      {this.renderUTCoverage()}
      {this.renderITCoverage()}
      {this.renderOverallCoverage()}
    </div>;
  }
}