@applicaster/zapp-react-native-utils 16.0.0-alpha.7128076344 → 16.0.0-alpha.7354639420

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 (291) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +59 -14
  3. package/actionsExecutor/ActionExecutorContext.tsx +115 -316
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
  6. package/actionsExecutor/__tests__/feedDecorator.test.ts +91 -0
  7. package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
  8. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  9. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  10. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  11. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  12. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
  13. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +100 -0
  14. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +372 -0
  15. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  16. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  17. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  18. package/actionsExecutor/actions/appRestart.ts +24 -0
  19. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  20. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  21. package/actionsExecutor/actions/goBack.ts +60 -0
  22. package/actionsExecutor/actions/goHome.ts +31 -0
  23. package/actionsExecutor/actions/index.ts +42 -0
  24. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  25. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  26. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  27. package/actionsExecutor/actions/navigateToScreen.ts +121 -0
  28. package/actionsExecutor/actions/openBottomSheet.ts +340 -0
  29. package/actionsExecutor/actions/presentScreen.ts +78 -0
  30. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  31. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  32. package/actionsExecutor/actions/screenToggleFlag.ts +36 -0
  33. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  34. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  35. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  36. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  37. package/actionsExecutor/actions/showAlert.ts +51 -0
  38. package/actionsExecutor/actions/showToast.ts +87 -0
  39. package/actionsExecutor/actions/switchLayout.ts +40 -0
  40. package/actionsExecutor/consts.ts +27 -0
  41. package/actionsExecutor/feedDecorator.ts +14 -8
  42. package/actionsExecutor/types.ts +59 -0
  43. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  44. package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
  45. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  46. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  47. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  48. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  49. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  50. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  51. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  52. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  53. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  54. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  55. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  56. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  57. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  58. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  59. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  60. package/analyticsUtils/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
  61. package/analyticsUtils/analyticsMapper.ts +4 -1
  62. package/analyticsUtils/logger.ts +9 -4
  63. package/analyticsUtils/playerAnalyticsTracker.ts +27 -3
  64. package/appUtils/HooksManager/index.ts +15 -17
  65. package/appUtils/HooksManager/logger.ts +5 -2
  66. package/appUtils/accessibilityManager/logger.ts +2 -4
  67. package/appUtils/accessibilityManager/utils.ts +1 -1
  68. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +2 -23
  69. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  70. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  71. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -26
  72. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  73. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  74. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  75. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  76. package/appUtils/contextKeysManager/index.ts +31 -132
  77. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  78. package/appUtils/focusManager/index.ts +2 -2
  79. package/appUtils/focusManager/logger.ts +2 -2
  80. package/appUtils/focusManagerAux/index.ts +2 -2
  81. package/appUtils/orientationHelper.ts +2 -2
  82. package/appUtils/platform/platformUtils.ts +13 -2
  83. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -60
  84. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  85. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  86. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  87. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  88. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  89. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  90. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  91. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  92. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  93. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  94. package/appUtils/playerManager/__tests__/playerFactory.test.ts +150 -0
  95. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  96. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  97. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  98. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  99. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  100. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  101. package/appUtils/playerManager/index.ts +10 -3
  102. package/appUtils/playerManager/player.ts +141 -4
  103. package/appUtils/playerManager/playerFactory.ts +18 -35
  104. package/appUtils/playerManager/playerNative.ts +29 -5
  105. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  106. package/appUtils/playerManager/playerToolbox.ts +196 -0
  107. package/appUtils/playerManager/usePlayNextOverlay.tsx +2 -2
  108. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  109. package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
  110. package/appUtils/playerManager/userCellPlayerMutedPreference.ts +1 -1
  111. package/appUtils/playerManager/userLanguagePreference.ts +2 -2
  112. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  113. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  114. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  115. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  116. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  117. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  118. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  119. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  120. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  121. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  122. package/arrayUtils/__tests__/sample.test.ts +61 -0
  123. package/arrayUtils/index.ts +119 -20
  124. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  125. package/bottomSheet/index.ts +17 -0
  126. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  127. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  128. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  129. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  130. package/cellUtils/index.ts +73 -8
  131. package/cellUtils/logger.ts +2 -2
  132. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  133. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  134. package/colorUtils/index.ts +50 -0
  135. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  136. package/configurationUtils/__tests__/modalBlocksParser.test.ts +403 -0
  137. package/configurationUtils/manifestKeyParser.ts +50 -10
  138. package/configurationUtils/modalBlocksParser.ts +252 -0
  139. package/domUtils/logger.ts +2 -2
  140. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  141. package/entryActions/aliasPresentation.ts +108 -0
  142. package/entryActions/buildEntryActions.ts +167 -0
  143. package/entryActions/index.ts +15 -0
  144. package/entryActions/types.ts +39 -0
  145. package/focusManager/FocusManager.ts +26 -0
  146. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  147. package/focusManager/logger.ts +1 -4
  148. package/headersUtils/index.ts +2 -2
  149. package/localizationUtils/index.ts +12 -6
  150. package/logger/__tests__/subsystems.test.ts +84 -0
  151. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  152. package/logger/index.ts +41 -7
  153. package/logger/subsystems.ts +83 -0
  154. package/logger/xrayToolbox.ts +67 -0
  155. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  156. package/manifestUtils/_internals/index.js +14 -3
  157. package/manifestUtils/defaultManifestConfigurations/generalContent.js +41 -0
  158. package/manifestUtils/defaultManifestConfigurations/player.js +357 -20
  159. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  160. package/manifestUtils/fieldUtils/index.js +125 -0
  161. package/manifestUtils/index.js +3 -0
  162. package/manifestUtils/keys.js +16 -2
  163. package/manifestUtils/mobileAction/button/index.js +16 -0
  164. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  165. package/manifestUtils/mobileAction/container/index.js +3 -1
  166. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  167. package/manifestUtils/mobileAction/groups/defaults.js +5 -2
  168. package/manifestUtils/modalBlocks.js +304 -0
  169. package/manifestUtils/platformIsTV.js +1 -0
  170. package/modalState/ContentViewModel.ts +113 -0
  171. package/modalState/EditableCollection.ts +17 -0
  172. package/modalState/EditableCollectionRegistry.ts +51 -0
  173. package/modalState/ModalOrchestrator.ts +213 -0
  174. package/modalState/RemoteEditableCollection.ts +235 -0
  175. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  176. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  177. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  178. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +86 -0
  179. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  180. package/modalState/__tests__/index.test.ts +30 -1
  181. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  182. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  183. package/modalState/index.ts +37 -83
  184. package/modalState/store.ts +109 -0
  185. package/modalState/types.ts +173 -0
  186. package/modalState/useBottomSheetContent.ts +109 -0
  187. package/navigationUtils/index.ts +5 -2
  188. package/navigationUtils/xrayNavigator.ts +12 -0
  189. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  190. package/numberUtils/__tests__/isZero.test.ts +27 -0
  191. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  192. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  193. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  194. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  195. package/numberUtils/index.ts +29 -10
  196. package/package.json +3 -2
  197. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  198. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  199. package/pipesUtils/index.ts +1 -0
  200. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  201. package/playerUtils/PlayerTTS/PlayerTTS.ts +1 -1
  202. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  203. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  204. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  205. package/playerUtils/contentDataKeys.ts +134 -0
  206. package/playerUtils/imaScriptDom.ts +1 -1
  207. package/playerUtils/index.ts +58 -15
  208. package/playerUtils/isAudioItem.ts +26 -0
  209. package/playerUtils/resolvePlayerActions.ts +71 -0
  210. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  211. package/playerUtils/useValidatePlayerConfig.tsx +1 -1
  212. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  213. package/pluginUtils/index.ts +29 -0
  214. package/pluginUtils/logger.ts +2 -2
  215. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  216. package/quickBrickAssets/index.ts +35 -0
  217. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  218. package/reactHooks/actions/index.ts +124 -3
  219. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  220. package/reactHooks/cell-click/index.ts +39 -24
  221. package/reactHooks/connection/index.tsx +8 -5
  222. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  223. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  224. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  225. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  226. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  227. package/reactHooks/feed/index.ts +5 -1
  228. package/reactHooks/feed/useBatchLoading.ts +9 -1
  229. package/reactHooks/feed/useBuildPipesUrl.ts +5 -2
  230. package/reactHooks/feed/useFeedLoader.tsx +30 -3
  231. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  232. package/reactHooks/feed/useMarkPipesDataStale.ts +97 -0
  233. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +5 -2
  234. package/reactHooks/index.ts +2 -0
  235. package/reactHooks/layout/index.ts +1 -1
  236. package/reactHooks/logger.ts +5 -2
  237. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  238. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  239. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  240. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  241. package/reactHooks/navigation/index.ts +3 -1
  242. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  243. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  244. package/reactHooks/navigation/useRoute.ts +22 -5
  245. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +2 -2
  246. package/reactHooks/screen/__tests__/useIsStandaloneFullscreen.test.ts +114 -0
  247. package/reactHooks/screen/index.ts +2 -0
  248. package/reactHooks/screen/useIsStandaloneFullscreen.ts +12 -0
  249. package/reactHooks/screen/useScreenData.ts +2 -2
  250. package/reactHooks/state/useComponentScreenState.ts +1 -1
  251. package/reactHooks/usePluginConfiguration.ts +88 -47
  252. package/reactHooks/utils/__tests__/index.test.js +22 -2
  253. package/reactHooks/utils/index.ts +13 -2
  254. package/reactHooks/videoModal/hooks/useChangeOrientation.ts +1 -4
  255. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  256. package/reactUtils/createContext/helpers.ts +2 -2
  257. package/reactUtils/logger.ts +2 -2
  258. package/riverComponetsMeasurementProvider/index.tsx +16 -10
  259. package/storage/ScreenSingleValueProvider.ts +1 -1
  260. package/storage/ScreenStateMultiSelectProvider.ts +1 -1
  261. package/storage/StorageMultiSelectProvider.ts +1 -1
  262. package/storage/StorageSingleSelectProvider.ts +1 -1
  263. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  264. package/stringUtils/index.ts +2 -2
  265. package/stylesUtils/logger.ts +2 -2
  266. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  267. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  268. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  269. package/uiActionsRegistrator/index.ts +25 -0
  270. package/uiActionsRegistrator/registry.ts +351 -0
  271. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  272. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  273. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +3 -2
  274. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  275. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  276. package/zappFrameworkUtils/loginPluginUtils.ts +2 -1
  277. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -1
  278. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  279. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  280. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  281. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  282. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  283. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  284. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  285. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
  286. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  287. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  288. package/playerUtils/getPlayerActionButtons.ts +0 -17
  289. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  290. package/reactHooks/feed/usePipesCacheReset.ts +0 -44
  291. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,349 @@
