All files / src/components/DatatableCore/InputTypes PickersFunction.js

100% Statements 15/15
100% Branches 10/10
100% Functions 2/2
100% Lines 15/15

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    20x 69x 69x           69x     20x                   20x 20x 20x 20x   20x         20x 18x   20x 20x             20x    
import { moment } from "../../../moment.config";
 
export const checkValue = ({ cellVal, mounting, valueVerification }) => {
  const { message, error } = valueVerification(cellVal);
  const newState = {
    tooltipOpen: mounting ? false : error,
    message,
    error
  };
 
  return newState;
};
 
export const setValue = ({
  date,
  value,
  dateFormat,
  rowId,
  columnId,
  setRowEdited,
  type,
  valueVerification
}) => {
  let cellVal = "";
  cellVal = date ? moment(date).format(dateFormat) : cellVal;
  cellVal = value || cellVal;
  cellVal = type === "number" ? parseInt(cellVal) : cellVal;
 
  let newState = {
    error: false,
    tooltipOpen: false,
    message: ""
  };
  if (valueVerification) {
    newState = checkValue({ cellVal, valueVerification });
  }
  const { error } = newState;
  setRowEdited({
    rowId,
    columnId,
    newValue: cellVal,
    error
  });
 
  return newState;
};