dce-reactkit 3.4.0 → 3.5.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/.eslintrc.js +2 -0
  2. package/.vscode/settings.json +1 -0
  3. package/dist/cjs/index.js +36372 -191
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +10 -0
  6. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +34 -0
  7. package/dist/cjs/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +9 -0
  8. package/dist/cjs/types/components/DBEntryManagerPanel/index.d.ts +25 -0
  9. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
  10. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
  11. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
  12. package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +40 -0
  13. package/dist/cjs/types/helpers/canReviewLogs.d.ts +0 -5
  14. package/dist/cjs/types/index.d.ts +6 -1
  15. package/dist/esm/index.js +36587 -427
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +10 -0
  18. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +34 -0
  19. package/dist/esm/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +9 -0
  20. package/dist/esm/types/components/DBEntryManagerPanel/index.d.ts +25 -0
  21. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
  22. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
  23. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
  24. package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +40 -0
  25. package/dist/esm/types/helpers/canReviewLogs.d.ts +0 -5
  26. package/dist/esm/types/index.d.ts +6 -1
  27. package/dist/index.d.ts +166 -35
  28. package/package.json +16 -12
  29. package/src/client/initClient.tsx +23 -31
  30. package/src/components/AppWrapper.tsx +1 -1
  31. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.tsx +303 -0
  32. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/index.tsx +737 -0
  33. package/src/components/DBEntryManagerPanel/helpers/generateEndpointPath.ts +16 -0
  34. package/src/components/DBEntryManagerPanel/index.tsx +522 -0
  35. package/src/components/DBEntryManagerPanel/types/DBEntry.ts +7 -0
  36. package/src/components/DBEntryManagerPanel/types/DBEntryField.ts +94 -0
  37. package/src/components/DBEntryManagerPanel/types/DBEntryFieldType.ts +18 -0
  38. package/src/components/ItemPicker/index.test.tsx +10 -10
  39. package/src/helpers/addDBEditorEndpoints.ts +128 -0
  40. package/src/helpers/canReviewLogs.ts +0 -20
  41. package/src/helpers/genCSV.ts +2 -5
  42. package/src/helpers/{getOrdinal.ts → getOrdinal.tsx} +0 -1
  43. package/src/index.ts +11 -9
  44. package/tsconfig.json +2 -6
  45. package/dist/cjs/types/helpers/abbreviate.test.d.ts +0 -5
  46. package/dist/cjs/types/helpers/avg.test.d.ts +0 -5
  47. package/dist/cjs/types/helpers/canReviewLogs.test.d.ts +0 -5
  48. package/dist/cjs/types/helpers/ceilToNumDecimals.test.d.ts +0 -5
  49. package/dist/cjs/types/helpers/compareArraysByProp.test.d.ts +0 -5
  50. package/dist/cjs/types/helpers/extractProp.test.d.ts +0 -5
  51. package/dist/cjs/types/helpers/floorToNumDecimals.test.d.ts +0 -5
  52. package/dist/cjs/types/helpers/forceNumIntoBounds.test.d.ts +0 -5
  53. package/dist/cjs/types/helpers/genCSV.test.d.ts +0 -5
  54. package/dist/cjs/types/helpers/genCommaList.d.ts +0 -12
  55. package/dist/cjs/types/helpers/genCommaList.test.d.ts +0 -1
  56. package/dist/cjs/types/helpers/getHumanReadableDate.test.d.ts +0 -5
  57. package/dist/cjs/types/helpers/getLocalTimeInfo.test.d.ts +0 -6
  58. package/dist/cjs/types/helpers/getMonthName.test.d.ts +0 -5
  59. package/dist/cjs/types/helpers/getOrdinal.test.d.ts +0 -5
  60. package/dist/cjs/types/helpers/getPartOfDay.test.d.ts +0 -5
  61. package/dist/cjs/types/helpers/getTimeInfoInET.test.d.ts +0 -5
  62. package/dist/cjs/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +0 -10
  63. package/dist/cjs/types/helpers/validators/shared/helpers/validateRegex.d.ts +0 -19
  64. package/dist/cjs/types/helpers/validators/shared/types/ValidationResult.d.ts +0 -12
  65. package/dist/cjs/types/helpers/validators/validateEmail.d.ts +0 -11
  66. package/dist/cjs/types/helpers/validators/validateEmail.test.d.ts +0 -1
  67. package/dist/cjs/types/helpers/validators/validatePhoneNumber.d.ts +0 -11
  68. package/dist/cjs/types/helpers/validators/validatePhoneNumber.test.d.ts +0 -1
  69. package/dist/cjs/types/helpers/validators/validateString.d.ts +0 -22
  70. package/dist/cjs/types/helpers/validators/validateString.test.d.ts +0 -1
  71. package/dist/esm/types/helpers/abbreviate.test.d.ts +0 -5
  72. package/dist/esm/types/helpers/avg.test.d.ts +0 -5
  73. package/dist/esm/types/helpers/canReviewLogs.test.d.ts +0 -5
  74. package/dist/esm/types/helpers/ceilToNumDecimals.test.d.ts +0 -5
  75. package/dist/esm/types/helpers/compareArraysByProp.test.d.ts +0 -5
  76. package/dist/esm/types/helpers/extractProp.test.d.ts +0 -5
  77. package/dist/esm/types/helpers/floorToNumDecimals.test.d.ts +0 -5
  78. package/dist/esm/types/helpers/forceNumIntoBounds.test.d.ts +0 -5
  79. package/dist/esm/types/helpers/genCSV.test.d.ts +0 -5
  80. package/dist/esm/types/helpers/genCommaList.d.ts +0 -12
  81. package/dist/esm/types/helpers/genCommaList.test.d.ts +0 -1
  82. package/dist/esm/types/helpers/getHumanReadableDate.test.d.ts +0 -5
  83. package/dist/esm/types/helpers/getLocalTimeInfo.test.d.ts +0 -6
  84. package/dist/esm/types/helpers/getMonthName.test.d.ts +0 -5
  85. package/dist/esm/types/helpers/getOrdinal.test.d.ts +0 -5
  86. package/dist/esm/types/helpers/getPartOfDay.test.d.ts +0 -5
  87. package/dist/esm/types/helpers/getTimeInfoInET.test.d.ts +0 -5
  88. package/dist/esm/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +0 -10
  89. package/dist/esm/types/helpers/validators/shared/helpers/validateRegex.d.ts +0 -19
  90. package/dist/esm/types/helpers/validators/shared/types/ValidationResult.d.ts +0 -12
  91. package/dist/esm/types/helpers/validators/validateEmail.d.ts +0 -11
  92. package/dist/esm/types/helpers/validators/validateEmail.test.d.ts +0 -1
  93. package/dist/esm/types/helpers/validators/validatePhoneNumber.d.ts +0 -11
  94. package/dist/esm/types/helpers/validators/validatePhoneNumber.test.d.ts +0 -1
  95. package/dist/esm/types/helpers/validators/validateString.d.ts +0 -22
  96. package/dist/esm/types/helpers/validators/validateString.test.d.ts +0 -1
  97. package/src/helpers/abbreviate.test.ts +0 -26
  98. package/src/helpers/avg.test.ts +0 -24
  99. package/src/helpers/canReviewLogs.test.ts +0 -67
  100. package/src/helpers/ceilToNumDecimals.test.ts +0 -39
  101. package/src/helpers/compareArraysByProp.test.ts +0 -102
  102. package/src/helpers/extractProp.test.ts +0 -34
  103. package/src/helpers/floorToNumDecimals.test.ts +0 -39
  104. package/src/helpers/forceNumIntoBounds.test.ts +0 -34
  105. package/src/helpers/genCSV.test.ts +0 -61
  106. package/src/helpers/genCommaList.test.ts +0 -57
  107. package/src/helpers/genCommaList.ts +0 -21
  108. package/src/helpers/getHumanReadableDate.test.ts +0 -29
  109. package/src/helpers/getLocalTimeInfo.test.ts +0 -48
  110. package/src/helpers/getMonthName.test.ts +0 -79
  111. package/src/helpers/getOrdinal.test.ts +0 -84
  112. package/src/helpers/getPartOfDay.test.ts +0 -56
  113. package/src/helpers/getTimeInfoInET.test.ts +0 -72
  114. package/src/helpers/validators/shared/constants/ERROR_MESSAGES.ts +0 -18
  115. package/src/helpers/validators/shared/helpers/validateRegex.ts +0 -47
  116. package/src/helpers/validators/shared/types/ValidationResult.ts +0 -20
  117. package/src/helpers/validators/validateEmail.test.ts +0 -110
  118. package/src/helpers/validators/validateEmail.ts +0 -47
  119. package/src/helpers/validators/validatePhoneNumber.test.ts +0 -94
  120. package/src/helpers/validators/validatePhoneNumber.ts +0 -49
  121. package/src/helpers/validators/validateString.test.ts +0 -175
  122. package/src/helpers/validators/validateString.ts +0 -171
  123. /package/src/helpers/{abbreviate.ts → abbreviate.tsx} +0 -0
  124. /package/src/helpers/{avg.ts → avg.tsx} +0 -0
  125. /package/src/helpers/{ceilToNumDecimals.ts → ceilToNumDecimals.tsx} +0 -0
  126. /package/src/helpers/{floorToNumDecimals.ts → floorToNumDecimals.tsx} +0 -0
  127. /package/src/helpers/{forceNumIntoBounds.ts → forceNumIntoBounds.tsx} +0 -0
  128. /package/src/helpers/{getLocalTimeInfo.ts → getLocalTimeInfo.tsx} +0 -0
  129. /package/src/helpers/{getTimeInfoInET.ts → getTimeInfoInET.tsx} +0 -0
