@applicaster/zapp-react-native-utils 15.1.0-rc.1 → 16.0.0-alpha.9803580571

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 (144) hide show
  1. package/README.md +0 -6
  2. package/actionUtils/index.ts +7 -0
  3. package/actionsExecutor/ActionExecutorContext.tsx +43 -12
  4. package/actionsExecutor/feedDecorator.ts +6 -6
  5. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  6. package/adsUtils/index.ts +2 -2
  7. package/analyticsUtils/README.md +1 -1
  8. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  9. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  10. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  11. package/appUtils/HooksManager/index.ts +10 -10
  12. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  13. package/appUtils/accessibilityManager/const.ts +4 -0
  14. package/appUtils/accessibilityManager/utils.ts +0 -1
  15. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  16. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  17. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  18. package/appUtils/contextKeysManager/index.ts +65 -10
  19. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
  20. package/appUtils/focusManager/index.ios.ts +43 -4
  21. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  22. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  23. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  24. package/appUtils/focusManagerAux/utils/index.ts +11 -3
  25. package/appUtils/focusManagerAux/utils/utils.ios.ts +202 -3
  26. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  27. package/appUtils/orientationHelper.ts +2 -4
  28. package/appUtils/platform/platformUtils.ts +1 -1
  29. package/appUtils/playerManager/player.ts +4 -0
  30. package/appUtils/playerManager/playerNative.ts +30 -21
  31. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  32. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  33. package/cloudEventsUtils/index.ts +65 -1
  34. package/componentsUtils/index.ts +8 -0
  35. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  36. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  37. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  38. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  39. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  40. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  41. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  42. package/errorUtils/__tests__/invariant.test.ts +112 -0
  43. package/focusManager/aux/index.ts +1 -1
  44. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  45. package/headersUtils/index.ts +2 -1
  46. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  47. package/manifestUtils/_internals/index.js +33 -0
  48. package/manifestUtils/defaultManifestConfigurations/player.js +59 -1
  49. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  50. package/manifestUtils/fieldUtils/index.js +54 -0
  51. package/manifestUtils/index.js +2 -0
  52. package/manifestUtils/keys.js +228 -0
  53. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  54. package/manifestUtils/mobileAction/button/index.js +140 -0
  55. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  56. package/manifestUtils/mobileAction/container/index.js +73 -0
  57. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  58. package/manifestUtils/mobileAction/groups/defaults.js +76 -0
  59. package/manifestUtils/mobileAction/groups/index.js +80 -0
  60. package/manifestUtils/tvAction/container/index.js +1 -1
  61. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  62. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  63. package/numberUtils/index.ts +23 -1
  64. package/package.json +4 -4
  65. package/pluginUtils/index.ts +4 -0
  66. package/reactHooks/advertising/index.ts +2 -2
  67. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  68. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  69. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  70. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  71. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  72. package/reactHooks/cell-click/index.ts +2 -1
  73. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  74. package/reactHooks/connection/__tests__/index.test.js +1 -1
  75. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  76. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  77. package/reactHooks/device/useIsTablet.tsx +14 -19
  78. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  79. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  80. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  81. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
  82. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  83. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +1 -1
  84. package/reactHooks/feed/index.ts +0 -2
  85. package/reactHooks/feed/useBatchLoading.ts +7 -1
  86. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  87. package/reactHooks/feed/usePipesCacheReset.ts +3 -1
  88. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  89. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  90. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  91. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  92. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  93. package/reactHooks/navigation/__tests__/index.test.tsx +2 -4
  94. package/reactHooks/navigation/index.ts +7 -6
  95. package/reactHooks/navigation/useRoute.ts +8 -6
  96. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  97. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  98. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  99. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  100. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  101. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  102. package/reactHooks/resolvers/useComponentResolver.ts +8 -2
  103. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  104. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  105. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  106. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
  107. package/reactHooks/screen/index.ts +0 -2
  108. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  109. package/reactHooks/state/useRivers.ts +1 -1
  110. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  111. package/reactHooks/usePluginConfiguration.ts +2 -2
  112. package/reactHooks/utils/__tests__/index.test.js +1 -1
  113. package/rectUtils/__tests__/index.test.ts +549 -0
  114. package/rectUtils/index.ts +2 -2
  115. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +206 -0
  116. package/refreshUtils/RefreshCoordinator/index.ts +245 -0
  117. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  118. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  119. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  120. package/screenState/__tests__/index.test.ts +1 -1
  121. package/screenUtils/index.ts +3 -0
  122. package/searchUtils/const.ts +7 -0
  123. package/searchUtils/index.ts +3 -0
  124. package/stringUtils/index.ts +1 -1
  125. package/testUtils/index.tsx +30 -21
  126. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  127. package/time/__tests__/Timer.test.ts +236 -0
  128. package/typeGuards/__tests__/isString.test.ts +21 -0
  129. package/typeGuards/index.ts +4 -0
  130. package/utils/__tests__/mergeRight.test.ts +48 -0
  131. package/utils/__tests__/path.test.ts +7 -0
  132. package/utils/__tests__/selectors.test.ts +124 -0
  133. package/utils/index.ts +13 -0
  134. package/utils/mergeRight.ts +5 -0
  135. package/utils/path.ts +6 -3
  136. package/utils/pathOr.ts +5 -1
  137. package/utils/selectors.ts +46 -0
  138. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +1 -1
  139. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
  140. package/zappFrameworkUtils/loginPluginUtils.ts +1 -1
  141. package/reactHooks/componentsMap/index.ts +0 -55
  142. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  143. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
  144. package/reactHooks/screen/useIsStandaloneFullscreen.ts +0 -12
