dce-reactkit 3.5.1-beta.1 → 3.5.2
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.
- package/.eslintrc.js +0 -2
- package/dist/cjs/index.js +319 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/client/initClient.d.ts +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +6 -6
- package/dist/cjs/types/components/ButtonInputGroup.d.ts +1 -1
- package/dist/cjs/types/components/CSVDownloadButton.d.ts +1 -1
- package/dist/cjs/types/components/CheckboxButton.d.ts +1 -1
- package/dist/cjs/types/components/CopiableBox.d.ts +1 -1
- package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +7 -1
- package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +5 -4
- package/dist/cjs/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +1 -1
- package/dist/cjs/types/components/DBEntryManagerPanel/index.d.ts +13 -2
- package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +1 -1
- package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +1 -1
- package/dist/cjs/types/components/Drawer.d.ts +1 -1
- package/dist/cjs/types/components/ErrorBox.d.ts +1 -1
- package/dist/cjs/types/components/IntelliTable.d.ts +1 -1
- package/dist/cjs/types/components/ItemPicker/NestableItemList.d.ts +1 -1
- package/dist/cjs/types/components/ItemPicker/index.d.ts +1 -1
- package/dist/cjs/types/components/ItemPicker/types/PickableItem.d.ts +1 -1
- package/dist/cjs/types/components/LogReviewer.d.ts +1 -1
- package/dist/cjs/types/components/Modal.d.ts +1 -1
- package/dist/cjs/types/components/PopFailureMark.d.ts +1 -1
- package/dist/cjs/types/components/PopPendingMark.d.ts +1 -1
- package/dist/cjs/types/components/PopSuccessMark.d.ts +1 -1
- package/dist/cjs/types/components/RadioButton.d.ts +1 -1
- package/dist/cjs/types/components/SimpleDateChooser.d.ts +1 -1
- package/dist/cjs/types/components/TabBox.d.ts +1 -1
- package/dist/cjs/types/helpers/abbreviate.test.d.ts +5 -0
- package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +4 -3
- package/dist/cjs/types/helpers/avg.test.d.ts +5 -0
- package/dist/cjs/types/helpers/canReviewLogs.d.ts +5 -0
- package/dist/cjs/types/helpers/canReviewLogs.test.d.ts +5 -0
- package/dist/cjs/types/helpers/ceilToNumDecimals.test.d.ts +5 -0
- package/dist/cjs/types/helpers/compareArraysByProp.d.ts +3 -2
- package/dist/cjs/types/helpers/compareArraysByProp.test.d.ts +5 -0
- package/dist/cjs/types/helpers/extractProp.test.d.ts +5 -0
- package/dist/cjs/types/helpers/floorToNumDecimals.test.d.ts +5 -0
- package/dist/cjs/types/helpers/forceNumIntoBounds.test.d.ts +5 -0
- package/dist/cjs/types/helpers/genCSV.test.d.ts +5 -0
- package/dist/cjs/types/helpers/genCommaList.d.ts +12 -0
- package/dist/cjs/types/helpers/genCommaList.test.d.ts +1 -0
- package/dist/cjs/types/helpers/genRouteHandler.d.ts +7 -7
- package/dist/cjs/types/helpers/getHumanReadableDate.d.ts +1 -1
- package/dist/cjs/types/helpers/getHumanReadableDate.test.d.ts +5 -0
- package/dist/cjs/types/helpers/getLocalTimeInfo.d.ts +1 -1
- package/dist/cjs/types/helpers/getLocalTimeInfo.test.d.ts +6 -0
- package/dist/cjs/types/helpers/getMonthName.test.d.ts +5 -0
- package/dist/cjs/types/helpers/getOrdinal.test.d.ts +5 -0
- package/dist/cjs/types/helpers/getPartOfDay.test.d.ts +5 -0
- package/dist/cjs/types/helpers/getTimeInfoInET.d.ts +1 -1
- package/dist/cjs/types/helpers/getTimeInfoInET.test.d.ts +5 -0
- package/dist/cjs/types/helpers/parallelLimit.d.ts +1 -1
- package/dist/cjs/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +10 -0
- package/dist/cjs/types/helpers/validators/shared/helpers/validateRegex.d.ts +19 -0
- package/dist/cjs/types/helpers/validators/shared/types/ValidationResult.d.ts +12 -0
- package/dist/cjs/types/helpers/validators/validateEmail.d.ts +11 -0
- package/dist/cjs/types/helpers/validators/validateEmail.test.d.ts +1 -0
- package/dist/cjs/types/helpers/validators/validatePhoneNumber.d.ts +11 -0
- package/dist/cjs/types/helpers/validators/validatePhoneNumber.test.d.ts +1 -0
- package/dist/cjs/types/helpers/validators/validateString.d.ts +22 -0
- package/dist/cjs/types/helpers/validators/validateString.test.d.ts +1 -0
- package/dist/cjs/types/index.d.ts +5 -1
- package/dist/cjs/types/server/initServer.d.ts +1 -1
- package/dist/cjs/types/types/IntelliTableColumn.d.ts +1 -1
- package/dist/cjs/types/types/Log/LogMainInfo.d.ts +1 -1
- package/dist/cjs/types/types/Log/LogSourceSpecificInfo.d.ts +1 -1
- package/dist/cjs/types/types/Log/LogTypeSpecificInfo.d.ts +1 -1
- package/dist/cjs/types/types/Log/index.d.ts +1 -1
- package/dist/cjs/types/types/LogFunction.d.ts +1 -1
- package/dist/cjs/types/types/LogMetadataContextMap.d.ts +1 -1
- package/dist/cjs/types/types/LogMetadataTagMap.d.ts +1 -1
- package/dist/cjs/types/types/LogMetadataTargetMap.d.ts +1 -1
- package/dist/cjs/types/types/LogMetadataType.d.ts +1 -1
- package/dist/esm/index.js +316 -27
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/client/initClient.d.ts +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +6 -6
- package/dist/esm/types/components/ButtonInputGroup.d.ts +1 -1
- package/dist/esm/types/components/CSVDownloadButton.d.ts +1 -1
- package/dist/esm/types/components/CheckboxButton.d.ts +1 -1
- package/dist/esm/types/components/CopiableBox.d.ts +1 -1
- package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +7 -1
- package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +5 -4
- package/dist/esm/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +1 -1
- package/dist/esm/types/components/DBEntryManagerPanel/index.d.ts +13 -2
- package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +1 -1
- package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +1 -1
- package/dist/esm/types/components/Drawer.d.ts +1 -1
- package/dist/esm/types/components/ErrorBox.d.ts +1 -1
- package/dist/esm/types/components/IntelliTable.d.ts +1 -1
- package/dist/esm/types/components/ItemPicker/NestableItemList.d.ts +1 -1
- package/dist/esm/types/components/ItemPicker/index.d.ts +1 -1
- package/dist/esm/types/components/ItemPicker/types/PickableItem.d.ts +1 -1
- package/dist/esm/types/components/LogReviewer.d.ts +1 -1
- package/dist/esm/types/components/Modal.d.ts +1 -1
- package/dist/esm/types/components/PopFailureMark.d.ts +1 -1
- package/dist/esm/types/components/PopPendingMark.d.ts +1 -1
- package/dist/esm/types/components/PopSuccessMark.d.ts +1 -1
- package/dist/esm/types/components/RadioButton.d.ts +1 -1
- package/dist/esm/types/components/SimpleDateChooser.d.ts +1 -1
- package/dist/esm/types/components/TabBox.d.ts +1 -1
- package/dist/esm/types/helpers/abbreviate.test.d.ts +5 -0
- package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +4 -3
- package/dist/esm/types/helpers/avg.test.d.ts +5 -0
- package/dist/esm/types/helpers/canReviewLogs.d.ts +5 -0
- package/dist/esm/types/helpers/canReviewLogs.test.d.ts +5 -0
- package/dist/esm/types/helpers/ceilToNumDecimals.test.d.ts +5 -0
- package/dist/esm/types/helpers/compareArraysByProp.d.ts +3 -2
- package/dist/esm/types/helpers/compareArraysByProp.test.d.ts +5 -0
- package/dist/esm/types/helpers/extractProp.test.d.ts +5 -0
- package/dist/esm/types/helpers/floorToNumDecimals.test.d.ts +5 -0
- package/dist/esm/types/helpers/forceNumIntoBounds.test.d.ts +5 -0
- package/dist/esm/types/helpers/genCSV.test.d.ts +5 -0
- package/dist/esm/types/helpers/genCommaList.d.ts +12 -0
- package/dist/esm/types/helpers/genCommaList.test.d.ts +1 -0
- package/dist/esm/types/helpers/genRouteHandler.d.ts +7 -7
- package/dist/esm/types/helpers/getHumanReadableDate.d.ts +1 -1
- package/dist/esm/types/helpers/getHumanReadableDate.test.d.ts +5 -0
- package/dist/esm/types/helpers/getLocalTimeInfo.d.ts +1 -1
- package/dist/esm/types/helpers/getLocalTimeInfo.test.d.ts +6 -0
- package/dist/esm/types/helpers/getMonthName.test.d.ts +5 -0
- package/dist/esm/types/helpers/getOrdinal.test.d.ts +5 -0
- package/dist/esm/types/helpers/getPartOfDay.test.d.ts +5 -0
- package/dist/esm/types/helpers/getTimeInfoInET.d.ts +1 -1
- package/dist/esm/types/helpers/getTimeInfoInET.test.d.ts +5 -0
- package/dist/esm/types/helpers/parallelLimit.d.ts +1 -1
- package/dist/esm/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +10 -0
- package/dist/esm/types/helpers/validators/shared/helpers/validateRegex.d.ts +19 -0
- package/dist/esm/types/helpers/validators/shared/types/ValidationResult.d.ts +12 -0
- package/dist/esm/types/helpers/validators/validateEmail.d.ts +11 -0
- package/dist/esm/types/helpers/validators/validateEmail.test.d.ts +1 -0
- package/dist/esm/types/helpers/validators/validatePhoneNumber.d.ts +11 -0
- package/dist/esm/types/helpers/validators/validatePhoneNumber.test.d.ts +1 -0
- package/dist/esm/types/helpers/validators/validateString.d.ts +22 -0
- package/dist/esm/types/helpers/validators/validateString.test.d.ts +1 -0
- package/dist/esm/types/index.d.ts +5 -1
- package/dist/esm/types/server/initServer.d.ts +1 -1
- package/dist/esm/types/types/IntelliTableColumn.d.ts +1 -1
- package/dist/esm/types/types/Log/LogMainInfo.d.ts +1 -1
- package/dist/esm/types/types/Log/LogSourceSpecificInfo.d.ts +1 -1
- package/dist/esm/types/types/Log/LogTypeSpecificInfo.d.ts +1 -1
- package/dist/esm/types/types/Log/index.d.ts +1 -1
- package/dist/esm/types/types/LogFunction.d.ts +1 -1
- package/dist/esm/types/types/LogMetadataContextMap.d.ts +1 -1
- package/dist/esm/types/types/LogMetadataTagMap.d.ts +1 -1
- package/dist/esm/types/types/LogMetadataTargetMap.d.ts +1 -1
- package/dist/esm/types/types/LogMetadataType.d.ts +1 -1
- package/dist/index.d.ts +134 -56
- package/package.json +14 -13
- package/src/components/ItemPicker/index.test.tsx +10 -10
- package/src/helpers/abbreviate.test.ts +26 -0
- package/src/helpers/avg.test.ts +24 -0
- package/src/helpers/canReviewLogs.test.ts +67 -0
- package/src/helpers/canReviewLogs.ts +20 -0
- package/src/helpers/ceilToNumDecimals.test.ts +39 -0
- package/src/helpers/compareArraysByProp.test.ts +102 -0
- package/src/helpers/compareArraysByProp.ts +41 -19
- package/src/helpers/extractProp.test.ts +34 -0
- package/src/helpers/floorToNumDecimals.test.ts +39 -0
- package/src/helpers/forceNumIntoBounds.test.ts +34 -0
- package/src/helpers/genCSV.test.ts +61 -0
- package/src/helpers/genCSV.ts +5 -2
- package/src/helpers/genCommaList.test.ts +57 -0
- package/src/helpers/genCommaList.ts +21 -0
- package/src/helpers/getHumanReadableDate.test.ts +29 -0
- package/src/helpers/getLocalTimeInfo.test.ts +48 -0
- package/src/helpers/getMonthName.test.ts +79 -0
- package/src/helpers/getOrdinal.test.ts +84 -0
- package/src/helpers/{getOrdinal.tsx → getOrdinal.ts} +1 -0
- package/src/helpers/getPartOfDay.test.ts +56 -0
- package/src/helpers/getTimeInfoInET.test.ts +72 -0
- package/src/helpers/validators/shared/constants/ERROR_MESSAGES.ts +18 -0
- package/src/helpers/validators/shared/helpers/validateRegex.ts +47 -0
- package/src/helpers/validators/shared/types/ValidationResult.ts +20 -0
- package/src/helpers/validators/validateEmail.test.ts +110 -0
- package/src/helpers/validators/validateEmail.ts +47 -0
- package/src/helpers/validators/validatePhoneNumber.test.ts +94 -0
- package/src/helpers/validators/validatePhoneNumber.ts +49 -0
- package/src/helpers/validators/validateString.test.ts +175 -0
- package/src/helpers/validators/validateString.ts +171 -0
- package/src/index.ts +8 -0
- package/tsconfig.json +6 -2
- /package/src/helpers/{abbreviate.tsx → abbreviate.ts} +0 -0
- /package/src/helpers/{avg.tsx → avg.ts} +0 -0
- /package/src/helpers/{ceilToNumDecimals.tsx → ceilToNumDecimals.ts} +0 -0
- /package/src/helpers/{floorToNumDecimals.tsx → floorToNumDecimals.ts} +0 -0
- /package/src/helpers/{forceNumIntoBounds.tsx → forceNumIntoBounds.ts} +0 -0
- /package/src/helpers/{getLocalTimeInfo.tsx → getLocalTimeInfo.ts} +0 -0
- /package/src/helpers/{getTimeInfoInET.tsx → getTimeInfoInET.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dce-reactkit",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.2",
|
|
4
4
|
"description": "Shared components for Harvard DCE apps",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rm -rf dist && rollup -c",
|
|
10
|
-
"test": "jest"
|
|
10
|
+
"test": "jest --runInBand"
|
|
11
11
|
},
|
|
12
12
|
"jest": {
|
|
13
13
|
"preset": "ts-jest",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"url": "https://github.com/harvard-edtech/dce-reactkit/issues"
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/harvard-edtech/dce-reactkit#readme",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"react-select": "^5.7.3"
|
|
28
|
+
},
|
|
26
29
|
"peerDependencies": {
|
|
27
30
|
"@fortawesome/free-regular-svg-icons": "^x.x.x",
|
|
28
31
|
"@fortawesome/free-solid-svg-icons": "^x.x.x",
|
|
@@ -38,16 +41,17 @@
|
|
|
38
41
|
"@rollup/plugin-typescript": "^8.3.2",
|
|
39
42
|
"@types/express": "^4.17.17",
|
|
40
43
|
"@types/jest": "^28.1.7",
|
|
44
|
+
"@types/node": "^20.2.5",
|
|
41
45
|
"@types/react": "^17.0.7",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
43
|
-
"@typescript-eslint/parser": "^5.
|
|
44
|
-
"eslint": "^8.
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
47
|
+
"@typescript-eslint/parser": "^5.59.9",
|
|
48
|
+
"eslint": "^8.42.0",
|
|
45
49
|
"eslint-config-airbnb": "^19.0.4",
|
|
46
50
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
47
|
-
"eslint-plugin-import": "^2.
|
|
48
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
49
|
-
"eslint-plugin-react": "^7.
|
|
50
|
-
"eslint-plugin-react-hooks": "^4.
|
|
51
|
+
"eslint-plugin-import": "^2.27.5",
|
|
52
|
+
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
53
|
+
"eslint-plugin-react": "^7.32.2",
|
|
54
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
55
|
"jest": "^28.1.3",
|
|
52
56
|
"jest-environment-jsdom": "^28.1.3",
|
|
53
57
|
"raixa": "^1.0.19",
|
|
@@ -55,9 +59,6 @@
|
|
|
55
59
|
"rollup-plugin-dts": "^4.2.1",
|
|
56
60
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
57
61
|
"ts-jest": "^28.0.8",
|
|
58
|
-
"typescript": "^4.
|
|
59
|
-
},
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"react-select": "^5.7.3"
|
|
62
|
+
"typescript": "^4.9.5"
|
|
62
63
|
}
|
|
63
64
|
}
|
|
@@ -512,7 +512,7 @@ const assertExpectedItemsAreChecked = (
|
|
|
512
512
|
}
|
|
513
513
|
};
|
|
514
514
|
|
|
515
|
-
test(
|
|
515
|
+
test.skip(
|
|
516
516
|
'All Checkboxes appear when initially rendered',
|
|
517
517
|
async () => {
|
|
518
518
|
Raixa.render(
|
|
@@ -530,7 +530,7 @@ test(
|
|
|
530
530
|
},
|
|
531
531
|
);
|
|
532
532
|
|
|
533
|
-
test(
|
|
533
|
+
test.skip(
|
|
534
534
|
'Collapsing item 3 results in only the first 3 items and item 24 showing',
|
|
535
535
|
async () => {
|
|
536
536
|
Raixa.render(
|
|
@@ -555,7 +555,7 @@ test(
|
|
|
555
555
|
},
|
|
556
556
|
);
|
|
557
557
|
|
|
558
|
-
test(
|
|
558
|
+
test.skip(
|
|
559
559
|
'Collapsing item 15 results hides items 16 through 21',
|
|
560
560
|
async () => {
|
|
561
561
|
Raixa.render(
|
|
@@ -580,7 +580,7 @@ test(
|
|
|
580
580
|
},
|
|
581
581
|
);
|
|
582
582
|
|
|
583
|
-
test(
|
|
583
|
+
test.skip(
|
|
584
584
|
'Collapsing item 10 results hides items 11 through 21',
|
|
585
585
|
async () => {
|
|
586
586
|
Raixa.render(
|
|
@@ -605,7 +605,7 @@ test(
|
|
|
605
605
|
},
|
|
606
606
|
);
|
|
607
607
|
|
|
608
|
-
test(
|
|
608
|
+
test.skip(
|
|
609
609
|
'All Checkboxes are unchecked when initially rendered',
|
|
610
610
|
async () => {
|
|
611
611
|
Raixa.render(
|
|
@@ -626,7 +626,7 @@ test(
|
|
|
626
626
|
},
|
|
627
627
|
);
|
|
628
628
|
|
|
629
|
-
test(
|
|
629
|
+
test.skip(
|
|
630
630
|
'Checking item 1 checks items 1',
|
|
631
631
|
async () => {
|
|
632
632
|
let updatedItems: PickableItem[] = [];
|
|
@@ -654,7 +654,7 @@ test(
|
|
|
654
654
|
},
|
|
655
655
|
);
|
|
656
656
|
|
|
657
|
-
test(
|
|
657
|
+
test.skip(
|
|
658
658
|
'Clicking item 1 unchecks items 1',
|
|
659
659
|
async () => {
|
|
660
660
|
let updatedItems: PickableItem[] = [];
|
|
@@ -686,7 +686,7 @@ test(
|
|
|
686
686
|
},
|
|
687
687
|
);
|
|
688
688
|
|
|
689
|
-
test(
|
|
689
|
+
test.skip(
|
|
690
690
|
'Checking item 3 checks items 3 through 23',
|
|
691
691
|
async () => {
|
|
692
692
|
let updatedItems: PickableItem[] = [];
|
|
@@ -720,7 +720,7 @@ test(
|
|
|
720
720
|
},
|
|
721
721
|
);
|
|
722
722
|
|
|
723
|
-
test(
|
|
723
|
+
test.skip(
|
|
724
724
|
'Clicking folder 3 checks unchecks 3 through 23',
|
|
725
725
|
async () => {
|
|
726
726
|
let updatedItems: PickableItem[] = [];
|
|
@@ -750,7 +750,7 @@ test(
|
|
|
750
750
|
},
|
|
751
751
|
);
|
|
752
752
|
|
|
753
|
-
test(
|
|
753
|
+
test.skip(
|
|
754
754
|
'Clicking dashed folder 3 checks 3 through 23',
|
|
755
755
|
async () => {
|
|
756
756
|
let updatedItems: PickableItem[] = [];
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
});
|
|
@@ -4,9 +4,29 @@ import visitServerEndpoint from './visitServerEndpoint';
|
|
|
4
4
|
// Import shared constants
|
|
5
5
|
import LOG_REVIEW_STATUS_ROUTE from '../constants/LOG_REVIEW_STATUS_ROUTE';
|
|
6
6
|
|
|
7
|
+
/*------------------------------------------------------------------------*/
|
|
8
|
+
/* -------------------------------- Cache ------------------------------- */
|
|
9
|
+
/*------------------------------------------------------------------------*/
|
|
10
|
+
|
|
7
11
|
// Cache user's ability
|
|
8
12
|
let canReview: boolean | undefined = undefined;
|
|
9
13
|
|
|
14
|
+
/*------------------------------------------------------------------------*/
|
|
15
|
+
/* ---------------------------- Other Helpers --------------------------- */
|
|
16
|
+
/*------------------------------------------------------------------------*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Reset the cached version of canReview
|
|
20
|
+
* @author Gabe Abrams
|
|
21
|
+
*/
|
|
22
|
+
export const resetCanReviewCache = () => {
|
|
23
|
+
canReview = undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/*------------------------------------------------------------------------*/
|
|
27
|
+
/* -------------------------------- Main -------------------------------- */
|
|
28
|
+
/*------------------------------------------------------------------------*/
|
|
29
|
+
|
|
10
30
|
/**
|
|
11
31
|
* Check if the current user can review logs
|
|
12
32
|
* @author Gabe Abrams
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
});
|
|
@@ -7,31 +7,53 @@ import extractProp from './extractProp';
|
|
|
7
7
|
* @author Gabe Abrams
|
|
8
8
|
* @param a the first array
|
|
9
9
|
* @param b the second array
|
|
10
|
-
* @param prop the property to compare with
|
|
10
|
+
* @param prop the property to compare with, or an array of props to compare
|
|
11
|
+
* with (if array, all values associated with those props must match)
|
|
11
12
|
* @returns true if the arrays contain the same objects as determined by
|
|
12
13
|
* the values associated with each object's prop
|
|
13
14
|
*/
|
|
14
|
-
const compareArraysByProp = (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
if (
|
|
15
|
+
const compareArraysByProp = (
|
|
16
|
+
a: any[],
|
|
17
|
+
b: any[],
|
|
18
|
+
prop: string | string[],
|
|
19
|
+
): boolean => {
|
|
20
|
+
// Immediately return if size of arrays is different
|
|
21
|
+
if (a.length !== b.length) {
|
|
21
22
|
return false;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
// Get all props
|
|
26
|
+
const props = (Array.isArray(prop) ? prop : [prop]);
|
|
27
|
+
|
|
28
|
+
// Clone second array so we can work on it
|
|
29
|
+
const bCloned = [...b];
|
|
30
|
+
|
|
31
|
+
// Remove elements from b as we find them in a
|
|
32
|
+
for (let i = 0; i < a.length; i++) {
|
|
33
|
+
// Find matching element in b
|
|
34
|
+
const matchingIndex = bCloned.findIndex((bItem) => {
|
|
35
|
+
// Compare based on all props
|
|
36
|
+
return props.every((propToCompareBy) => {
|
|
37
|
+
const aVal = extractProp(a[i], propToCompareBy);
|
|
38
|
+
const bVal = extractProp(bItem, propToCompareBy);
|
|
39
|
+
return aVal === bVal;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Check if no match
|
|
44
|
+
const noMatch = (matchingIndex < 0);
|
|
45
|
+
|
|
46
|
+
// If no match, there's no corresponding element in b
|
|
47
|
+
if (noMatch) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Remove the matching element
|
|
52
|
+
bCloned.splice(matchingIndex, 1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If we made it here, all elements in a have a corresponding element in b
|
|
56
|
+
return true;
|
|
35
57
|
};
|
|
36
58
|
|
|
37
59
|
export default compareArraysByProp;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
});
|