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

CBIIT / crdc-datahub-ui / 17135186002

21 Aug 2025 06:09PM UTC coverage: 77.612% (+1.7%) from 75.941%
17135186002

Pull #806

github

web-flow
Merge 3963dff0e into c10ceac73
Pull Request #806: Submission Request Excel Import & Export CRDCDH-3033, CRDCDH-3045, CRDCDH-3063

4850 of 5333 branches covered (90.94%)

Branch coverage included in aggregate %.

3174 of 3450 new or added lines in 33 files covered. (92.0%)

7 existing lines in 3 files now uncovered.

29048 of 38343 relevant lines covered (75.76%)

175.51 hits per line

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

87.18
/src/classes/Excel/ErrorCatalog.ts
1
/**
2
 * Defines the shape of the error messages catalog.
3
 */
4
type ErrorEntry = {
5
  [key: string]: (() => string) | ((args: unknown) => string);
6
};
7

8
/**
9
 * A catalog of error message templates used for form validation.
10
 * Each entry is a function that returns a formatted error message string.
11
 */
12
const T = {
1✔
13
  // length
14
  max: ({ max }: { max: number }) => `Must be less than or equal to ${max} characters.`,
1✔
15
  requiredMax: ({ max }: { max: number }) =>
1✔
16
    `This field is required. ${max} characters are allowed.`,
14,506✔
17

18
  // selections
19
  yesNo: () => `Please select 'Yes' or 'No' from the dropdown`,
1✔
20
  fromDropdown: (p?: { label?: string }) =>
1✔
NEW
21
    `Please select ${p?.label ?? "a value"} from the dropdown`,
×
22

23
  // formats
24
  email: () => `Please provide a valid email address.`,
1✔
25
  orcid: () => `Please provide a valid ORCID.`,
1✔
26
  dateMMDDYYYY: () => `The date is invalid. Please enter a date in the format MM/DD/YYYY.`,
1✔
27

28
  // numeric
29
  between: ({ min, max }: { min: number | string; max: number | string }) =>
1✔
30
    `Value must be between ${Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(
14✔
31
      typeof min === "string" ? parseFloat(min) : min
14!
32
    )} and ${Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(
14✔
33
      typeof max === "string" ? parseFloat(max) : max
14!
34
    )}.`,
14✔
35

36
  // generic
37
  invalidOperation: () => `Invalid operation.`,
1✔
38
} as const satisfies ErrorEntry;
1✔
39

40
// Helper Types
41
type IsFunc<T> = T extends (...args: readonly unknown[]) => unknown ? true : false;
42

43
export type ErrorKey = {
44
  [K in keyof typeof T]: IsFunc<(typeof T)[K]> extends true ? K : never;
45
}[keyof typeof T];
46

47
type ParamsOf<F> = F extends () => string
48
  ? undefined
49
  : F extends (a: infer A) => string
50
    ? A
51
    : never;
52

53
export type ErrorParams<K extends ErrorKey> = ParamsOf<(typeof T)[K]>;
54

55
type ArgsFor<F> = F extends (...args: infer P) => string
56
  ? P extends []
57
    ? []
58
    : P extends [infer A]
59
      ? undefined extends A
60
        ? [] | [Exclude<A, undefined>]
61
        : [A]
62
      : never
63
  : never;
64

65
/**
66
 * A catalog for managing error message templates.
67
 */
68
export const ErrorCatalog = {
1✔
69
  get<K extends ErrorKey>(key: K, ...args: ArgsFor<(typeof T)[K]>): string {
1✔
70
    const fn = T[key] as (...a: unknown[]) => string;
31,614✔
71
    return fn(...(args as [] | [unknown]));
31,614✔
72
  },
31,614✔
73

74
  keys(): ReadonlyArray<ErrorKey> {
1✔
NEW
75
    return Object.keys(T) as ReadonlyArray<ErrorKey>;
×
NEW
76
  },
×
77

78
  templates: T,
1✔
79
} as const;
1✔
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

© 2025 Coveralls, Inc