@@ -1,6 +0,0 @@
1
- /**
2
- * Test for getLocalTimeInfo helper function
3
- * NOTE: only works if this test is run on a machine in ET
4
- * @author Gabe Abrams
5
- */
6
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Test for getMonthName helper
3
- * @author Gabe Abrams
4
- */
5
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Test file for the getOrdinal helper
3
- * @author Gabe Abrams
4
- */
5
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Test file for the getPartOfDay helper
3
- * @author Gabe Abrams
4
- */
5
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Test file for the getTimeInfoInET helper
3
- * @author Gabe Abrams
4
- */
5
- export {};
@@ -1,10 +0,0 @@
1
- export declare const INVALID_REGEX_ERROR = "input does not follow the requested format";
2
- export declare const INVALID_EMAIL_ERROR = "Please provide a valid email address.";
3
- export declare const INVALID_PHONE_ERROR = "Please provide a valid phone number.";
4
- export declare const INVALID_STRING_ERRORS: {
5
- MIN_LEN: (minLen: number) => string;
6
- MAX_LEN: (maxLen: number) => string;
7
- LETTERS_ONLY: string;
8
- NUMBERS_ONLY: string;
9
- MESSAGE_INTRO: string;
10
- };
@@ -1,19 +0,0 @@
1
- import ValidationResult from '../types/ValidationResult';
2
- /**
3
- * Determines whether a given input string is considered valid based on
4
- * the provided regex.
5
- * @author Austen Money
6
- * @param opts object containing all args
7
- * @param opts.input user-provided input to validate
8
- * @param opts.regex regular expression to check against input
9
- * @param [opts.regexDescription] description of what regexString is checking
10
- * for, used to customize error message
11
- * @returns the unchanged input if valid, or a customized error message if
12
- * invalid
13
- */
14
- declare const validateRegex: (opts: {
15
- input: string;
16
- regex: RegExp;
17
- regexDescription?: string;
18
- }) => ValidationResult<string>;
19
- export default validateRegex;
@@ -1,12 +0,0 @@
1
- /**
2
- * Result of a validation function.
3
- * @author Austen Money
4
- */
5
- type ValidationResult<CleanedValueType> = ({
6
- isValid: true;
7
- cleanedValue: CleanedValueType;
8
- } | {
9
- isValid: false;
10
- errorMessage: string;
11
- });
12
- export default ValidationResult;
@@ -1,11 +0,0 @@
1
- import ValidationResult from './shared/types/ValidationResult';
2
- /**
3
- * Determines whether a given email address is valid.
4
- * @author Austen Money
5
- * @param email email address to validate
6
- * @returns whether email fulfills proper formatting requirements, includes a
7
- * cleaned version of the address without leading or trailing
8
- * whitespace if valid or an error message if invalid.
9
- */
10
- declare const validateEmail: (email: string) => ValidationResult<string>;
11
- export default validateEmail;
@@ -1,11 +0,0 @@
1
- import ValidationResult from './shared/types/ValidationResult';
2
- /**
3
- * Determines whether a given phone number is valid.
4
- * @author Austen Money
5
- * @param phoneNumber phone number to validate
6
- * @returns whether phone number is considered valid - if valid, also returns
7
- * a cleaned version of the number without any formatting. If invalid,
8
- * returns an error message.
9
- */
10
- declare const validatePhoneNumber: (phoneNumber: string) => ValidationResult<string>;
11
- export default validatePhoneNumber;
@@ -1,22 +0,0 @@
1
- import ValidationResult from './shared/types/ValidationResult';
2
- /**
3
- * Determines whether a given input string is considered valid based on
4
- * the provided requirements.
5
- * @author Austen Money
6
- * @param input input string
7
- * @param opts options for validation
8
- * @returns whether input is considered valid according to reqs - if
9
- * valid, returns a cleaned version of input; if invalid, returns
10
- * a string containing error messages describing which requirements
11
- * were not met.
12
- */
13
- declare const validateString: (input: string, opts: {
14
- ignoreWhitespace?: boolean;
15
- minLen?: number;
16
- maxLen?: number;
17
- lettersOnly?: boolean;
18
- numbersOnly?: boolean;
19
- regexTest?: RegExp;
20
- regexDescription?: string;
21
- }) => ValidationResult<string>;
22
- export default validateString;
@@ -1,26 +0,0 @@
1
- /**
2
- * Unit tests for abbreviate helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- import abbreviate from './abbreviate';
7
-
8
- describe('helpers > abbreviate', () => {
9
- it('should return the original text if it is shorter than the maxChars parameter', () => {
10
- const text = 'Hello, world!';
11
- const maxChars = 20;
12
- expect(abbreviate(text, maxChars)).toEqual(text);
13
- });
14
-
15
- it('should abbreviate the text if it is longer than the maxChars parameter', () => {
16
- const text = 'This is a really long string that needs to be abbreviated';
17
- const maxChars = 20;
18
- expect(abbreviate(text, maxChars)).toEqual('This is a really...');
19
- });
20
-
21
- it('should handle leading/trailing whitespace', () => {
22
- const text = ' This is a string with leading/trailing whitespace ';
23
- const maxChars = 20;
24
- expect(abbreviate(text, maxChars)).toEqual('This is a string...');
25
- });
26
- });
@@ -1,24 +0,0 @@
1
- /**
2
- * Unit tests for avg helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- import avg from './avg';
7
-
8
- describe('helpers > avg', () => {
9
- it('should return 0 for an empty array', () => {
10
- expect(avg([])).toEqual(0);
11
- });
12
-
13
- it('should return the correct average for an array of numbers', () => {
14
- expect(avg([1, 2, 3, 4, 5])).toEqual(3);
15
- });
16
-
17
- it('should handle negative numbers', () => {
18
- expect(avg([-1, 0, 1])).toEqual(0);
19
- });
20
-
21
- it('should handle decimal numbers', () => {
22
- expect(avg([1.5, 2.5, 3.5])).toEqual(2.5);
23
- });
24
- });
@@ -1,67 +0,0 @@
1
- /**
2
- * Unit tests for canReviewLogs
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import dce-reactkit
7
- import stubServerEndpoint from './stubServerEndpoint';
8
-
9
- // Import main function
10
- import canReviewLogs, { resetCanReviewCache } from './canReviewLogs';
11
-
12
- // Import shared constants
13
- import LOG_REVIEW_STATUS_ROUTE from '../constants/LOG_REVIEW_STATUS_ROUTE';
14
-
15
- describe('helpers > canReviewLogs', () => {
16
- beforeEach(() => {
17
- // Reset the cache
18
- resetCanReviewCache();
19
- });
20
-
21
- it('should return true if the server returns a truthy value', async () => {
22
- stubServerEndpoint({
23
- method: 'GET',
24
- path: LOG_REVIEW_STATUS_ROUTE,
25
- body: true,
26
- });
27
-
28
- const result = await canReviewLogs();
29
- expect(result).toEqual(true);
30
- });
31
-
32
- it('should return false if the server returns a falsy value', async () => {
33
- stubServerEndpoint({
34
- method: 'GET',
35
- path: LOG_REVIEW_STATUS_ROUTE,
36
- body: false,
37
- });
38
-
39
- const result = await canReviewLogs();
40
- expect(result).toEqual(false);
41
- });
42
-
43
- it('should return false if the server throws an error', async () => {
44
- stubServerEndpoint({
45
- method: 'GET',
46
- path: LOG_REVIEW_STATUS_ROUTE,
47
- errorMessage: 'Server error',
48
- errorCode: 'C500',
49
- });
50
-
51
- const result = await canReviewLogs();
52
- expect(result).toEqual(false);
53
- });
54
-
55
- it('should cache the server response and return it on subsequent calls', async () => {
56
- stubServerEndpoint({
57
- method: 'GET',
58
- path: LOG_REVIEW_STATUS_ROUTE,
59
- body: true,
60
- });
61
-
62
- const result1 = await canReviewLogs();
63
- const result2 = await canReviewLogs();
64
- expect(result1).toEqual(true);
65
- expect(result2).toEqual(true);
66
- });
67
- });
@@ -1,39 +0,0 @@
1
- /**
2
- * Test file for the ceilToNumDecimals helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main function
7
- import ceilToNumDecimals from './ceilToNumDecimals';
8
-
9
- describe('ceilToNumDecimals', () => {
10
- it('should return 0 for 0 with 0 decimals', () => {
11
- const result = ceilToNumDecimals(0, 0);
12
- expect(result).toEqual(0);
13
- });
14
-
15
- it('should return 1 for 1 with 0 decimals', () => {
16
- const result = ceilToNumDecimals(1, 0);
17
- expect(result).toEqual(1);
18
- });
19
-
20
- it('should return 1.24 for 1.234 with 2 decimals', () => {
21
- const result = ceilToNumDecimals(1.234, 2);
22
- expect(result).toEqual(1.24);
23
- });
24
-
25
- it('should return -1.23 for -1.234 with 2 decimals', () => {
26
- const result = ceilToNumDecimals(-1.234, 2);
27
- expect(result).toEqual(-1.23);
28
- });
29
-
30
- it('should return 1234 for 1234 with 0 decimals', () => {
31
- const result = ceilToNumDecimals(1234, 0);
32
- expect(result).toEqual(1234);
33
- });
34
-
35
- it('should return 0.002 for 0.00123 with 3 decimals', () => {
36
- const result = ceilToNumDecimals(0.00123, 3);
37
- expect(result).toEqual(0.002);
38
- });
39
- });
@@ -1,102 +0,0 @@
1
- /**
2
- * Test file for the compareArraysByProp helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main helper
7
- import compareArraysByProp from './compareArraysByProp';
8
-
9
- describe('compareArraysByProp', () => {
10
- it('should return true for two empty arrays', () => {
11
- const result = compareArraysByProp([], [], 'id');
12
- expect(result).toEqual(true);
13
- });
14
-
15
- it('should return true for two arrays with the same objects in the same order', () => {
16
- const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
17
- const b = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
18
- const result = compareArraysByProp(a, b, 'id');
19
- expect(result).toEqual(true);
20
- });
21
-
22
- it('should return true for two arrays with the same objects in a different order', () => {
23
- const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
24
- const b = [{ id: 3, name: 'Charlie' }, { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
25
- const result = compareArraysByProp(a, b, 'id');
26
- expect(result).toEqual(true);
27
- });
28
-
29
- it('should return false for two arrays with different objects', () => {
30
- const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
31
- const b = [{ id: 4, name: 'Dave' }, { id: 5, name: 'Eve' }, { id: 6, name: 'Frank' }];
32
- const result = compareArraysByProp(a, b, 'id');
33
- expect(result).toEqual(false);
34
- });
35
-
36
- it('should return false for two arrays with different objects and some shared objects', () => {
37
- const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
38
- const b = [{ id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }, { id: 4, name: 'Dave' }];
39
- const result = compareArraysByProp(a, b, 'id');
40
- expect(result).toEqual(false);
41
- });
42
-
43
- it('should return true for two arrays with the same objects with multiple properties', () => {
44
- const a = [
45
- { id: 1, name: 'Alice', age: 25 },
46
- { id: 2, name: 'Bob', age: 30 },
47
- { id: 3, name: 'Charlie', age: 35 },
48
- ];
49
- const b = [
50
- { id: 1, name: 'Alice', age: 25 },
51
- { id: 2, name: 'Bob', age: 30 },
52
- { id: 3, name: 'Charlie', age: 35 },
53
- ];
54
- const result = compareArraysByProp(a, b, 'id');
55
- expect(result).toEqual(true);
56
- });
57
-
58
- it('should return true for two arrays with the same objects with multiple properties in a different order', () => {
59
- const a = [
60
- { id: 1, name: 'Alice', age: 25 },
61
- { id: 2, name: 'Bob', age: 30 },
62
- { id: 3, name: 'Charlie', age: 35 },
63
- ];
64
- const b = [
65
- { id: 3, name: 'Charlie', age: 35 },
66
- { id: 1, name: 'Alice', age: 25 },
67
- { id: 2, name: 'Bob', age: 30 },
68
- ];
69
- const result = compareArraysByProp(a, b, 'id');
70
- expect(result).toEqual(true);
71
- });
72
-
73
- it('should return false for two arrays with different objects with multiple properties', () => {
74
- const a = [
75
- { id: 1, name: 'Alice', age: 25 },
76
- { id: 2, name: 'Bob', age: 30 },
77
- { id: 3, name: 'Charlie', age: 35 },
78
- ];
79
- const b = [
80
- { id: 4, name: 'Dave', age: 40 },
81
- { id: 5, name: 'Eve', age: 45 },
82
- { id: 6, name: 'Frank', age: 50 },
83
- ];
84
- const result = compareArraysByProp(a, b, 'id');
85
- expect(result).toEqual(false);
86
- });
87
-
88
- it('should return false for two arrays with different objects with multiple properties and some shared objects', () => {
89
- const a = [
90
- { id: 1, name: 'Alice', age: 25 },
91
- { id: 2, name: 'Bob', age: 30 },
92
- { id: 3, name: 'Charlie', age: 35 },
93
- ];
94
- const b = [
95
- { id: 2, name: 'Bob', age: 30 },
96
- { id: 3, name: 'Charlie', age: 35 },
97
- { id: 4, name: 'Dave', age: 40 },
98
- ];
99
- const result = compareArraysByProp(a, b, 'id');
100
- expect(result).toEqual(false);
101
- });
102
- });
@@ -1,34 +0,0 @@
1
- /**
2
- * Test file for the extractProp helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main helper
7
- import extractProp from './extractProp';
8
-
9
- describe('extractProp', () => {
10
- it('should return an empty array if the input array is empty', () => {
11
- const result = extractProp([], 'age');
12
- expect(result).toEqual([]);
13
- });
14
-
15
- it('should extract the correct property from each object in the array', () => {
16
- const users = [
17
- { name: 'Alice', age: 25 },
18
- { name: 'Bob', age: 30 },
19
- { name: 'Charlie', age: 35 },
20
- ];
21
- const result = extractProp(users, 'age');
22
- expect(result).toEqual([25, 30, 35]);
23
- });
24
-
25
- it('should return undefined for objects that do not have the specified property', () => {
26
- const users = [
27
- { name: 'Alice', age: 25 },
28
- { name: 'Bob' },
29
- { name: 'Charlie', age: 35 },
30
- ];
31
- const result = extractProp(users, 'age');
32
- expect(result).toEqual([25, undefined, 35]);
33
- });
34
- });
@@ -1,39 +0,0 @@
1
- /**
2
- * Test file for the floorToNumDecimals helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main function
7
- import floorToNumDecimals from './floorToNumDecimals';
8
-
9
- describe('floorToNumDecimals', () => {
10
- it('should return 0 for 0 with 0 decimals', () => {
11
- const result = floorToNumDecimals(0, 0);
12
- expect(result).toEqual(0);
13
- });
14
-
15
- it('should return 1 for 1 with 0 decimals', () => {
16
- const result = floorToNumDecimals(1, 0);
17
- expect(result).toEqual(1);
18
- });
19
-
20
- it('should return 1.23 for 1.234 with 2 decimals', () => {
21
- const result = floorToNumDecimals(1.234, 2);
22
- expect(result).toEqual(1.23);
23
- });
24
-
25
- it('should return -1.24 for -1.234 with 2 decimals', () => {
26
- const result = floorToNumDecimals(-1.234, 2);
27
- expect(result).toEqual(-1.24);
28
- });
29
-
30
- it('should return 1234 for 1234 with 0 decimals', () => {
31
- const result = floorToNumDecimals(1234, 0);
32
- expect(result).toEqual(1234);
33
- });
34
-
35
- it('should return 0.001 for 0.00123 with 3 decimals', () => {
36
- const result = floorToNumDecimals(0.00123, 3);
37
- expect(result).toEqual(0.001);
38
- });
39
- });
@@ -1,34 +0,0 @@
1
- /**
2
- * Test file for the forceNumIntoBounds helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main helper
7
- import forceNumIntoBounds from './forceNumIntoBounds';
8
-
9
- describe('forceNumIntoBounds', () => {
10
- it('should return the number if it is within the bounds', () => {
11
- const result = forceNumIntoBounds(5, 0, 10);
12
- expect(result).toEqual(5);
13
- });
14
-
15
- it('should return the minimum bound if the number is less than the minimum', () => {
16
- const result = forceNumIntoBounds(-5, 0, 10);
17
- expect(result).toEqual(0);
18
- });
19
-
20
- it('should return the maximum bound if the number is greater than the maximum', () => {
21
- const result = forceNumIntoBounds(15, 0, 10);
22
- expect(result).toEqual(10);
23
- });
24
-
25
- it('should return the minimum bound if the number is equal to the minimum', () => {
26
- const result = forceNumIntoBounds(0, 0, 10);
27
- expect(result).toEqual(0);
28
- });
29
-
30
- it('should return the maximum bound if the number is equal to the maximum', () => {
31
- const result = forceNumIntoBounds(10, 0, 10);
32
- expect(result).toEqual(10);
33
- });
34
- });
@@ -1,61 +0,0 @@
1
- /**
2
- * Test file for the genCSV helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main helper
7
- import genCSV from './genCSV';
8
-
9
- describe('genCSV', () => {
10
- it('should return an empty string for empty data', () => {
11
- const result = genCSV([], []);
12
- expect(result).toEqual('');
13
- });
14
-
15
- it('should generate a CSV with the correct headers and data', () => {
16
- const columns = [
17
- { title: 'Name', param: 'name' },
18
- { title: 'Age', param: 'age' },
19
- { title: 'Email', param: 'email' },
20
- ];
21
- const data = [
22
- { name: 'Alice', age: 25, email: 'alice@example.com' },
23
- { name: 'Bob', age: 30, email: 'bob@example.com' },
24
- { name: 'Charlie', age: 35, email: 'charlie@example.com' },
25
- ];
26
- const expected = `Name,Age,Email\nAlice,25,alice@example.com\nBob,30,bob@example.com\nCharlie,35,charlie@example.com`;
27
- const result = genCSV(data, columns);
28
- expect(result).toEqual(expected);
29
- });
30
-
31
- it('should handle undefined and null values correctly', () => {
32
- const columns = [
33
- { title: 'Name', param: 'name' },
34
- { title: 'Age', param: 'age' },
35
- { title: 'Email', param: 'email' },
36
- ];
37
- const data = [
38
- { name: 'Alice', age: undefined, email: null },
39
- { name: 'Bob', age: null, email: 'bob@example.com' },
40
- { name: 'Charlie', age: 35, email: undefined },
41
- ];
42
- const expected = `Name,Age,Email\nAlice,,\nBob,,bob@example.com\nCharlie,35,`;
43
- const result = genCSV(data, columns);
44
- expect(result).toEqual(expected);
45
- });
46
-
47
- it('should handle objects in cells correctly', () => {
48
- const columns = [
49
- { title: 'Name', param: 'name' },
50
- { title: 'Data', param: 'data' },
51
- ];
52
- const data = [
53
- { name: 'Alice', data: { foo: 'bar' } },
54
- { name: 'Bob', data: [1, 2, 3] },
55
- { name: 'Charlie', data: null },
56
- ];
57
- const expected = `Name,Data\nAlice,"{""foo"":""bar""}"\nBob,"[1,2,3]"\nCharlie,`;
58
- const result = genCSV(data, columns);
59
- expect(result).toEqual(expected);
60
- });
61
- });
@@ -1,57 +0,0 @@
1
- // Import function
2
- import genCommaList from './genCommaList';
3
-
4
- test(
5
- 'Empty list.',
6
- async () => {
7
- const emptyList: string[] = [];
8
- const emptyListResponse: string = '';
9
-
10
- const result = genCommaList(emptyList);
11
- expect(result).toStrictEqual(emptyListResponse);
12
- },
13
- );
14
-
15
- test(
16
- 'One word list.',
17
- async () => {
18
- const oneList: string[] = ['apples'];
19
- const oneListResponse: string = 'apples';
20
-
21
- const result = genCommaList(oneList);
22
- expect(result).toStrictEqual(oneListResponse);
23
- },
24
- );
25
-
26
- test(
27
- 'Two word list.',
28
- async () => {
29
- const twoList: string[] = ['apples', 'oranges'];
30
- const twoListResponse: string = 'apples and oranges';
31
-
32
- const result = genCommaList(twoList);
33
- expect(result).toStrictEqual(twoListResponse);
34
- },
35
- );
36
-
37
- test(
38
- 'Three word list.',
39
- async () => {
40
- const threeList: string[] = ['apples', 'oranges', 'bananas'];
41
- const threeListResponse: string = 'apples, oranges, and bananas';
42
-
43
- const result = genCommaList(threeList);
44
- expect(result).toStrictEqual(threeListResponse);
45
- },
46
- );
47
-
48
- test(
49
- 'Four word list.',
50
- async () => {
51
- const fourList: string[] = ['apples', 'oranges', 'bananas', 'grapes'];
52
- const fourListResponse: string = 'apples, oranges, bananas, and grapes';
53
-
54
- const result = genCommaList(fourList);
55
- expect(result).toStrictEqual(fourListResponse);
56
- },
57
- );
@@ -1,21 +0,0 @@
1
- /**
2
- * Given an array of strings, create a single comma-separated string that includes
3
- * 'and' as well as an oxford comma.
4
- * Ex: ['apples'] => 'apples'
5
- * Ex: ['apples', 'bananas'] => 'apples and bananas'
6
- * Ex: ['apples', 'bananas', 'grapes'] => 'apples, bananas, and grapes'
7
- * @author Austen Money
8
- * @param list an array of elements to be made into a single comma-separated string.
9
- * @returns a comma-separated string.
10
- */
11
- const genCommaList = (list: string[]): string => {
12
- const { length } = list;
13
-
14
- return (
15
- length < 2
16
- ? list.join('')
17
- : `${list.slice(0, length - 1).join(', ')}${length < 3 ? ' and ' : ', and '}${list[length - 1]}`
18
- );
19
- };
20
-
21
- export default genCommaList;