aboutsummaryrefslogtreecommitdiff
path: root/src/listComponents.js
blob: 2d89ac32d509f6fa694a4bf473674bae5154de9a (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * 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 Affero 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero 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 GroupsCoverage extends Component {
  _renderChilds(row) {
    return row.group
      ? (<GroupsCoverage groups={row.group} />)
      : (<PackagesCoverage packages={row.package} />);
  }

  _renderRow(row) {
    return (
      <li key={row.$.name}>
        <span>{row.$.name}</span>
        <Counters data={row.counter} inlineList="true" />
        {this._renderChilds(row)}
      </li>
    )
  }

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

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 GroupsSourceCoverage extends Component {
  _renderChilds(row) {
    return row.group
     ? (<GroupsSourceCoverage groups={row.group} sourceSet={this.props.sourceSet} />)
     : (<PackagesSourceCoverage packages={row.package} sourceSet={this.props.sourceSet} />);
  }

  _renderRow(row) {
    return (
      <li key={row.$.name}>
        <span>{row.$.name}</span>
        {this._renderChilds(row)}
      </li>
    )
  }

  render() {
    return renderRows(row => this._renderRow(row), this.props.groups, 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);
  }
}