@applicaster/zapp-react-native-utils 16.0.0-alpha.7845362739 → 16.0.0-alpha.8101951023
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actionsExecutor/ActionExecutor.ts +50 -3
- package/actionsExecutor/ActionExecutorContext.tsx +99 -17
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +12 -0
- package/actionsExecutor/actions/navigateToScreen.ts +18 -4
- package/actionsExecutor/actions/openBottomSheet.ts +329 -0
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/refreshComponent.ts +6 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +64 -8
- package/actionsExecutor/consts.ts +27 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
- package/appUtils/HooksManager/index.ts +9 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
- package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
- package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
- package/appUtils/playerManager/index.ts +1 -1
- package/appUtils/playerManager/player.ts +115 -3
- package/appUtils/playerManager/playerFactory.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +6 -4
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
- package/arrayUtils/index.ts +79 -0
- package/cellUtils/index.ts +30 -3
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +269 -0
- package/configurationUtils/manifestKeyParser.ts +50 -10
- package/configurationUtils/modalBlocksParser.ts +214 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
- package/entryActions/aliasPresentation.ts +108 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +15 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +330 -1
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/modalBlocks.js +304 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +211 -0
- package/modalState/RemoteEditableCollection.ts +235 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/index.ts +35 -83
- package/modalState/store.ts +109 -0
- package/modalState/types.ts +160 -0
- package/modalState/useBottomSheetContent.ts +109 -0
- package/package.json +2 -2
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +37 -16
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/reactHooks/actions/index.ts +67 -2
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
- package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
- package/reactHooks/navigation/index.ts +2 -0
- package/reactHooks/navigation/usePresentScreen.ts +157 -0
- package/reactHooks/navigation/useRoute.ts +22 -5
- package/reactHooks/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +11 -1
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -203
- package/uiActionsRegistrator/registry.ts +335 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/zappFrameworkUtils/localStorageHelper.ts +10 -2
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
const mockAppStoreGet = jest.fn();
|
|
2
|
+
|
|
3
|
+
jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
|
|
4
|
+
appStore: { get: (key) => mockAppStoreGet(key) },
|
|
5
|
+
}));
|
|
6
|
+
|
|
1
7
|
import * as R from "ramda";
|
|
2
8
|
import * as pluginUtils from "../index";
|
|
3
9
|
|
|
@@ -148,6 +154,32 @@ describe("findPluginByIdentifier", () => {
|
|
|
148
154
|
});
|
|
149
155
|
});
|
|
150
156
|
|
|
157
|
+
describe("getPluginByIdentifier", () => {
|
|
158
|
+
const { getPluginByIdentifier } = pluginUtils;
|
|
159
|
+
|
|
160
|
+
const plugins = {
|
|
161
|
+
foo: pluginMock("foo", "foo", "some_plugin_type"),
|
|
162
|
+
bar: pluginMock("foo", "bar", "some_plugin_type"),
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
mockAppStoreGet.mockReset();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("reads plugins from appStore and returns the matching plugin", () => {
|
|
170
|
+
mockAppStoreGet.mockReturnValue(plugins);
|
|
171
|
+
|
|
172
|
+
expect(getPluginByIdentifier("foo")).toEqual(plugins.foo);
|
|
173
|
+
expect(mockAppStoreGet).toHaveBeenCalledWith("plugins");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("returns undefined when the plugin is not found", () => {
|
|
177
|
+
mockAppStoreGet.mockReturnValue(plugins);
|
|
178
|
+
|
|
179
|
+
expect(getPluginByIdentifier("do_not_exist")).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
151
183
|
describe("findPluginByType", () => {
|
|
152
184
|
const { findPluginByType } = pluginUtils;
|
|
153
185
|
|
package/pluginUtils/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
+
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
2
3
|
import { toCamelCase, toPascalCase } from "../stringUtils";
|
|
3
4
|
|
|
4
5
|
import { getNavigationType } from "../navigationUtils";
|
|
@@ -97,6 +98,34 @@ export function findPluginByIdentifier(
|
|
|
97
98
|
return plugin;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Like findPluginByIdentifier, but reads the current plugins list from appStore.
|
|
103
|
+
* Convenience for non-render / hook code that doesn't already have `plugins` in hand.
|
|
104
|
+
* @param identifier of the plugin to look for
|
|
105
|
+
* @param doNotWarn if set to true, will not log a warning if plugin is not found
|
|
106
|
+
* @return whole plugin if found, undefined otherwise
|
|
107
|
+
*/
|
|
108
|
+
export function getPluginByIdentifier(
|
|
109
|
+
identifier: string,
|
|
110
|
+
doNotWarn: boolean = false
|
|
111
|
+
): (QuickBrickPlugin | ZappPlugin | Plugin) | undefined {
|
|
112
|
+
try {
|
|
113
|
+
const plugins = appStore.get("plugins") ?? {};
|
|
114
|
+
|
|
115
|
+
return findPluginByIdentifier(identifier, plugins, doNotWarn);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (!doNotWarn) {
|
|
118
|
+
pluginUtilsLogger.warning({
|
|
119
|
+
message:
|
|
120
|
+
"Could not read plugins from appStore while resolving plugin by identifier",
|
|
121
|
+
data: { identifier, error },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
100
129
|
const pluginTypeForItemTypeMap = {
|
|
101
130
|
playable: "player",
|
|
102
131
|
};
|
|
@@ -6,6 +6,7 @@ import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Con
|
|
|
6
6
|
import {
|
|
7
7
|
observeEntryState,
|
|
8
8
|
RegisteredActionValue,
|
|
9
|
+
uiActionsRegistry,
|
|
9
10
|
} from "../../uiActionsRegistrator";
|
|
10
11
|
import { reactHooksLogger } from "../logger";
|
|
11
12
|
|
|
@@ -34,7 +35,13 @@ export function useActions<T = unknown>(plugId: string): any {
|
|
|
34
35
|
if (!logged) {
|
|
35
36
|
logger.warning({
|
|
36
37
|
message: `useActions: Couldn't find an action for ${plugId} plugin`,
|
|
37
|
-
|
|
38
|
+
// Identifiers only. The action map holds every plugin's module and
|
|
39
|
+
// live React context, which is far too large for a log line and can
|
|
40
|
+
// carry whatever state those plugins hold.
|
|
41
|
+
data: {
|
|
42
|
+
plugId,
|
|
43
|
+
availableActions: Object.keys(context?.actions ?? {}),
|
|
44
|
+
},
|
|
38
45
|
});
|
|
39
46
|
|
|
40
47
|
setLogged(true);
|
|
@@ -80,7 +87,31 @@ export function useEntryActionState(
|
|
|
80
87
|
useEffect(() => {
|
|
81
88
|
if (!action) return undefined;
|
|
82
89
|
|
|
83
|
-
|
|
90
|
+
// An action's stream is third-party code. Subscribing with only a `next`
|
|
91
|
+
// handler lets RxJS rethrow an error notification asynchronously, where no
|
|
92
|
+
// error boundary catches it - one plugin faulting would take the app down
|
|
93
|
+
// rather than this one button. The button keeps its last known state.
|
|
94
|
+
let subscription;
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
subscription = observeEntryState(action, entry).subscribe({
|
|
98
|
+
next: setState,
|
|
99
|
+
error: (error) =>
|
|
100
|
+
logger.warning({
|
|
101
|
+
message:
|
|
102
|
+
"useEntryActionState: the action's state stream failed - the button keeps its last state",
|
|
103
|
+
data: { entryId, error },
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
} catch (error) {
|
|
107
|
+
logger.warning({
|
|
108
|
+
message:
|
|
109
|
+
"useEntryActionState: could not observe the action - the button keeps its initial state",
|
|
110
|
+
data: { entryId, error },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
84
115
|
|
|
85
116
|
return () => subscription.unsubscribe();
|
|
86
117
|
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
@@ -88,6 +119,18 @@ export function useEntryActionState(
|
|
|
88
119
|
|
|
89
120
|
const invokeAction = useCallback(
|
|
90
121
|
(options: InvokeArgsOptions = {}) => {
|
|
122
|
+
if (typeof action?.invokeAction !== "function") {
|
|
123
|
+
// A button was rendered and pressed, and the press goes nowhere. Only
|
|
124
|
+
// reachable on a user interaction, so it costs nothing on render. The
|
|
125
|
+
// action value carries no identifier, so the label is what locates the
|
|
126
|
+
// button that misbehaved.
|
|
127
|
+
logger.warning({
|
|
128
|
+
message:
|
|
129
|
+
"useEntryActionState: the pressed action has no invokeAction - the press did nothing",
|
|
130
|
+
data: { entryId, label: state?.label },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
91
134
|
action?.invokeAction?.(entry, { updateState: setState, ...options });
|
|
92
135
|
},
|
|
93
136
|
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
@@ -96,3 +139,25 @@ export function useEntryActionState(
|
|
|
96
139
|
|
|
97
140
|
return { state, invokeAction };
|
|
98
141
|
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A value that changes whenever a provider is added to or removed from
|
|
145
|
+
* `uiActionsRegistry`.
|
|
146
|
+
*
|
|
147
|
+
* Providers can register after the UI that wants them has rendered - the audio
|
|
148
|
+
* player registers playback speed only once its controller has state, and
|
|
149
|
+
* plugin-backed actions are bridged in from an effect. Put this in the
|
|
150
|
+
* dependency list of anything that resolves actions, so the list is re-read
|
|
151
|
+
* instead of being frozen at first paint.
|
|
152
|
+
*/
|
|
153
|
+
export function useRegistryRevision(): number {
|
|
154
|
+
const [revision, setRevision] = useState(0);
|
|
155
|
+
|
|
156
|
+
useEffect(
|
|
157
|
+
() =>
|
|
158
|
+
uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
|
|
159
|
+
[]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return revision;
|
|
163
|
+
}
|
|
@@ -5,6 +5,7 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
|
|
|
5
5
|
|
|
6
6
|
const mockNavigator = {
|
|
7
7
|
getPathname: () => "pathnameMock",
|
|
8
|
+
currentRoute: "pathnameMock",
|
|
8
9
|
push: jest.fn(),
|
|
9
10
|
data: {},
|
|
10
11
|
};
|
|
@@ -29,6 +30,7 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
|
|
|
29
30
|
),
|
|
30
31
|
useTargetScreenData: jest.fn(() => ({})),
|
|
31
32
|
useCurrentScreenData: jest.fn(() => ({})),
|
|
33
|
+
useScreenContext: jest.fn(() => ({})),
|
|
32
34
|
}));
|
|
33
35
|
|
|
34
36
|
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
@@ -66,6 +68,12 @@ const wrapper = ({ children }) => (
|
|
|
66
68
|
</CellTapContext.Provider>
|
|
67
69
|
);
|
|
68
70
|
|
|
71
|
+
const actionExecutorWrapper = ({ children }) => (
|
|
72
|
+
<ActionExecutorContext.Provider value={actionExecutor}>
|
|
73
|
+
{children}
|
|
74
|
+
</ActionExecutorContext.Provider>
|
|
75
|
+
);
|
|
76
|
+
|
|
69
77
|
describe("useCellClick", () => {
|
|
70
78
|
it("returns a function", () => {
|
|
71
79
|
const { result } = renderHook(() => useCellClick(mockProps));
|
|
@@ -95,4 +103,60 @@ describe("useCellClick", () => {
|
|
|
95
103
|
|
|
96
104
|
cleanup();
|
|
97
105
|
});
|
|
106
|
+
|
|
107
|
+
it("does not push when the cell finishes a hook", async () => {
|
|
108
|
+
mockNavigator.push.mockClear();
|
|
109
|
+
|
|
110
|
+
const item = {
|
|
111
|
+
id: "profile-1",
|
|
112
|
+
type: { value: "feed" },
|
|
113
|
+
extensions: {
|
|
114
|
+
tap_actions: {
|
|
115
|
+
actions: [
|
|
116
|
+
{ type: "sessionStorageSet" },
|
|
117
|
+
{ type: "finishHook", options: { success: true } },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const { result } = renderHook(() => useCellClick({ item }), {
|
|
124
|
+
wrapper: actionExecutorWrapper,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await result.current();
|
|
128
|
+
|
|
129
|
+
await waitFor(() => {
|
|
130
|
+
expect(actionExecutor.handleEntryActions).toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(mockNavigator.push).not.toHaveBeenCalled();
|
|
134
|
+
cleanup();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("pushes after tap actions that do not finish a hook", async () => {
|
|
138
|
+
mockNavigator.push.mockClear();
|
|
139
|
+
|
|
140
|
+
const item = {
|
|
141
|
+
id: "episode-1",
|
|
142
|
+
type: { value: "feed" },
|
|
143
|
+
extensions: {
|
|
144
|
+
tap_actions: {
|
|
145
|
+
actions: [{ type: "sessionStorageSet" }],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const { result } = renderHook(() => useCellClick({ item }), {
|
|
151
|
+
wrapper: actionExecutorWrapper,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await result.current();
|
|
155
|
+
|
|
156
|
+
await waitFor(() => {
|
|
157
|
+
expect(mockNavigator.push).toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
cleanup();
|
|
161
|
+
});
|
|
98
162
|
});
|
|
@@ -83,6 +83,12 @@ export const useCellClick = ({
|
|
|
83
83
|
|
|
84
84
|
logOnPress(selectedItem, pathname, component, onCellTap);
|
|
85
85
|
|
|
86
|
+
const tapActions = selectedItem?.extensions?.tap_actions?.actions;
|
|
87
|
+
|
|
88
|
+
const finishesHook =
|
|
89
|
+
Array.isArray(tapActions) &&
|
|
90
|
+
tapActions.some((action) => action?.type === "finishHook");
|
|
91
|
+
|
|
86
92
|
if (selectedItem) {
|
|
87
93
|
await actionExecutor?.handleEntryActions(selectedItem, {
|
|
88
94
|
component,
|
|
@@ -101,20 +107,21 @@ export const useCellClick = ({
|
|
|
101
107
|
url: selectedItem.link.href,
|
|
102
108
|
});
|
|
103
109
|
}
|
|
104
|
-
} else {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
} else if (isFunction(onCellTap)) {
|
|
111
|
+
onCellTap?.(selectedItem, _index);
|
|
112
|
+
} else if (!finishesHook) {
|
|
113
|
+
// finishHook already completes the hook and navigates to the original
|
|
114
|
+
// target. Pushing the cell as well stacks a second copy of that screen
|
|
115
|
+
// (e.g. home/home after a profile selector hook).
|
|
116
|
+
if (currentRoute === pathname || pathname.includes("video-modal")) {
|
|
117
|
+
const targetScreen = component?.data?.target;
|
|
118
|
+
|
|
119
|
+
push(
|
|
120
|
+
R.when(
|
|
121
|
+
() => targetScreen,
|
|
122
|
+
R.mergeLeft({ screen_type: targetScreen })
|
|
123
|
+
)(selectedItem)
|
|
124
|
+
);
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
127
|
},
|
package/reactHooks/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
3
|
-
import { renderHook } from "@testing-library/react-native";
|
|
3
|
+
import { act, render, renderHook } from "@testing-library/react-native";
|
|
4
4
|
import { isNavBarVisible, useRoute } from "../";
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
import configureMockStore from "redux-mock-store";
|
|
7
7
|
import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
|
|
8
8
|
import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
|
|
9
9
|
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
10
|
+
import { modalStore } from "@applicaster/zapp-react-native-utils/modalState";
|
|
10
11
|
|
|
11
12
|
const plugins = [];
|
|
12
13
|
|
|
@@ -156,6 +157,20 @@ const videoModalWrapper = ({ children }) => (
|
|
|
156
157
|
</Provider>
|
|
157
158
|
);
|
|
158
159
|
|
|
160
|
+
const modalEntry = { id: "modal-entry-1", type: { value: "video" } };
|
|
161
|
+
|
|
162
|
+
const modalPathname = `${ROUTE_TYPES.MODAL}/${rivers["river-general"].id}`;
|
|
163
|
+
|
|
164
|
+
const modalWrapper = ({ children }) => (
|
|
165
|
+
<Provider store={store}>
|
|
166
|
+
<NavigationContext.Provider value={mainStackNavigator}>
|
|
167
|
+
<PathnameContext.Provider value={modalPathname}>
|
|
168
|
+
{children}
|
|
169
|
+
</PathnameContext.Provider>
|
|
170
|
+
</NavigationContext.Provider>
|
|
171
|
+
</Provider>
|
|
172
|
+
);
|
|
173
|
+
|
|
159
174
|
const hookModalWrapper = ({ children }) => (
|
|
160
175
|
<Provider store={store}>
|
|
161
176
|
<NavigationContext.Provider value={hookModalNavigator}>
|
|
@@ -166,6 +181,45 @@ const hookModalWrapper = ({ children }) => (
|
|
|
166
181
|
</Provider>
|
|
167
182
|
);
|
|
168
183
|
|
|
184
|
+
// Reports every render of useRoute so the tests below can assert on route
|
|
185
|
+
// transitions and on subscription behaviour, not just on a one-shot result.
|
|
186
|
+
function RouteProbe({ onRender }: { onRender: (route: any) => void }) {
|
|
187
|
+
onRender(useRoute());
|
|
188
|
+
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const openRiverModal = () =>
|
|
193
|
+
act(() => {
|
|
194
|
+
modalStore.getState().openModal({
|
|
195
|
+
item: rivers["river-general"] as any,
|
|
196
|
+
props: { entry: modalEntry },
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const renderRouteProbe = (pathname: string, onRender: (route: any) => void) => {
|
|
201
|
+
const tree = (currentPathname: string) => (
|
|
202
|
+
<Provider store={store}>
|
|
203
|
+
<ScreenDataContext.Provider value={homeStack.state}>
|
|
204
|
+
<NavigationContext.Provider value={videoModalNavigator}>
|
|
205
|
+
<PathnameContext.Provider value={currentPathname}>
|
|
206
|
+
<RouteProbe onRender={onRender} />
|
|
207
|
+
</PathnameContext.Provider>
|
|
208
|
+
</NavigationContext.Provider>
|
|
209
|
+
</ScreenDataContext.Provider>
|
|
210
|
+
</Provider>
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
const { rerender } = render(tree(pathname));
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
navigateTo: (nextPathname: string) =>
|
|
217
|
+
act(() => {
|
|
218
|
+
rerender(tree(nextPathname));
|
|
219
|
+
}),
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
|
|
169
223
|
describe("navigation", () => {
|
|
170
224
|
describe("useRoute", () => {
|
|
171
225
|
describe("Main stack components", () => {
|
|
@@ -188,6 +242,39 @@ describe("navigation", () => {
|
|
|
188
242
|
});
|
|
189
243
|
});
|
|
190
244
|
|
|
245
|
+
describe("Modal components", () => {
|
|
246
|
+
beforeEach(() => {
|
|
247
|
+
modalStore.getState().openModal({
|
|
248
|
+
item: rivers["river-general"] as any,
|
|
249
|
+
props: { entry: modalEntry },
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
afterEach(() => {
|
|
254
|
+
modalStore.getState().dismissModal();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("should return a correct pathname", () => {
|
|
258
|
+
const { result } = renderHook(() => useRoute(), {
|
|
259
|
+
wrapper: modalWrapper,
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
expect(result.current.pathname).toEqual(modalPathname);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("should return correct screenData information", () => {
|
|
266
|
+
const { result } = renderHook(() => useRoute(), {
|
|
267
|
+
wrapper: modalWrapper,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
expect(result.current.screenData.id).toEqual(modalEntry.id);
|
|
271
|
+
|
|
272
|
+
expect(result.current.screenData.targetScreen.id).toEqual(
|
|
273
|
+
rivers["river-general"].id
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
191
278
|
describe("Hook modal components", () => {
|
|
192
279
|
it("should return a correct pathname", () => {
|
|
193
280
|
const { result } = renderHook(() => useRoute(), {
|
|
@@ -231,6 +318,94 @@ describe("navigation", () => {
|
|
|
231
318
|
);
|
|
232
319
|
});
|
|
233
320
|
});
|
|
321
|
+
|
|
322
|
+
describe("store subscriptions", () => {
|
|
323
|
+
afterEach(() => {
|
|
324
|
+
act(() => {
|
|
325
|
+
modalStore.getState().dismissModal();
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Every hook in useRoute must run on every render. When the modal and
|
|
330
|
+
// hook-modal subscriptions lived inside the route branches, walking a
|
|
331
|
+
// single mounted component through the route types changed the hook
|
|
332
|
+
// count and React threw "Rendered more hooks than during the previous
|
|
333
|
+
// render".
|
|
334
|
+
it("keeps a stable hook order when the route type changes", () => {
|
|
335
|
+
let route: any;
|
|
336
|
+
|
|
337
|
+
const { navigateTo } = renderRouteProbe(homeStack.route, (current) => {
|
|
338
|
+
route = current;
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
expect(route.screenData.id).toEqual(entry.id);
|
|
342
|
+
expect(route.screenData.targetScreen.id).toEqual(screen.id);
|
|
343
|
+
|
|
344
|
+
openRiverModal();
|
|
345
|
+
navigateTo(modalPathname);
|
|
346
|
+
|
|
347
|
+
expect(route.pathname).toEqual(modalPathname);
|
|
348
|
+
expect(route.screenData.id).toEqual(modalEntry.id);
|
|
349
|
+
|
|
350
|
+
expect(route.screenData.targetScreen.id).toEqual(
|
|
351
|
+
rivers["river-general"].id
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
navigateTo(hooksModalPathname);
|
|
355
|
+
|
|
356
|
+
expect(route.pathname).toEqual(hooksModalPathname);
|
|
357
|
+
|
|
358
|
+
expect(route.screenData.id).toEqual(
|
|
359
|
+
hookModalContextState.state.screenData.payload.id
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
navigateTo(videoModalPathname);
|
|
363
|
+
|
|
364
|
+
expect(route.pathname).toEqual(videoModalPathname);
|
|
365
|
+
expect(route.screenData.id).toEqual(videoItem.id);
|
|
366
|
+
|
|
367
|
+
expect(route.screenData.targetScreen.id).toEqual(
|
|
368
|
+
rivers["river-player"].id
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
navigateTo(homeStack.route);
|
|
372
|
+
|
|
373
|
+
expect(route.pathname).toEqual(homeStack.route);
|
|
374
|
+
expect(route.screenData.id).toEqual(entry.id);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("does not re-render a non-modal route when modal state changes", () => {
|
|
378
|
+
let renders = 0;
|
|
379
|
+
|
|
380
|
+
renderRouteProbe(homeStack.route, () => {
|
|
381
|
+
renders += 1;
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const rendersBeforeOpen = renders;
|
|
385
|
+
|
|
386
|
+
openRiverModal();
|
|
387
|
+
|
|
388
|
+
expect(renders).toBe(rendersBeforeOpen);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("re-renders a modal route when modal state changes", () => {
|
|
392
|
+
let route: any;
|
|
393
|
+
|
|
394
|
+
renderRouteProbe(modalPathname, (current) => {
|
|
395
|
+
route = current;
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
expect(route.screenData).toEqual({});
|
|
399
|
+
|
|
400
|
+
openRiverModal();
|
|
401
|
+
|
|
402
|
+
expect(route.screenData.id).toEqual(modalEntry.id);
|
|
403
|
+
|
|
404
|
+
expect(route.screenData.targetScreen.id).toEqual(
|
|
405
|
+
rivers["river-general"].id
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
234
409
|
});
|
|
235
410
|
|
|
236
411
|
describe("isNavBarVisible", () => {
|