1
+ import { renderHook, act, waitFor } from "@testing-library/react-native";
2
+
3
+ import { modalOrchestrator } from "../ModalOrchestrator";
4
+ import { MenuItem } from "../types";
5
+ import { useBottomSheetContent } from "../useBottomSheetContent";
6
+ import type { ContentState } from "../ContentViewModel";
7
+
8
+ jest.mock("../ModalOrchestrator", () => ({
9
+ isPresentSubMenuAction: jest.requireActual("../types").isPresentSubMenuAction,
10
+ modalOrchestrator: {
11
+ canGoBack: false,
12
+ back: jest.fn(),
13
+ close: jest.fn(),
14
+ },
15
+ }));
16
+
17
+ type MockViewModel = {
18
+ getState: jest.Mock<ContentState, []>;
19
+ subscribe: jest.Mock<(listener: (state: ContentState) => void) => () => void>;
20
+ refetch: jest.Mock<Promise<void>, []>;
21
+ };
22
+
23
+ const createViewModel = (
24
+ initialState: ContentState
25
+ ): MockViewModel & {
26
+ emit: (nextState: ContentState) => void;
27
+ } => {
28
+ let listener: ((state: ContentState) => void) | undefined;
29
+ const unsubscribe = jest.fn();
30
+
31
+ const viewModel: MockViewModel & { emit: (nextState: ContentState) => void } =
32
+ {
33
+ getState: jest.fn(() => initialState),
34
+ subscribe: jest.fn((nextListener) => {
35
+ listener = nextListener;
36
+
37
+ return unsubscribe;
38
+ }),
39
+ refetch: jest.fn().mockResolvedValue(undefined),
40
+ emit: (nextState) => {
41
+ listener?.(nextState);
42
+ },
43
+ };
44
+
45
+ return viewModel;
46
+ };
47
+
48
+ describe("useBottomSheetContent", () => {
49
+ const onPress = jest.fn().mockResolvedValue(undefined);
50
+
51
+ beforeEach(() => {
52
+ jest.clearAllMocks();
53
+ modalOrchestrator.canGoBack = false;
54
+ });
55
+
56
+ it("returns initial state from the view model", () => {
57
+ const viewModel = createViewModel({
58
+ items: [{ title: "Item 1" }],
59
+ isLoading: false,
60
+ });
61
+
62
+ const { result } = renderHook(() =>
63
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
64
+ );
65
+
66
+ expect(result.current.items).toEqual([{ title: "Item 1" }]);
67
+ expect(result.current.isLoading).toBe(false);
68
+ expect(result.current.error).toBeUndefined();
69
+ expect(result.current.showCentralLoading).toBe(false);
70
+ expect(result.current.canGoBack).toBe(false);
71
+ expect(viewModel.subscribe).toHaveBeenCalledTimes(1);
72
+ });
73
+
74
+ it("computes showCentralLoading when loading with no items", () => {
75
+ const viewModel = createViewModel({
76
+ items: [],
77
+ isLoading: true,
78
+ });
79
+
80
+ const { result } = renderHook(() =>
81
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
82
+ );
83
+
84
+ expect(result.current.showCentralLoading).toBe(true);
85
+ });
86
+
87
+ it("does not show central loading when items exist while loading", () => {
88
+ const viewModel = createViewModel({
89
+ items: [{ title: "Item 1" }],
90
+ isLoading: true,
91
+ });
92
+
93
+ const { result } = renderHook(() =>
94
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
95
+ );
96
+
97
+ expect(result.current.showCentralLoading).toBe(false);
98
+ });
99
+
100
+ it("updates when the view model emits new state", () => {
101
+ const viewModel = createViewModel({
102
+ items: [],
103
+ isLoading: true,
104
+ });
105
+
106
+ const { result } = renderHook(() =>
107
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
108
+ );
109
+
110
+ act(() => {
111
+ viewModel.emit({
112
+ items: [{ title: "Fetched Item" }],
113
+ isLoading: false,
114
+ });
115
+ });
116
+
117
+ expect(result.current.items).toEqual([{ title: "Fetched Item" }]);
118
+ expect(result.current.isLoading).toBe(false);
119
+ expect(result.current.showCentralLoading).toBe(false);
120
+ });
121
+
122
+ it("exposes error state from the view model", () => {
123
+ const viewModel = createViewModel({
124
+ items: [],
125
+ isLoading: false,
126
+ error: "Network Error",
127
+ });
128
+
129
+ const { result } = renderHook(() =>
130
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
131
+ );
132
+
133
+ expect(result.current.error).toBe("Network Error");
134
+ });
135
+
136
+ it("unsubscribes from the view model on unmount", () => {
137
+ const viewModel = createViewModel({
138
+ items: [],
139
+ isLoading: false,
140
+ });
141
+
142
+ const { unmount } = renderHook(() =>
143
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
144
+ );
145
+
146
+ const unsubscribeFn = viewModel.subscribe.mock.results[0]
147
+ .value as jest.Mock;
148
+
149
+ unmount();
150
+
151
+ expect(unsubscribeFn).toHaveBeenCalledTimes(1);
152
+ });
153
+
154
+ describe("handleItemPress", () => {
155
+ it("delegates to onPress and refetches for leaf items", async () => {
156
+ const viewModel = createViewModel({
157
+ items: [{ title: "Leaf" }],
158
+ isLoading: false,
159
+ });
160
+
161
+ const item: MenuItem = { title: "Leaf" };
162
+
163
+ const { result } = renderHook(() =>
164
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
165
+ );
166
+
167
+ await act(async () => {
168
+ await result.current.handleItemPress(item);
169
+ });
170
+
171
+ expect(onPress).toHaveBeenCalledWith(item);
172
+ expect(viewModel.refetch).toHaveBeenCalledTimes(1);
173
+ });
174
+
175
+ it("does not refetch when the item opens a present submenu action", async () => {
176
+ const viewModel = createViewModel({
177
+ items: [{ title: "Parent" }],
178
+ isLoading: false,
179
+ });
180
+
181
+ const item: MenuItem = {
182
+ title: "Parent",
183
+ action: {
184
+ type: "presentSubMenu",
185
+ menu: {
186
+ content: {
187
+ title: "Submenu",
188
+ items: [{ title: "Child" }],
189
+ },
190
+ },
191
+ },
192
+ };
193
+
194
+ const { result } = renderHook(() =>
195
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
196
+ );
197
+
198
+ await act(async () => {
199
+ await result.current.handleItemPress(item);
200
+ });
201
+
202
+ expect(onPress).toHaveBeenCalledWith(item);
203
+ expect(viewModel.refetch).not.toHaveBeenCalled();
204
+ });
205
+
206
+ it("awaits onPress before refetching", async () => {
207
+ const viewModel = createViewModel({
208
+ items: [{ title: "Leaf" }],
209
+ isLoading: false,
210
+ });
211
+
212
+ const item: MenuItem = { title: "Leaf" };
213
+ const callOrder: string[] = [];
214
+
215
+ onPress.mockImplementation(async () => {
216
+ callOrder.push("onPress");
217
+ });
218
+
219
+ viewModel.refetch.mockImplementation(async () => {
220
+ callOrder.push("refetch");
221
+ });
222
+
223
+ const { result } = renderHook(() =>
224
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
225
+ );
226
+
227
+ await act(async () => {
228
+ await result.current.handleItemPress(item);
229
+ });
230
+
231
+ expect(callOrder).toEqual(["onPress", "refetch"]);
232
+ });
233
+ });
234
+
235
+ describe("goBackOrClose", () => {
236
+ it("calls back when the orchestrator can go back", () => {
237
+ modalOrchestrator.canGoBack = true;
238
+
239
+ const viewModel = createViewModel({
240
+ items: [],
241
+ isLoading: false,
242
+ });
243
+
244
+ const { result } = renderHook(() =>
245
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
246
+ );
247
+
248
+ act(() => {
249
+ result.current.goBackOrClose();
250
+ });
251
+
252
+ expect(modalOrchestrator.back).toHaveBeenCalledTimes(1);
253
+ expect(modalOrchestrator.close).not.toHaveBeenCalled();
254
+ });
255
+
256
+ it("calls close when the orchestrator cannot go back", () => {
257
+ modalOrchestrator.canGoBack = false;
258
+
259
+ const viewModel = createViewModel({
260
+ items: [],
261
+ isLoading: false,
262
+ });
263
+
264
+ const { result } = renderHook(() =>
265
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
266
+ );
267
+
268
+ act(() => {
269
+ result.current.goBackOrClose();
270
+ });
271
+
272
+ expect(modalOrchestrator.close).toHaveBeenCalledTimes(1);
273
+ expect(modalOrchestrator.back).not.toHaveBeenCalled();
274
+ });
275
+ });
276
+
277
+ it("exposes close from the modal orchestrator", () => {
278
+ const viewModel = createViewModel({
279
+ items: [],
280
+ isLoading: false,
281
+ });
282
+
283
+ const { result } = renderHook(() =>
284
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
285
+ );
286
+
287
+ act(() => {
288
+ result.current.close();
289
+ });
290
+
291
+ expect(modalOrchestrator.close).toHaveBeenCalledTimes(1);
292
+ });
293
+
294
+ it("reflects canGoBack from the modal orchestrator", () => {
295
+ modalOrchestrator.canGoBack = true;
296
+
297
+ const viewModel = createViewModel({
298
+ items: [],
299
+ isLoading: false,
300
+ });
301
+
302
+ const { result } = renderHook(() =>
303
+ useBottomSheetContent({ viewModel: viewModel as any, onPress })
304
+ );
305
+
306
+ expect(result.current.canGoBack).toBe(true);
307
+ });
308
+
309
+ it("resubscribes when the view model instance changes", async () => {
310
+ const firstViewModel = createViewModel({
311
+ items: [{ title: "First" }],
312
+ isLoading: false,
313
+ });
314
+
315
+ const secondViewModel = createViewModel({
316
+ items: [{ title: "Second" }],
317
+ isLoading: false,
318
+ });
319
+
320
+ const { result, rerender } = renderHook(
321
+ ({ viewModel }) =>
322
+ useBottomSheetContent({ viewModel: viewModel as any, onPress }),
323
+ {
324
+ initialProps: { viewModel: firstViewModel },
325
+ }
326
+ );
327
+
328
+ expect(result.current.items).toEqual([{ title: "First" }]);
329
+
330
+ rerender({ viewModel: secondViewModel });
331
+
332
+ expect(
333
+ firstViewModel.subscribe.mock.results[0].value
334
+ ).toHaveBeenCalledTimes(1);
335
+
336
+ expect(secondViewModel.subscribe).toHaveBeenCalledTimes(1);
337
+
338
+ act(() => {
339
+ secondViewModel.emit({
340
+ items: [{ title: "Updated Second" }],
341
+ isLoading: false,
342
+ });
343
+ });
344
+
345
+ await waitFor(() => {
346
+ expect(result.current.items).toEqual([{ title: "Updated Second" }]);
347
+ });
348
+ });
349
+ });
@@ -0,0 +1,142 @@
1
+ import { act, renderHook } from "@testing-library/react-native";
2
+
3
+ import { modalStore, useModalStoreState } from "../";
4
+
5
+ const item = { id: "river-general", name: "Test Modal" };
6
+ const props = { entry: { id: "modal-entry-1" } };
7
+
8
+ const openModal = () =>
9
+ act(() => {
10
+ modalStore.getState().openModal({ item, props } as any);
11
+ });
12
+
13
+ // Counts every render of the hook so the tests can assert on subscription
14
+ // behaviour, not just on the returned value.
15
+ const renderModalStoreState = (skipSubscription?: boolean) => {
16
+ const renders = { count: 0 };
17
+
18
+ const view = renderHook(() => {
19
+ renders.count += 1;
20
+
21
+ return skipSubscription === undefined
22
+ ? useModalStoreState()
23
+ : useModalStoreState(skipSubscription);
24
+ });
25
+
26
+ return { ...view, renders };
27
+ };
28
+
29
+ describe("useModalStoreState", () => {
30
+ afterEach(() => {
31
+ act(() => {
32
+ modalStore.getState().dismissModal();
33
+ });
34
+ });
35
+
36
+ describe("when subscribed (default)", () => {
37
+ it("returns the live modal state when called without arguments", () => {
38
+ const { result } = renderModalStoreState();
39
+
40
+ expect(result.current.visible).toBe(false);
41
+
42
+ openModal();
43
+
44
+ expect(result.current.visible).toBe(true);
45
+ expect(result.current.screen).toBe(item);
46
+ expect(result.current.props).toBe(props);
47
+ });
48
+
49
+ it("re-renders the consumer when the modal state changes", () => {
50
+ const { renders } = renderModalStoreState(false);
51
+
52
+ const rendersBeforeOpen = renders.count;
53
+
54
+ openModal();
55
+
56
+ expect(renders.count).toBeGreaterThan(rendersBeforeOpen);
57
+ });
58
+
59
+ // Counterpart to "returns a stable reference across store updates": an open
60
+ // modal is the one point where a live subscription and a skipped one hold
61
+ // different references, which is what makes that assertion meaningful.
62
+ it("returns a new reference while the modal is open", () => {
63
+ const { result } = renderModalStoreState(false);
64
+
65
+ const firstValue = result.current;
66
+
67
+ openModal();
68
+
69
+ expect(result.current).not.toBe(firstValue);
70
+ });
71
+ });
72
+
73
+ describe("when subscription is skipped", () => {
74
+ it("reports an empty modal state even while a modal is open", () => {
75
+ openModal();
76
+
77
+ expect(modalStore.getState().modalState.visible).toBe(true);
78
+
79
+ const { result } = renderModalStoreState(true);
80
+
81
+ expect(result.current).toMatchObject({
82
+ visible: false,
83
+ screen: null,
84
+ options: {},
85
+ props: {},
86
+ });
87
+ });
88
+
89
+ it("does not re-render the consumer when the modal state changes", () => {
90
+ const { renders } = renderModalStoreState(true);
91
+
92
+ const rendersBeforeOpen = renders.count;
93
+
94
+ openModal();
95
+
96
+ expect(renders.count).toBe(rendersBeforeOpen);
97
+ });
98
+
99
+ // The skipped branch has to hand back a module-level constant. Returning a
100
+ // fresh object would fail zustand's Object.is check and re-render on every
101
+ // store notification - the opposite of what skipping is for.
102
+ it("returns a stable reference across store updates", () => {
103
+ const { result } = renderModalStoreState(true);
104
+
105
+ const firstValue = result.current;
106
+
107
+ openModal();
108
+
109
+ // Asserted while the modal is open: dismissing resets the store to the
110
+ // very same initialModalState object, so an end-to-end round trip would
111
+ // hold this identity even for a live subscription.
112
+ expect(result.current).toBe(firstValue);
113
+
114
+ act(() => {
115
+ modalStore.getState().dismissModal();
116
+ });
117
+
118
+ expect(result.current).toBe(firstValue);
119
+ });
120
+ });
121
+
122
+ it("picks up the current modal state when it starts subscribing", () => {
123
+ let skipSubscription = true;
124
+
125
+ const { result, rerender } = renderHook(() =>
126
+ useModalStoreState(skipSubscription)
127
+ );
128
+
129
+ openModal();
130
+
131
+ expect(result.current.visible).toBe(false);
132
+
133
+ skipSubscription = false;
134
+
135
+ act(() => {
136
+ rerender(undefined);
137
+ });
138
+
139
+ expect(result.current.visible).toBe(true);
140
+ expect(result.current.screen).toBe(item);
141
+ });
142
+ });
@@ -1,83 +1,37 @@
1
- import { useStore, createStore } from "zustand";
2
-
3
- interface ModalState {
4
- visible: boolean;
5
- screen: any;
6
- options: Record<string, unknown>;
7
- props: Record<string, unknown>;
8
- }
9
-
10
- interface ModalStore {
11
- modalState: ModalState;
12
- setModalState: (newState: Partial<ModalState>) => void;
13
- openModal: (
14
- item: any,
15
- options?: Record<string, unknown>,
16
- props?: Record<string, unknown>
17
- ) => void;
18
- dismissModal: () => void;
19
- }
20
-
21
- const initialModalState: ModalState = {
22
- visible: false,
23
- screen: null,
24
- options: {},
25
- props: {},
26
- };
27
-
28
- export const modalStore = createStore<ModalStore>((set) => ({
29
- modalState: initialModalState,
30
- setModalState: (newState) =>
31
- set((state) => ({
32
- modalState: { ...state.modalState, ...newState },
33
- })),
34
- openModal: ({ item, options = {}, props }: OpenModalArg) =>
35
- set({
36
- modalState: {
37
- visible: true,
38
- screen: item,
39
- options: {
40
- animated: true,
41
- animationType: "slide",
42
- onShow: () => {},
43
- presentationStyle: "overFullScreen",
44
- transparent: true,
45
- ...options,
46
- onDismiss: () => set({ modalState: initialModalState }),
47
- onRequestClose: () => set({ modalState: initialModalState }),
48
- },
49
- props,
50
- },
51
- }),
52
- dismissModal: () => set(() => ({ modalState: initialModalState })),
53
- }));
54
-
55
- export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
56
- useStore(modalStore, selector);
57
-
58
- export const openModal = modalStore.getInitialState().openModal;
59
-
60
- export const dismissModal = modalStore.getInitialState().dismissModal;
61
-
62
- export const openBottomSheetModal = ({
63
- ModalBottomSheetContent,
64
- modalBottomSheetContentProps,
65
- props = {},
66
- options = {},
67
- }: OpenModalBottomSheetArgs) => {
68
- openModal({
69
- item: {
70
- ModalBottomSheetContent,
71
- modalBottomSheetContentProps,
72
- },
73
- props,
74
- options: {
75
- animationType: "none",
76
- animated: false,
77
- ...options,
78
- },
79
- });
80
- };
81
-
82
- export const useModalStoreState = (): ModalState =>
83
- useModalStore<ModalState>((state) => state.modalState);
1
+ export {
2
+ modalStore,
3
+ useModalStore,
4
+ openModal,
5
+ dismissModal,
6
+ openBottomSheetModal,
7
+ useModalStoreState,
8
+ } from "./store";
9
+
10
+ export type { ModalState, ModalStore } from "./store";
11
+
12
+ export { modalOrchestrator } from "./ModalOrchestrator";
13
+
14
+ export { ContentViewModel } from "./ContentViewModel";
15
+
16
+ export type {
17
+ Menu,
18
+ MenuItem,
19
+ Header,
20
+ Content,
21
+ Action,
22
+ PresentSubMenuAction,
23
+ SecondaryAction,
24
+ SelectMode,
25
+ SelectionBehavior,
26
+ OperationButton,
27
+ OperationButtons,
28
+ } from "./types";
29
+
30
+ export {
31
+ isPresentSubMenuAction,
32
+ getMenuItemActions,
33
+ OPERATIONS,
34
+ hasOperation,
35
+ } from "./types";
36
+
37
+ export { useBottomSheetContent } from "./useBottomSheetContent";