aboutsummaryrefslogtreecommitdiff
path: root/src/Blocks.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/Blocks.js')
-rw-r--r--src/Blocks.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/Blocks.js b/src/Blocks.js
new file mode 100644
index 0000000..48e0376
--- /dev/null
+++ b/src/Blocks.js
@@ -0,0 +1,99 @@
1/*
2 * JaCoCo Report Viewer, a web-based coverage report viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD
4 * Adam NAILI
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20import React, { Component } from 'react';
21
22function renderRows(renderRowFunc, rows, inline) {
23 const renderedRows = rows ? rows.map(renderRowFunc) : (<li>None.</li>);
24 return (<ul inline-list={inline.toString()}>{renderedRows}</ul>);
25}
26
27export class SessionInfo extends Component {
28 _renderRow(row) {
29 const date = new Date(parseInt(row.start));
30 return (<li key={row.id}>{row.id}: {date.toISOString()} ({row.dump - row.start} ms)</li>);
31 }
32
33 render() {
34 return renderRows(row => this._renderRow(row.$), this.props.data, false);
35 }
36}
37
38export class Counters extends Component {
39 _renderRow(row) {
40 const covered = parseInt(row.covered);
41 const totalCount = covered + parseInt(row.missed);
42 const wellCovered = covered === totalCount;
43 return (<li key={row.type} well-covered={wellCovered.toString()}>{row.type}: {covered}/{totalCount}</li>);
44 }
45
46 render() {
47 return renderRows(row => this._renderRow(row.$), this.props.data, this.props.inlineList !== undefined);
48 }
49}
50
51export class PackagesCoverage extends Component {
52 _renderRow(row) {
53 return (
54 <li key={row.$.name}>
55 <span>{row.$.name}</span>
56 <Counters data={row.counter} inlineList="true" />
57 <ClassesCoverage classes={row.class} />
58 </li>
59 )
60 }
61
62 render() {
63 return renderRows(this._renderRow, this.props.packages, false);
64 }
65}
66
67class ClassesCoverage extends Component {
68 _renderRow(row) {
69 const counters = row.counter.filter(counter => counter.$.type !== 'CLASS');
70 return (
71 <li key={row.$.name}>
72 <span>{row.$.name}</span>
73 <Counters data={counters} inlineList="true" />
74 <MethodsCoverage methods={row.method} />
75 </li>
76 )
77 }
78
79 render() {
80 return renderRows(this._renderRow, this.props.classes, false);
81 }
82}
83
84class MethodsCoverage extends Component {
85 _renderRow(row) {
86 const counters = row.counter.filter(counter => counter.$.type !== 'METHOD');
87 const method = row.$.name + ':' + row.$.line;
88 return (
89 <li key={method}>
90 <span>{method}</span>
91 <Counters data={counters} inlineList="true" />
92 </li>
93 )
94 }
95
96 render() {
97 return renderRows(this._renderRow, this.props.methods, false);
98 }
99}