• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / crdc-datahub-ui / 9809009086

05 Jul 2024 01:21PM UTC coverage: 35.876% (-0.8%) from 36.644%
9809009086

push

github

web-flow
Merge pull request #419 from CBIIT/CRDCDH-1253

CRDCDH-1253 Remove Data Submission Upload Types

1207 of 4007 branches covered (30.12%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

28 existing lines in 2 files now uncovered.

1953 of 4801 relevant lines covered (40.68%)

96.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.0
/src/utils/validationUtils.ts
1
/**
2
 * Updates the validity of an HTMLInputElement by setting a custom validation message.
3
 *
4
 * @param inputRef - The reference to the HTMLInputElement to be validated
5
 * @param message - The custom validation message to be set. Defaults to an empty string if not provided.
6
 */
7
export const updateInputValidity = (
40✔
8
  inputRef: React.RefObject<HTMLInputElement>,
9
  message = ""
×
10
): void => {
UNCOV
11
  if (!inputRef?.current) {
×
12
    return; // Invalid ref
×
13
  }
UNCOV
14
  if (typeof inputRef.current.setCustomValidity !== "function") {
×
15
    return; // Input element doesn't support custom validity
×
16
  }
17

UNCOV
18
  inputRef.current.setCustomValidity(message);
×
19
};
20

21
/**
22
 *  Updates the validity of a MUI select component by setting a custom validation message.
23
 *
24
 * NOTE: This interfaces with the MUI Select ref which returns { node, value, focus }
25
 *
26
 * @param selectRef - the reference to the MUI select component to be validated
27
 * @param message - The custom validation message to be set. Defaults to an empty string if not provided.
28
 */
29
export const updateSelectValidity = (selectRef, message = ""): void => {
40!
30
  if (!selectRef?.current?.node) {
×
31
    return; // Invalid ref
×
32
  }
33
  if (typeof selectRef.current.node?.setCustomValidity !== "function") {
×
34
    return; // Input element doesn't support custom validity
×
35
  }
36

37
  selectRef.current.node.setCustomValidity(message);
×
38
};
39

40
/**
41
 * Validates whether a given value (string or number) lies within a specified range.
42
 *
43
 * @param value - The value to be validated. It can be of type string or number.
44
 *                If it's a string, the function will attempt to parse a number from it.
45
 * @param min - The minimum allowed value. Defaults to 0 if not provided.
46
 * @param max - The maximum allowed value. Optional.
47
 * @param allowFloat - A boolean indicating whether floating point numbers are considered
48
 *                     valid. Defaults to false.
49
 * @returns A boolean indicating whether the value passed the validation or not.
50
 *          Returns false if the value is NaN after being parsed or if it doesn't
51
 *          fall within the min and max parameters.
52
 */
53
export const isValidInRange = (
40✔
54
  value: string | number,
55
  min = 0,
×
56
  max?: number,
57
  allowFloat = false
×
58
): boolean => {
59
  const numValue = typeof value === "string" ? parseFloat(value) : value;
×
60

61
  if (Number.isNaN(numValue)) {
×
62
    return false;
×
63
  }
64
  if (!allowFloat && !Number.isInteger(numValue)) {
×
65
    return false;
×
66
  }
67
  if (numValue < min || (max !== undefined && numValue > max)) {
×
68
    return false;
×
69
  }
70

71
  return true;
×
72
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc