@applicaster/zapp-react-native-utils 15.0.0-rc.12 → 15.0.0-rc.121

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 (159) hide show
  1. package/README.md +0 -6
  2. package/actionsExecutor/ActionExecutorContext.tsx +3 -6
  3. package/actionsExecutor/feedDecorator.ts +6 -6
  4. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  5. package/adsUtils/index.ts +2 -2
  6. package/analyticsUtils/README.md +1 -1
  7. package/analyticsUtils/analyticsMapper.ts +10 -2
  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/__tests__/utils.test.ts +360 -0
  14. package/appUtils/accessibilityManager/const.ts +4 -0
  15. package/appUtils/accessibilityManager/hooks.ts +20 -13
  16. package/appUtils/accessibilityManager/index.ts +28 -1
  17. package/appUtils/accessibilityManager/utils.ts +59 -8
  18. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  19. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  20. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  21. package/appUtils/contextKeysManager/index.ts +65 -10
  22. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +4 -0
  23. package/appUtils/focusManager/index.ios.ts +59 -3
  24. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  26. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  27. package/appUtils/focusManagerAux/utils/index.ts +21 -5
  28. package/appUtils/focusManagerAux/utils/utils.ios.ts +234 -0
  29. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  30. package/appUtils/localizationsHelper.ts +4 -0
  31. package/appUtils/orientationHelper.ts +2 -4
  32. package/appUtils/platform/platformUtils.ts +117 -18
  33. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  34. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  35. package/appUtils/playerManager/player.ts +4 -0
  36. package/appUtils/playerManager/playerNative.ts +31 -17
  37. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  38. package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
  39. package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
  40. package/arrayUtils/index.ts +5 -0
  41. package/cellUtils/index.ts +32 -0
  42. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  43. package/cloudEventsUtils/index.ts +65 -1
  44. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  45. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  46. package/configurationUtils/index.ts +17 -11
  47. package/dateUtils/__tests__/dayjs.test.ts +330 -0
  48. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  49. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  50. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  51. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  52. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  53. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  54. package/errorUtils/__tests__/invariant.test.ts +112 -0
  55. package/focusManager/aux/index.ts +1 -1
  56. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  57. package/headersUtils/index.ts +2 -1
  58. package/manifestUtils/defaultManifestConfigurations/player.js +115 -11
  59. package/manifestUtils/keys.js +21 -0
  60. package/manifestUtils/platformIsTV.js +13 -0
  61. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  62. package/manifestUtils/tvAction/container/index.js +1 -1
  63. package/navigationUtils/index.ts +15 -5
  64. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  65. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  66. package/numberUtils/index.ts +23 -1
  67. package/package.json +4 -4
  68. package/playerUtils/usePlayerTTS.ts +8 -3
  69. package/pluginUtils/index.ts +4 -0
  70. package/reactHooks/advertising/index.ts +2 -2
  71. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  72. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  73. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  74. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  75. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  76. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  77. package/reactHooks/connection/__tests__/index.test.js +1 -1
  78. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  79. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  80. package/reactHooks/device/useIsTablet.tsx +14 -19
  81. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  82. package/reactHooks/events/index.ts +20 -0
  83. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  84. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  85. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
  86. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  87. package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
  88. package/reactHooks/feed/index.ts +0 -2
  89. package/reactHooks/feed/useBatchLoading.ts +7 -1
  90. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  91. package/reactHooks/feed/useInflatedUrl.ts +44 -18
  92. package/reactHooks/feed/usePipesCacheReset.ts +3 -1
  93. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  94. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  95. package/reactHooks/index.ts +2 -0
  96. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  97. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  98. package/reactHooks/layout/index.ts +1 -1
  99. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  100. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  101. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  102. package/reactHooks/navigation/index.ts +27 -11
  103. package/reactHooks/navigation/useRoute.ts +11 -7
  104. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  105. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  106. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  107. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  108. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  109. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  110. package/reactHooks/resolvers/useComponentResolver.ts +19 -3
  111. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  112. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  113. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  114. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
  115. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  116. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  117. package/reactHooks/state/index.ts +2 -0
  118. package/reactHooks/state/useComponentScreenState.ts +45 -0
  119. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  120. package/reactHooks/state/useRivers.ts +1 -1
  121. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  122. package/reactHooks/usePluginConfiguration.ts +2 -2
  123. package/reactHooks/utils/__tests__/index.test.js +1 -1
  124. package/rectUtils/__tests__/index.test.ts +549 -0
  125. package/rectUtils/index.ts +2 -2
  126. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +161 -0
  127. package/refreshUtils/RefreshCoordinator/index.ts +216 -0
  128. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  129. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  130. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  131. package/screenPickerUtils/index.ts +5 -0
  132. package/screenState/__tests__/index.test.ts +1 -1
  133. package/screenUtils/index.ts +3 -0
  134. package/searchUtils/const.ts +7 -0
  135. package/searchUtils/index.ts +3 -0
  136. package/services/storageServiceSync.web.ts +1 -1
  137. package/stringUtils/index.ts +1 -1
  138. package/testUtils/index.tsx +30 -21
  139. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  140. package/time/__tests__/Timer.test.ts +236 -0
  141. package/typeGuards/__tests__/isString.test.ts +21 -0
  142. package/typeGuards/index.ts +4 -0
  143. package/utils/__tests__/clone.test.ts +158 -0
  144. package/utils/__tests__/mapAccum.test.ts +73 -0
  145. package/utils/__tests__/mergeRight.test.ts +48 -0
  146. package/utils/__tests__/path.test.ts +7 -0
  147. package/utils/__tests__/selectors.test.ts +124 -0
  148. package/utils/clone.ts +7 -0
  149. package/utils/index.ts +22 -1
  150. package/utils/mapAccum.ts +23 -0
  151. package/utils/mergeRight.ts +5 -0
  152. package/utils/path.ts +6 -3
  153. package/utils/pathOr.ts +5 -1
  154. package/utils/selectors.ts +46 -0
  155. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +49 -12
  156. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
  157. package/reactHooks/componentsMap/index.ts +0 -55
  158. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  159. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -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
  });
