aboutsummaryrefslogtreecommitdiff
path: root/src/Blocks.js
blob: d9020fa17700361624c80ca1cda3fb1511356aa1 (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
/*
 * 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';

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);
  }
}