All files / utils dashboardUtils.js

100% Statements 25/25
100% Branches 20/20
100% Functions 9/9
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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        3x 609x     3x 206x     3x 207x     3x 206x     3x 205x         3x 205x         3x 1224x 1222x 1222x     3x 1216x     3x 207x 207x 207x         53x   154x                            
// dashboardUtil.js
 
import { timestampToDate, daysSinceTimestamp } from "main/utils/dateUtils";
 
const fieldOrBlank = (gamePlus, field) => {
  return gamePlus?.[field] ?? "--";
};
 
const getGameName = (gamePlus) => {
  return gamePlus?.game?.name ?? "--";
};
 
const getIsHidden = (gamePlus) => {
  return gamePlus?.game?.hidden === true;
};
 
const getGameId = (gamePlus, id) => {
  return gamePlus?.game?.id ?? id ?? "--";
};
 
const getStartingDate = (gamePlus) => {
  return gamePlus?.game?.startingDate
    ? timestampToDate(gamePlus.game.startingDate)
    : "--";
};
 
const getDaysActive = (gamePlus) => {
  return gamePlus?.game?.startingDate
    ? daysSinceTimestamp(gamePlus.game.startingDate)
    : "--";
};
 
const formatOneDecimal = (value) => {
  if (value === null) return "--";
  const numericValue = Number(value);
  return Number.isNaN(numericValue) ? "--" : numericValue.toFixed(1);
};
 
const numericFieldOrBlank = (gamePlus, field) => {
  return formatOneDecimal(gamePlus?.[field]);
};
 
const getPercentageOfCarryingCapacity = (totalCows, effectiveCapacity) => {
  const numericTotalCows = Number(totalCows);
  const numericEffectiveCapacity = Number(effectiveCapacity);
  if (
    Number.isNaN(numericTotalCows) ||
    Number.isNaN(numericEffectiveCapacity) ||
    !numericEffectiveCapacity
  ) {
    return "--";
  }
  return `${((numericTotalCows / numericEffectiveCapacity) * 100).toFixed(2)}%`;
};
 
export {
  fieldOrBlank,
  getGameName,
  getIsHidden,
  getGameId,
  getStartingDate,
  getDaysActive,
  formatOneDecimal,
  numericFieldOrBlank,
  getPercentageOfCarryingCapacity,
};