@@ -155,9 +155,9 @@ export function getMediaItems(entry: ZappEntry): Option<ZappMediaItem[]> {
155
155
 
156
156
  /**
157
157
  * Retrieves the "src" value from a media item in the entry's media group,
158
- * based on a provided key, with fallback logic.
158
+ * based on a provided key, with optional fallback logic.
159
159
  *
160
- * Fallback order:
160
+ * Fallback order (when enabled):
161
161
  * 1. Attempts to find a media item with the specified key (or "image_base" if none provided).
162
162
  * 2. If not found, attempts to find a media item with the key "image_base".
163
163
  * 3. If still not found, falls back to the first available media item.
@@ -166,15 +166,19 @@ export function getMediaItems(entry: ZappEntry): Option<ZappMediaItem[]> {
166
166
  * since empty URIs are invalid in some platforms (e.g., React Native).
167
167
  *
168
168
  * @param {ZappEntry} entry - The entry object containing a media group.
169
- * @param {string[] | unknown} arg - A single-element array containing the key to look up, or any unknown value.
169
+ * @param {string[] | unknown} arg - Can be an array or any other value (treated as empty array).
170
+ * When an array:
171
+ * - First element: The key to look up. If omitted or undefined, defaults to "image_base".
172
+ * - Second element: Boolean to enable/disable fallback logic. If omitted or undefined, defaults to true.
170
173
  * @returns {?string} The "src" URI from the matched media item, or undefined if not found or empty.
171
174
  */
172
175
  export function imageSrcFromMediaItem(
173
176
  entry: ZappEntry,
174
177
  arg: string[] | unknown
175
178
  ): Option<string> {
176
- const args: unknown = R.unless(Array.isArray, Array)(arg || []);
179
+ const args: any = R.unless(Array.isArray, Array)(arg || []);
177
180
  const imageKey: string = args?.[0] || "image_base"; // always a single key in this function
181
+ const fallback: boolean = args?.[1] !== false;
178
182
 
179
183
  const mediaItems = getMediaItems(entry);
180
184
 
@@ -185,14 +189,16 @@ export function imageSrcFromMediaItem(
185
189
  // Try to find the item with the given key
186
190
  let foundItem = mediaItems.find((item) => item.key === imageKey);
187
191
 
188
- // If not found and key was not "image_base", try to find "image_base"
189
- if (!foundItem && imageKey !== "image_base") {
190
- foundItem = mediaItems.find((item) => item.key === "image_base");
191
- }
192
+ if (fallback) {
193
+ // If not found and key was not "image_base", try to find "image_base"
194
+ if (!foundItem && imageKey !== "image_base") {
195
+ foundItem = mediaItems.find((item) => item.key === "image_base");
196
+ }
192
197
 
193
- // If still not found, default to first item
194
- if (!foundItem) {
195
- foundItem = mediaItems[0];
198
+ // If still not found, default to first item
199
+ if (!foundItem) {
200
+ foundItem = mediaItems[0];
201
+ }
196
202
  }
197
203
 
198
204
  const src = foundItem?.src;
@@ -0,0 +1,330 @@
1
+ import { dayjs } from "../index";
2
+ import customParseFormat from "dayjs/plugin/customParseFormat";
3
+
4
+ dayjs.extend(customParseFormat);
5
+
6
+ describe("dayjs", () => {
7
+ describe("basic functionality", () => {
8
+ it("should be defined and be a function", () => {
9
+ expect(dayjs).toBeDefined();
10
+ expect(typeof dayjs).toBe("function");
11
+ });
12
+
13
+ it("should create dayjs object from date string", () => {
14
+ const date = dayjs("2023-01-01");
15
+
16
+ expect(date.isValid()).toBe(true);
17
+ expect(date.year()).toBe(2023);
18
+ expect(date.month()).toBe(0); // January is 0
19
+ expect(date.date()).toBe(1);
20
+ });
21
+
22
+ it("should create dayjs object from timestamp", () => {
23
+ const timestamp = 1672531200000; // 2023-01-01 00:00:00 UTC
24
+ const date = dayjs(timestamp);
25
+
26
+ expect(date.isValid()).toBe(true);
27
+ expect(date.valueOf()).toBe(timestamp);
28
+ });
29
+
30
+ it("should get current date when called without arguments", () => {
31
+ const now = dayjs();
32
+
33
+ expect(now.isValid()).toBe(true);
34
+ expect(now.year()).toBeGreaterThan(2020);
35
+ });
36
+ });
37
+
38
+ describe("utc plugin", () => {
39
+ it("should support UTC conversion", () => {
40
+ const date = dayjs("2023-01-01T12:00:00");
41
+ const utcDate = date.utc();
42
+
43
+ expect(utcDate).toBeDefined();
44
+ expect(utcDate.isValid()).toBe(true);
45
+ });
46
+
47
+ it("should create UTC date", () => {
48
+ const utcDate = dayjs.utc("2023-01-01");
49
+
50
+ expect(utcDate.isValid()).toBe(true);
51
+ expect(utcDate.utcOffset()).toBe(0);
52
+ });
53
+
54
+ it("should handle UTC offset correctly", () => {
55
+ const date = dayjs.utc();
56
+
57
+ expect(date.utcOffset()).toBe(0);
58
+ });
59
+ });
60
+
61
+ describe("timezone plugin", () => {
62
+ it("should support timezone conversion", () => {
63
+ const date = dayjs("2023-01-01T12:00:00");
64
+ const tzDate = date.tz("America/New_York");
65
+
66
+ expect(tzDate).toBeDefined();
67
+ expect(tzDate.isValid()).toBe(true);
68
+ });
69
+
70
+ it("should create date in specific timezone", () => {
71
+ const date = dayjs.tz("2023-01-01", "America/New_York");
72
+
73
+ expect(date.isValid()).toBe(true);
74
+ });
75
+
76
+ it("should handle timezone method", () => {
77
+ const date = dayjs();
78
+
79
+ // Just verify the method exists and doesn't throw
80
+ expect(() => date.tz("UTC")).not.toThrow();
81
+ });
82
+ });
83
+
84
+ describe("isoWeek plugin", () => {
85
+ it("should get ISO week of year", () => {
86
+ const date = dayjs("2023-01-01");
87
+ const isoWeek = date.isoWeek();
88
+
89
+ expect(typeof isoWeek).toBe("number");
90
+ expect(isoWeek).toBeGreaterThan(0);
91
+ expect(isoWeek).toBeLessThanOrEqual(53);
92
+ });
93
+
94
+ it("should get ISO weekday", () => {
95
+ const date = dayjs("2023-01-02"); // Monday
96
+ const isoWeekday = date.isoWeekday();
97
+
98
+ expect(isoWeekday).toBe(1); // Monday is 1 in ISO weekday
99
+ });
100
+
101
+ it("should set ISO week", () => {
102
+ const date = dayjs("2023-01-01");
103
+ const newDate = date.isoWeek(10);
104
+
105
+ expect(newDate.isoWeek()).toBe(10);
106
+ });
107
+ });
108
+
109
+ describe("duration plugin", () => {
110
+ it("should create duration from milliseconds", () => {
111
+ const duration = dayjs.duration(1000);
112
+
113
+ expect(duration.asSeconds()).toBe(1);
114
+ });
115
+
116
+ it("should create duration with object", () => {
117
+ const duration = dayjs.duration({
118
+ hours: 1,
119
+ minutes: 30,
120
+ });
121
+
122
+ expect(duration.asMinutes()).toBe(90);
123
+ });
124
+
125
+ it("should format duration", () => {
126
+ const duration = dayjs.duration(3661, "seconds");
127
+
128
+ expect(duration.hours()).toBe(1);
129
+ expect(duration.minutes()).toBe(1);
130
+ expect(duration.seconds()).toBe(1);
131
+ });
132
+
133
+ it("should add duration to date", () => {
134
+ const date = dayjs("2023-01-01");
135
+ const duration = dayjs.duration(1, "day");
136
+ const newDate = date.add(duration);
137
+
138
+ expect(newDate.date()).toBe(2);
139
+ });
140
+
141
+ it("should subtract duration from date", () => {
142
+ const date = dayjs("2023-01-02");
143
+ const duration = dayjs.duration(1, "day");
144
+ const newDate = date.subtract(duration);
145
+
146
+ expect(newDate.date()).toBe(1);
147
+ });
148
+ });
149
+
150
+ describe("relativeTime plugin", () => {
151
+ it("should get time from now", () => {
152
+ const pastDate = dayjs().subtract(1, "hour");
153
+ const relative = pastDate.fromNow();
154
+
155
+ expect(typeof relative).toBe("string");
156
+ expect(relative).toContain("hour");
157
+ });
158
+
159
+ it("should get time to now", () => {
160
+ const futureDate = dayjs().add(1, "hour");
161
+ const relative = futureDate.toNow();
162
+
163
+ expect(typeof relative).toBe("string");
164
+ expect(relative).toContain("hour");
165
+ });
166
+
167
+ it("should get time from specific date", () => {
168
+ const date1 = dayjs("2023-01-01");
169
+ const date2 = dayjs("2023-01-02");
170
+ const relative = date1.from(date2);
171
+
172
+ expect(typeof relative).toBe("string");
173
+ expect(relative).toContain("day");
174
+ });
175
+
176
+ it("should get time to specific date", () => {
177
+ const date1 = dayjs("2023-01-01");
178
+ const date2 = dayjs("2023-01-02");
179
+ const relative = date2.to(date1);
180
+
181
+ expect(typeof relative).toBe("string");
182
+ expect(relative).toContain("day");
183
+ });
184
+
185
+ it("should handle relative time for minutes", () => {
186
+ const pastDate = dayjs().subtract(30, "minutes");
187
+ const relative = pastDate.fromNow();
188
+
189
+ expect(relative).toContain("minute");
190
+ });
191
+
192
+ it("should handle relative time for days", () => {
193
+ const pastDate = dayjs().subtract(5, "days");
194
+ const relative = pastDate.fromNow();
195
+
196
+ expect(relative).toContain("day");
197
+ });
198
+
199
+ it("should handle relative time for months", () => {
200
+ const pastDate = dayjs().subtract(2, "months");
201
+ const relative = pastDate.fromNow();
202
+
203
+ expect(relative).toContain("month");
204
+ });
205
+
206
+ it("should handle relative time for years", () => {
207
+ const pastDate = dayjs().subtract(2, "years");
208
+ const relative = pastDate.fromNow();
209
+
210
+ expect(relative).toContain("year");
211
+ });
212
+ });
213
+
214
+ describe("custom relativeTime thresholds", () => {
215
+ it("should respect custom threshold configuration", () => {
216
+ // Our custom config has 59 minutes threshold for 'mm'
217
+ const date = dayjs().subtract(45, "minutes");
218
+ const relative = date.fromNow();
219
+
220
+ // Should show minutes, not hours
221
+ expect(relative).toContain("minute");
222
+ });
223
+
224
+ it("should handle edge case at day threshold", () => {
225
+ const date = dayjs().subtract(29, "days");
226
+ const relative = date.fromNow();
227
+
228
+ // With custom threshold of 29 days, should still show days
229
+ expect(relative).toContain("day");
230
+ });
231
+ });
232
+
233
+ describe("date manipulation", () => {
234
+ it("should add time units", () => {
235
+ const date = dayjs("2023-01-01");
236
+
237
+ expect(date.add(1, "day").date()).toBe(2);
238
+ expect(date.add(1, "month").month()).toBe(1);
239
+ expect(date.add(1, "year").year()).toBe(2024);
240
+ });
241
+
242
+ it("should subtract time units", () => {
243
+ const date = dayjs("2023-01-02");
244
+
245
+ expect(date.subtract(1, "day").date()).toBe(1);
246
+ expect(date.subtract(1, "month").month()).toBe(11); // December of previous year
247
+ expect(date.subtract(1, "year").year()).toBe(2022);
248
+ });
249
+
250
+ it("should start of time unit", () => {
251
+ const date = dayjs("2023-06-15T14:30:45");
252
+
253
+ expect(date.startOf("day").hour()).toBe(0);
254
+ expect(date.startOf("month").date()).toBe(1);
255
+ expect(date.startOf("year").month()).toBe(0);
256
+ });
257
+
258
+ it("should end of time unit", () => {
259
+ const date = dayjs("2023-06-15T14:30:45");
260
+
261
+ expect(date.endOf("day").hour()).toBe(23);
262
+ expect(date.endOf("month").date()).toBe(30); // June has 30 days
263
+ expect(date.endOf("year").month()).toBe(11); // December
264
+ });
265
+ });
266
+
267
+ describe("formatting", () => {
268
+ it("should format date", () => {
269
+ const date = dayjs("2023-01-01T12:30:45");
270
+
271
+ expect(date.format("YYYY-MM-DD")).toBe("2023-01-01");
272
+ expect(date.format("YYYY/MM/DD HH:mm:ss")).toContain("2023/01/01");
273
+ });
274
+
275
+ it("should convert to ISO string", () => {
276
+ const date = dayjs("2023-01-01");
277
+ const iso = date.toISOString();
278
+
279
+ expect(iso).toContain("2023-01-01");
280
+ expect(iso).toContain("T");
281
+ expect(iso).toContain("Z");
282
+ });
283
+
284
+ it("should convert to Date object", () => {
285
+ const dayjsDate = dayjs("2023-01-01");
286
+ const jsDate = dayjsDate.toDate();
287
+
288
+ expect(jsDate).toBeInstanceOf(Date);
289
+ expect(jsDate.getFullYear()).toBe(2023);
290
+ });
291
+ });
292
+
293
+ describe("comparison", () => {
294
+ it("should check if date is before another", () => {
295
+ const date1 = dayjs("2023-01-01");
296
+ const date2 = dayjs("2023-01-02");
297
+
298
+ expect(date1.isBefore(date2)).toBe(true);
299
+ expect(date2.isBefore(date1)).toBe(false);
300
+ });
301
+
302
+ it("should check if date is after another", () => {
303
+ const date1 = dayjs("2023-01-01");
304
+ const date2 = dayjs("2023-01-02");
305
+
306
+ expect(date2.isAfter(date1)).toBe(true);
307
+ expect(date1.isAfter(date2)).toBe(false);
308
+ });
309
+
310
+ it("should check if date is same as another", () => {
311
+ const date1 = dayjs("2023-01-01");
312
+ const date2 = dayjs("2023-01-01");
313
+
314
+ expect(date1.isSame(date2)).toBe(true);
315
+ });
316
+ });
317
+
318
+ describe("validation", () => {
319
+ it("should validate valid dates", () => {
320
+ expect(dayjs("2023-01-01").isValid()).toBe(true);
321
+ expect(dayjs(new Date()).isValid()).toBe(true);
322
+ expect(dayjs(Date.now()).isValid()).toBe(true);
323
+ });
324
+
325
+ it("should detect invalid dates", () => {
326
+ expect(dayjs("invalid").isValid()).toBe(false);
327
+ expect(dayjs("2023-13-01", "YYYY-MM-DD", true).isValid()).toBe(false);
328
+ });
329
+ });
330
+ });