aboutsummaryrefslogtreecommitdiff
path: root/src/Blocks.js
blob: f8305385ec26d17afa7f0ae594076fb7452ec72a (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * JaCoCo Report Viewer, a web-based coverage report viewer
 * Copyright (C) 2018  Pacien TRAN-GIRARD
 *                     Adam NAILI
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import React, { Component } from 'react';
import { CoverageListing } from './CoverageListing.js';

function renderRows(renderRowFunc, rows, inline) {
  const renderedRows = rows ? rows.map(renderRowFunc) : (<li>None.</li>);
  return (<ul inline-list={inline.toString()}>{renderedRows}</ul>);
}

export class SessionInfo extends Component {
  _renderRow(row) {
    const date = new Date(parseInt(row.start));
    return (<li key={row.id}>{row.id}: {date.toISOString()} ({row.dump - row.start} ms)</li>);
  }

  render() {
    return renderRows(row => this._renderRow(row.$), this.props.data, false);
  }
}

export class Counters extends Component {
  _renderRow(row) {
    const covered = parseInt(row.covered);
    const totalCount = covered + parseInt(row.missed);
    const wellCovered = covered === totalCount;
    return (<li key={row.type} well-covered={wellCovered.toString()}>{row.type}: {covered}/{totalCount}</li>);
  }

  render() {
    return renderRows(row => this._renderRow(row.$), this.props.data, this.props.inlineList !== undefined);
  }
}

export class PackagesCoverage extends Component {
  _renderRow(row) {
    return (
      <li key={row.$.name}>
        <span>{row.$.name}</span>
        <Counters data={row.counter} inlineList="true" />
        <ClassesCoverage classes={row.class} />
      </li>
    )
  }

  render() {
    return renderRows(this._renderRow, this.props.packages, false);
  }
}

class ClassesCoverage extends Component {
  _renderRow(row) {
    const counters = row.counter.filter(counter => counter.$.type !== 'CLASS');
    return (
      <li key={row.$.name}>
        <span>{row.$.name}</span>
        <Counters data={counters} inlineList="true" />
        <MethodsCoverage methods={row.method} />
      </li>
    )
  }

  render() {
    return renderRows(this._renderRow, this.props.classes, false);
  }
}

class MethodsCoverage extends Component {
  _renderRow(row) {
    const counters = row.counter.filter(counter => counter.$.type !== 'METHOD');
    const method = row.$.name + row.$.desc + ':' + row.$.line;
    return (
      <li key={method}>
        <span>{method}</span>
        <Counters data={counters} inlineList="true" />
      </li>
    )
  }

  render() {
    return renderRows(this._renderRow, this.props.methods, false);
  }
}

export class PackagesSourceCoverage extends Component {
  _renderRow(row) {
    return (
      <li key={row.$.name}>
        <span>{row.$.name}</span>
        <SourcesCoverage package={row.$.name} 
                         packageSourceFiles={row.sourcefile}
                         sourceSet={this.props.sourceSet} />
      </li>
    )
  }

  render() {
    return renderRows(row => this._renderRow(row), this.props.packages, false);
  }
}

class SourcesCoverage extends Component {
  _renderRow(row) {
    const fileName = this.props.package + '/' + row.$.name;
    return (
      <li key={fileName}>
        <span>{fileName}</span>
        <CoverageListing fileName={fileName}
                         sourceSet={this.props.sourceSet}
                         coverage={row.line} />
      </li>
    )
  }

  render() {
    return renderRows(row => this._renderRow(row), this.props.packageSourceFiles, false);
  }
}