summaryHeader.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const React = require('react');
  2. function Ignores({ metrics, metricsToShow }) {
  3. const metricKeys = Object.keys(metricsToShow);
  4. const result = [];
  5. for (let i = 0; i < metricKeys.length; i++) {
  6. const metricKey = metricKeys[i];
  7. if (metricsToShow[metricKey]) {
  8. const skipped = metrics[metricKey].skipped;
  9. if (skipped > 0) {
  10. result.push(
  11. `${skipped} ${metricKey}${
  12. skipped === 1 ? '' : metricKey === 'branch' ? 'es' : 's'
  13. }`
  14. );
  15. }
  16. }
  17. }
  18. if (result.length === 0) {
  19. return false;
  20. }
  21. return (
  22. <div className="toolbar__item">
  23. <span className="strong">{result.join(', ')}</span>
  24. <span className="quiet">Ignored</span>
  25. </div>
  26. );
  27. }
  28. function StatusMetric({ data, name }) {
  29. return (
  30. <div className="toolbar__item">
  31. <span className="strong">{data.pct}%</span>{' '}
  32. <span className="quiet">{name}</span>{' '}
  33. <span className={'fraction ' + data.classForPercent}>
  34. {data.covered}/{data.total}
  35. </span>
  36. </div>
  37. );
  38. }
  39. module.exports = function SummaryHeader({ metrics, metricsToShow }) {
  40. return (
  41. <div className="toolbar">
  42. {metricsToShow.statements && (
  43. <StatusMetric data={metrics.statements} name="Statements" />
  44. )}
  45. {metricsToShow.branches && (
  46. <StatusMetric data={metrics.branches} name="Branches" />
  47. )}
  48. {metricsToShow.functions && (
  49. <StatusMetric data={metrics.functions} name="Functions" />
  50. )}
  51. {metricsToShow.lines && (
  52. <StatusMetric data={metrics.lines} name="Lines" />
  53. )}
  54. <Ignores metrics={metrics} metricsToShow={metricsToShow} />
  55. </div>
  56. );
  57. };