source: trip-planner-front/node_modules/istanbul-reports/lib/html-spa/src/summaryTableLine.js@ 84d0fbb

Last change on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.1 KB
Line 
1const React = require('react');
2
3function MetricCells({ metrics }) {
4 const { classForPercent, pct, covered, missed, total } = metrics;
5
6 return (
7 <>
8 <td className={'pct ' + classForPercent}>{Math.round(pct)}% </td>
9 <td className={classForPercent}>
10 <div className="bar">
11 <div
12 className={`bar__data ${classForPercent} ${classForPercent}--dark`}
13 style={{ width: pct + '%' }}
14 ></div>
15 </div>
16 </td>
17 <td className={'abs ' + classForPercent}>{covered}</td>
18 <td className={'abs ' + classForPercent}>{missed}</td>
19 <td className={'abs ' + classForPercent}>{total}</td>
20 </>
21 );
22}
23
24function FileCell({
25 file,
26 prefix,
27 expandedLines,
28 setExpandedLines,
29 hasChildren,
30 setFileFilter
31}) {
32 if (hasChildren) {
33 const expandedIndex = expandedLines.indexOf(prefix + file);
34 const isExpanded = expandedIndex >= 0;
35 const newExpandedLines = isExpanded
36 ? [
37 ...expandedLines.slice(0, expandedIndex),
38 ...expandedLines.slice(expandedIndex + 1)
39 ]
40 : [...expandedLines, prefix + file];
41
42 return (
43 <>
44 <button
45 type="button"
46 onClick={() => setExpandedLines(newExpandedLines)}
47 className="expandbutton"
48 >
49 {isExpanded ? String.fromCharCode(0x2013) : '+'}
50 </button>
51 <a
52 href="javascript:void(0)"
53 onClick={() => setFileFilter(prefix + file)}
54 >
55 {file}
56 </a>
57 </>
58 );
59 } else {
60 return <a href={`./${prefix}${file}.html`}>{file}</a>;
61 }
62}
63
64function getWorstMetricClassForPercent(metricsToShow, metrics) {
65 let classForPercent = 'none';
66 for (const metricToShow in metricsToShow) {
67 if (metricsToShow[metricToShow]) {
68 const metricClassForPercent = metrics[metricToShow].classForPercent;
69
70 // ignore none metrics so they don't change whats shown
71 if (metricClassForPercent === 'none') {
72 continue;
73 }
74
75 // if the metric low or lower than whats currently being used, replace it
76 if (
77 metricClassForPercent == 'low' ||
78 (metricClassForPercent === 'medium' &&
79 classForPercent !== 'low') ||
80 (metricClassForPercent === 'high' &&
81 classForPercent !== 'low' &&
82 classForPercent !== 'medium')
83 ) {
84 classForPercent = metricClassForPercent;
85 }
86 }
87 }
88 return classForPercent;
89}
90
91module.exports = function SummaryTableLine({
92 prefix,
93 metrics,
94 file,
95 children,
96 tabSize,
97 metricsToShow,
98 expandedLines,
99 setExpandedLines,
100 fileFilter,
101 setFileFilter
102}) {
103 tabSize = tabSize || 0;
104 if (children && tabSize > 0) {
105 tabSize--;
106 }
107 prefix = (fileFilter ? fileFilter + '/' : '') + (prefix || '');
108
109 return (
110 <>
111 <tr>
112 <td
113 className={
114 'file ' +
115 getWorstMetricClassForPercent(metricsToShow, metrics)
116 }
117 >
118 {/* eslint-disable-line prefer-spread */ Array.apply(null, {
119 length: tabSize
120 }).map((nothing, index) => (
121 <span className="filetab" key={index} />
122 ))}
123 <FileCell
124 file={file}
125 prefix={prefix}
126 expandedLines={expandedLines}
127 setExpandedLines={setExpandedLines}
128 hasChildren={Boolean(children)}
129 setFileFilter={setFileFilter}
130 />
131 </td>
132 {metricsToShow.statements && (
133 <MetricCells metrics={metrics.statements} />
134 )}
135 {metricsToShow.branches && (
136 <MetricCells metrics={metrics.branches} />
137 )}
138 {metricsToShow.functions && (
139 <MetricCells metrics={metrics.functions} />
140 )}
141 {metricsToShow.lines && <MetricCells metrics={metrics.lines} />}
142 </tr>
143 {children &&
144 expandedLines.indexOf(prefix + file) >= 0 &&
145 children.map(child => (
146 <SummaryTableLine
147 {...child}
148 tabSize={tabSize + 2}
149 key={child.file}
150 prefix={prefix + file + '/'}
151 metricsToShow={metricsToShow}
152 expandedLines={expandedLines}
153 setExpandedLines={setExpandedLines}
154 setFileFilter={setFileFilter}
155 />
156 ))}
157 </>
158 );
159};
Note: See TracBrowser for help on using the repository browser.