@@ -50,7 +50,7 @@ describe("getAllSpecificStyles", () => {
50
50
  });
51
51
 
52
52
  expect(outStyles).toHaveProperty("default");
53
- expect(outStyles["default"]).toEqual({});
53
+ expect(outStyles.default).toEqual({});
54
54
  });
55
55
 
56
56
  it("should handle empty configuration", () => {
@@ -83,7 +83,7 @@ describe("getAllSpecificStyles", () => {
83
83
  outStyles,
84
84
  });
85
85
 
86
- expect(outStyles["default"]).toEqual({
86
+ expect(outStyles.default).toEqual({
87
87
  backgroundColor: "#FF0000",
88
88
  borderWidth: 2,
89
89
  });
@@ -104,7 +104,7 @@ describe("getAllSpecificStyles", () => {
104
104
  outStyles,
105
105
  });
106
106
 
107
- expect(outStyles["default"]).toEqual({
107
+ expect(outStyles.default).toEqual({
108
108
  backgroundColor: "#FF0000",
109
109
  textSize: 16,
110
110
  });
@@ -126,7 +126,7 @@ describe("getAllSpecificStyles", () => {
126
126
  outStyles,
127
127
  });
128
128
 
129
- expect(outStyles["default"]).toEqual({
129
+ expect(outStyles.default).toEqual({
130
130
  backgroundColor: "#FF0000",
131
131
  });
132
132
  });
@@ -148,11 +148,11 @@ describe("getAllSpecificStyles", () => {
148
148
  outStyles,
149
149
  });
150
150
 
151
- expect(outStyles["default"]).toEqual({
151
+ expect(outStyles.default).toEqual({
152
152
  backgroundColor: "#FF0000",
153
153
  });
154
154
 
155
- expect(outStyles["pressed"]).toEqual({
155
+ expect(outStyles.pressed).toEqual({
156
156
  backgroundColor: "#00FF00",
157
157
  });
158
158
  });
@@ -171,7 +171,7 @@ describe("getAllSpecificStyles", () => {
171
171
  outStyles,
172
172
  });
173
173
 
174
- expect(outStyles["focused"]).toEqual({
174
+ expect(outStyles.focused).toEqual({
175
175
  borderWidth: 3,
176
176
  });
177
177
  });
@@ -190,7 +190,7 @@ describe("getAllSpecificStyles", () => {
190
190
  outStyles,
191
191
  });
192
192
 
193
- expect(outStyles["selected"]).toEqual({
193
+ expect(outStyles.selected).toEqual({
194
194
  opacity: 0.5,
195
195
  });
196
196
  });
@@ -209,7 +209,7 @@ describe("getAllSpecificStyles", () => {
209
209
  outStyles,
210
210
  });
211
211
 
212
- expect(outStyles["focused_selected"]).toEqual({
212
+ expect(outStyles.focused_selected).toEqual({
213
213
  scale: 1.2,
214
214
  });
215
215
  });
@@ -232,21 +232,21 @@ describe("getAllSpecificStyles", () => {
232
232
  outStyles,
233
233
  });
234
234
 
235
- expect(outStyles["default"]).toEqual({
235
+ expect(outStyles.default).toEqual({
236
236
  backgroundColor: "#FF0000",
237
237
  borderWidth: 1,
238
238
  opacity: 1,
239
239
  });
240
240
 
241
241
  // Pressed should have default styles merged with its specific override
242
- expect(outStyles["pressed"]).toEqual({
242
+ expect(outStyles.pressed).toEqual({
243
243
  backgroundColor: "#00FF00", // Override
244
244
  borderWidth: 1, // From default
245
245
  opacity: 1, // From default
246
246
  });
247
247
 
248
248
  // Focused should have default styles merged with its specific override
249
- expect(outStyles["focused"]).toEqual({
249
+ expect(outStyles.focused).toEqual({
250
250
  backgroundColor: "#FF0000", // From default
251
251
  borderWidth: 1, // From default
252
252
  opacity: 0.8, // Override
@@ -270,7 +270,7 @@ describe("getAllSpecificStyles", () => {
270
270
  outStyles,
271
271
  });
272
272
 
273
- expect(outStyles["pressed"]).toEqual({
273
+ expect(outStyles.pressed).toEqual({
274
274
  existingKey: "existingValue", // Should be preserved
275
275
  backgroundColor: "#FF0000", // From default
276
276
  textColor: "#FFFFFF", // New pressed style
@@ -294,7 +294,7 @@ describe("getAllSpecificStyles", () => {
294
294
  outStyles,
295
295
  });
296
296
 
297
- expect(outStyles["default"]).toEqual({
297
+ expect(outStyles.default).toEqual({
298
298
  backgroundColor: "#FF0000", // Samsung-specific should be included
299
299
  });
300
300
  });
@@ -317,7 +317,7 @@ describe("getAllSpecificStyles", () => {
317
317
  outStyles,
318
318
  });
319
319
 
320
- expect(outStyles["default"]).toEqual({
320
+ expect(outStyles.default).toEqual({
321
321
  backgroundColor: "#FFFFFF", // Only non-platform specific
322
322
  });
323
323
  });
@@ -336,7 +336,7 @@ describe("getAllSpecificStyles", () => {
336
336
  outStyles,
337
337
  });
338
338
 
339
- expect(outStyles["default"]).toEqual({
339
+ expect(outStyles.default).toEqual({
340
340
  color: "#FF0000",
341
341
  });
342
342
  });
@@ -356,7 +356,7 @@ describe("getAllSpecificStyles", () => {
356
356
  outStyles,
357
357
  });
358
358
 
359
- expect(outStyles["pressed"]).toEqual({
359
+ expect(outStyles.pressed).toEqual({
360
360
  backgroundColor: "#FF0000", // Only samsung style
361
361
  });
362
362
  });
@@ -377,7 +377,7 @@ describe("getAllSpecificStyles", () => {
377
377
  outStyles,
378
378
  });
379
379
 
380
- expect(outStyles["default"]).toEqual({
380
+ expect(outStyles.default).toEqual({
381
381
  backgroundColor: "#00FF00", // Samsung-specific should win
382
382
  });
383
383
  });
@@ -412,14 +412,14 @@ describe("getAllSpecificStyles", () => {
412
412
  outStyles,
413
413
  });
414
414
 
415
- expect(outStyles["default"]).toEqual({
415
+ expect(outStyles.default).toEqual({
416
416
  backgroundColor: "#FFFFFF",
417
417
  textColor: "#000000",
418
418
  borderWidth: 1,
419
419
  padding: 10,
420
420
  });
421
421
 
422
- expect(outStyles["pressed"]).toEqual({
422
+ expect(outStyles.pressed).toEqual({
423
423
  backgroundColor: "#EEEEEE",
424
424
  textColor: "#000000",
425
425
  borderWidth: 1,
@@ -427,7 +427,7 @@ describe("getAllSpecificStyles", () => {
427
427
  opacity: 0.8,
428
428
  });
429
429
 
430
- expect(outStyles["focused"]).toEqual({
430
+ expect(outStyles.focused).toEqual({
431
431
  backgroundColor: "#FFFFFF",
432
432
  textColor: "#000000",
433
433
  borderWidth: 1,
@@ -453,7 +453,7 @@ describe("getAllSpecificStyles", () => {
453
453
  outStyles,
454
454
  });
455
455
 
456
- expect(outStyles["default"]).toEqual({
456
+ expect(outStyles.default).toEqual({
457
457
  validKey: "included",
458
458
  });
459
459
  });
@@ -474,11 +474,11 @@ describe("getAllSpecificStyles", () => {
474
474
  outStyles,
475
475
  });
476
476
 
477
- expect(outStyles["focused_selected"]).toEqual({
477
+ expect(outStyles.focused_selected).toEqual({
478
478
  test: "focused_selected_value",
479
479
  });
480
480
 
481
- expect(outStyles["focused"]).toEqual({
481
+ expect(outStyles.focused).toEqual({
482
482
  another: "focused_value",
483
483
  });
484
484
  });
@@ -517,7 +517,7 @@ describe("getAllSpecificStyles", () => {
517
517
  outStyles,
518
518
  });
519
519
 
520
- expect(outStyles["pressed"]["backgroundColor"]).toBe("#222222");
520
+ expect(outStyles.pressed.backgroundColor).toBe("#222222");
521
521
  });
522
522
 
523
523
  it("should handle frozen outStyles properties", () => {
@@ -537,7 +537,7 @@ describe("getAllSpecificStyles", () => {
537
537
  });
538
538
 
539
539
  // Should create new object instead of mutating frozen one
540
- expect(outStyles["default"]).toEqual({
540
+ expect(outStyles.default).toEqual({
541
541
  existingProp: "value",
542
542
  backgroundColor: "#FF0000",
543
543
  });
@@ -0,0 +1,207 @@
1
+ import { getEnumKeyByEnumValue } from "../index";
2
+
3
+ describe("getEnumKeyByEnumValue", () => {
4
+ enum TestEnum {
5
+ First = "FIRST",
6
+ Second = "SECOND",
7
+ Third = "THIRD",
8
+ }
9
+
10
+ enum NumericEnum {
11
+ Zero = 0,
12
+ One = 1,
13
+ Two = 2,
14
+ Three = 3,
15
+ }
16
+
17
+ enum MixedEnum {
18
+ StringValue = "string",
19
+ NumericValue = 42,
20
+ BooleanValue = "true",
21
+ }
22
+
23
+ describe("string enums", () => {
24
+ it("should return key for valid enum value", () => {
25
+ expect(getEnumKeyByEnumValue(TestEnum, "FIRST")).toBe("First");
26
+ expect(getEnumKeyByEnumValue(TestEnum, "SECOND")).toBe("Second");
27
+ expect(getEnumKeyByEnumValue(TestEnum, "THIRD")).toBe("Third");
28
+ });
29
+
30
+ it("should return null for invalid enum value", () => {
31
+ expect(getEnumKeyByEnumValue(TestEnum, "INVALID")).toBeNull();
32
+ expect(getEnumKeyByEnumValue(TestEnum, "")).toBeNull();
33
+ expect(getEnumKeyByEnumValue(TestEnum, "first")).toBeNull();
34
+ });
35
+
36
+ it("should be case-sensitive", () => {
37
+ expect(getEnumKeyByEnumValue(TestEnum, "first")).toBeNull();
38
+ expect(getEnumKeyByEnumValue(TestEnum, "FIRST")).toBe("First");
39
+ });
40
+ });
41
+
42
+ describe("numeric enums", () => {
43
+ it("should return key for valid numeric enum value", () => {
44
+ expect(getEnumKeyByEnumValue(NumericEnum, 0)).toBe("Zero");
45
+ expect(getEnumKeyByEnumValue(NumericEnum, 1)).toBe("One");
46
+ expect(getEnumKeyByEnumValue(NumericEnum, 2)).toBe("Two");
47
+ expect(getEnumKeyByEnumValue(NumericEnum, 3)).toBe("Three");
48
+ });
49
+
50
+ it("should return null for invalid numeric value", () => {
51
+ expect(getEnumKeyByEnumValue(NumericEnum, 4)).toBeNull();
52
+ expect(getEnumKeyByEnumValue(NumericEnum, -1)).toBeNull();
53
+ expect(getEnumKeyByEnumValue(NumericEnum, 999)).toBeNull();
54
+ });
55
+
56
+ it("should handle numeric strings", () => {
57
+ // When passing string "0", it won't match numeric enum value 0
58
+ expect(getEnumKeyByEnumValue(NumericEnum, "0")).toBeNull();
59
+ });
60
+ });
61
+
62
+ describe("mixed enums", () => {
63
+ it("should handle string values in mixed enum", () => {
64
+ expect(getEnumKeyByEnumValue(MixedEnum, "string")).toBe("StringValue");
65
+ });
66
+
67
+ it("should handle numeric values in mixed enum", () => {
68
+ expect(getEnumKeyByEnumValue(MixedEnum, 42)).toBe("NumericValue");
69
+ });
70
+
71
+ it("should handle boolean-like string values", () => {
72
+ expect(getEnumKeyByEnumValue(MixedEnum, "true")).toBe("BooleanValue");
73
+ });
74
+
75
+ it("should not match boolean to string 'true'", () => {
76
+ expect(getEnumKeyByEnumValue(MixedEnum, true)).toBeNull();
77
+ });
78
+ });
79
+
80
+ describe("edge cases", () => {
81
+ it("should return null for null value", () => {
82
+ expect(getEnumKeyByEnumValue(TestEnum, null)).toBeNull();
83
+ });
84
+
85
+ it("should return null for undefined value", () => {
86
+ expect(getEnumKeyByEnumValue(TestEnum, undefined)).toBeNull();
87
+ });
88
+
89
+ it("should handle empty enum", () => {
90
+ const EmptyEnum = {};
91
+ expect(getEnumKeyByEnumValue(EmptyEnum, "anything")).toBeNull();
92
+ });
93
+
94
+ it("should handle object values", () => {
95
+ expect(getEnumKeyByEnumValue(TestEnum, {})).toBeNull();
96
+ });
97
+
98
+ it("should handle array values", () => {
99
+ expect(getEnumKeyByEnumValue(TestEnum, [])).toBeNull();
100
+ });
101
+
102
+ it("should return first matching key if multiple keys have same value", () => {
103
+ enum DuplicateEnum {
104
+ First = "SAME",
105
+ Second = "SAME",
106
+ }
107
+
108
+ const result = getEnumKeyByEnumValue(DuplicateEnum, "SAME");
109
+ expect(result).toBeTruthy();
110
+ expect(["First", "Second"]).toContain(result);
111
+ });
112
+ });
113
+
114
+ describe("type checking", () => {
115
+ it("should work with const enum-like objects", () => {
116
+ const ConstLikeEnum = {
117
+ KEY_ONE: "value1",
118
+ KEY_TWO: "value2",
119
+ } as const;
120
+
121
+ expect(getEnumKeyByEnumValue(ConstLikeEnum, "value1")).toBe("KEY_ONE");
122
+ expect(getEnumKeyByEnumValue(ConstLikeEnum, "value2")).toBe("KEY_TWO");
123
+ });
124
+
125
+ it("should work with plain objects", () => {
126
+ const plainObject = {
127
+ key1: "val1",
128
+ key2: "val2",
129
+ key3: 123,
130
+ };
131
+
132
+ expect(getEnumKeyByEnumValue(plainObject, "val1")).toBe("key1");
133
+ expect(getEnumKeyByEnumValue(plainObject, 123)).toBe("key3");
134
+ });
135
+
136
+ it("should return correct TypeScript type", () => {
137
+ const result = getEnumKeyByEnumValue(TestEnum, "FIRST");
138
+
139
+ // Result should be keyof TestEnum | null
140
+ if (result !== null) {
141
+ expect(typeof result).toBe("string");
142
+ }
143
+ });
144
+ });
145
+
146
+ describe("special values", () => {
147
+ enum SpecialEnum {
148
+ EmptyString = "",
149
+ Zero = 0,
150
+ False = "false",
151
+ Null = "null",
152
+ }
153
+
154
+ it("should handle empty string value", () => {
155
+ expect(getEnumKeyByEnumValue(SpecialEnum, "")).toBe("EmptyString");
156
+ });
157
+
158
+ it("should handle zero value", () => {
159
+ expect(getEnumKeyByEnumValue(SpecialEnum, 0)).toBe("Zero");
160
+ });
161
+
162
+ it("should handle false-like string", () => {
163
+ expect(getEnumKeyByEnumValue(SpecialEnum, "false")).toBe("False");
164
+ });
165
+
166
+ it("should handle null-like string", () => {
167
+ expect(getEnumKeyByEnumValue(SpecialEnum, "null")).toBe("Null");
168
+ });
169
+ });
170
+
171
+ describe("performance", () => {
172
+ it("should handle large enums efficiently", () => {
173
+ const largeEnum: Record<string, string> = {};
174
+
175
+ for (let i = 0; i < 1000; i++) {
176
+ largeEnum[`Key${i}`] = `Value${i}`;
177
+ }
178
+
179
+ expect(getEnumKeyByEnumValue(largeEnum, "Value500")).toBe("Key500");
180
+ expect(getEnumKeyByEnumValue(largeEnum, "Value999")).toBe("Key999");
181
+ expect(getEnumKeyByEnumValue(largeEnum, "NonExistent")).toBeNull();
182
+ });
183
+ });
184
+
185
+ describe("reverse lookup", () => {
186
+ enum ReverseEnum {
187
+ A = "ValueA",
188
+ B = "ValueB",
189
+ }
190
+
191
+ it("should provide reverse lookup functionality", () => {
192
+ // Forward: get value from key
193
+ expect(ReverseEnum.A).toBe("ValueA");
194
+
195
+ // Reverse: get key from value
196
+ expect(getEnumKeyByEnumValue(ReverseEnum, "ValueA")).toBe("A");
197
+ });
198
+
199
+ it("should be consistent with enum access", () => {
200
+ const key = getEnumKeyByEnumValue(TestEnum, "SECOND");
201
+
202
+ if (key) {
203
+ expect(TestEnum[key]).toBe("SECOND");
204
+ }
205
+ });
206
+ });
207
+ });
@@ -0,0 +1,97 @@
1
+ import { GeneralError } from "../GeneralError";
2
+
3
+ describe("GeneralError", () => {
4
+ it("should create error with message only", () => {
5
+ const message = "Something went wrong";
6
+ const error = new GeneralError(message);
7
+
8
+ expect(error).toBeInstanceOf(Error);
9
+ expect(error).toBeInstanceOf(GeneralError);
10
+ expect(error.message).toBe(message);
11
+ expect(error.statusCode).toBeNull();
12
+ expect(error.localizationKey).toBeNull();
13
+ });
14
+
15
+ it("should create error with message and status code", () => {
16
+ const message = "Not found";
17
+ const statusCode = 404;
18
+ const error = new GeneralError(message, statusCode);
19
+
20
+ expect(error.message).toBe(message);
21
+ expect(error.statusCode).toBe(statusCode);
22
+ expect(error.localizationKey).toBeNull();
23
+ });
24
+
25
+ it("should create error with all parameters", () => {
26
+ const message = "Forbidden";
27
+ const statusCode = 403;
28
+ const localizationKey = "error.forbidden";
29
+ const error = new GeneralError(message, statusCode, localizationKey);
30
+
31
+ expect(error.message).toBe(message);
32
+ expect(error.statusCode).toBe(statusCode);
33
+ expect(error.localizationKey).toBe(localizationKey);
34
+ });
35
+
36
+ it("should create error with null status code explicitly", () => {
37
+ const message = "Error without status";
38
+ const error = new GeneralError(message, null, "error.general");
39
+
40
+ expect(error.message).toBe(message);
41
+ expect(error.statusCode).toBeNull();
42
+ expect(error.localizationKey).toBe("error.general");
43
+ });
44
+
45
+ it("should create error with null localization key explicitly", () => {
46
+ const message = "Server error";
47
+ const statusCode = 500;
48
+ const error = new GeneralError(message, statusCode, null);
49
+
50
+ expect(error.message).toBe(message);
51
+ expect(error.statusCode).toBe(statusCode);
52
+ expect(error.localizationKey).toBeNull();
53
+ });
54
+
55
+ it("should have error name", () => {
56
+ const error = new GeneralError("Test error");
57
+
58
+ expect(error.name).toBe("Error");
59
+ });
60
+
61
+ it("should be throwable and catchable", () => {
62
+ const message = "Test throw";
63
+ const statusCode = 400;
64
+
65
+ expect(() => {
66
+ throw new GeneralError(message, statusCode);
67
+ }).toThrow(GeneralError);
68
+
69
+ try {
70
+ throw new GeneralError(message, statusCode);
71
+ } catch (error) {
72
+ expect(error).toBeInstanceOf(GeneralError);
73
+ expect((error as GeneralError).message).toBe(message);
74
+ expect((error as GeneralError).statusCode).toBe(statusCode);
75
+ }
76
+ });
77
+
78
+ it("should maintain error stack trace", () => {
79
+ const error = new GeneralError("Stack trace test");
80
+
81
+ expect(error.stack).toBeDefined();
82
+ expect(error.stack).toContain("Stack trace test");
83
+ });
84
+
85
+ it("should allow status code to be 0", () => {
86
+ const error = new GeneralError("Zero status", 0);
87
+
88
+ expect(error.statusCode).toBe(0);
89
+ });
90
+
91
+ it("should allow empty string message", () => {
92
+ const error = new GeneralError("");
93
+
94
+ expect(error.message).toBe("");
95
+ expect(error.statusCode).toBeNull();
96
+ });
97
+ });