@applicaster/quick-brick-core 15.1.4 → 16.0.0-alpha.1042942411
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/App/ActionSetters/index.ts +5 -4
- package/App/ActionsProvider/ActionsProvider.tsx +31 -9
- package/App/ActionsProvider/LegacyActionsRegistryAdapter.tsx +107 -0
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +12 -27
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx +197 -104
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useOpenSchemeHandler/index.ts +4 -7
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler.ts +42 -30
- package/App/DeepLinking/URLSchemeHandler/URLSchemeHandler.tsx +4 -1
- package/App/DeepLinking/URLSchemeHandler/__tests__/URLSchemeHandler.test.tsx +20 -13
- package/App/DeepLinking/URLSchemeListener/index.tsx +3 -4
- package/App/ErrorBoundary/__tests__/store.test.js +1 -1
- package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/__tests__/index.test.tsx +88 -0
- package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/index.tsx +30 -56
- package/App/NavigationProvider/Loader.tsx +3 -4
- package/App/NavigationProvider/NavigationProvider.tsx +22 -35
- package/App/NavigationProvider/ScreenHooks/usePluginScreenHooks.ts +2 -2
- package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +193 -152
- package/App/NavigationProvider/navigator/selectors.ts +21 -5
- package/App/NetworkStatusProvider/NetworkStatusProvider.tsx +2 -2
- package/App/NetworkStatusProvider/__tests__/NetworkStatusProvider.test.tsx +4 -4
- package/App/NotificationToastRenderer/NotificationToastManager.ts +203 -0
- package/App/NotificationToastRenderer/NotificationToastRenderer.tsx +102 -0
- package/App/NotificationToastRenderer/NotificationToastRenderer.web.tsx +61 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastManager.test.ts +213 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.test.tsx +85 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.web.test.tsx +90 -0
- package/App/NotificationToastRenderer/__tests__/useNotificationHeight.test.tsx +53 -0
- package/App/NotificationToastRenderer/__tests__/useNotificationToastState.test.ts +112 -0
- package/App/NotificationToastRenderer/index.tsx +5 -0
- package/App/NotificationToastRenderer/useNotificationHeight.tsx +14 -0
- package/App/NotificationToastRenderer/useNotificationToastState.tsx +12 -0
- package/App/__tests__/createQuickBrickApp.test.js +1 -1
- package/App/appRemoteDataLoader/index.tsx +2 -2
- package/App/index.tsx +8 -5
- package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +1 -1
- package/App/remoteContextReloader/helpers.ts +3 -3
- package/package.json +8 -8
- package/App/DeepLinking/URLSchemeHandler/__tests__/__snapshots__/URLSchemeHandler.test.tsx.snap +0 -24
|
@@ -21,7 +21,8 @@ const warnUndefinedContext = (context) =>
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
type Subscription = {
|
|
24
|
-
[x: string]: () => any;
|
|
24
|
+
[x: string]: (() => any) | string;
|
|
25
|
+
pluginId?: string;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
const getModuleContext = R.path(["module", "context"]);
|
|
@@ -29,7 +30,7 @@ const getModuleContext = R.path(["module", "context"]);
|
|
|
29
30
|
const getContexts = R.compose(
|
|
30
31
|
R.map((action) => {
|
|
31
32
|
const item = getModuleContext(action);
|
|
32
|
-
item
|
|
33
|
+
item.pluginId = action.name;
|
|
33
34
|
|
|
34
35
|
return item;
|
|
35
36
|
}),
|
|
@@ -46,10 +47,10 @@ const useSubscribeToActionProviders = () => {
|
|
|
46
47
|
}, [actionContext]);
|
|
47
48
|
|
|
48
49
|
const subscriptions = getContexts(actionContext.actions).map((context) => {
|
|
49
|
-
const subscription = React.useContext<
|
|
50
|
+
const subscription = React.useContext<Subscription>(context);
|
|
50
51
|
|
|
51
52
|
if (subscription) {
|
|
52
|
-
subscription
|
|
53
|
+
subscription.pluginId = context.pluginId;
|
|
53
54
|
|
|
54
55
|
return subscription;
|
|
55
56
|
} else {
|
|
@@ -3,6 +3,14 @@ import * as R from "ramda";
|
|
|
3
3
|
|
|
4
4
|
import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ActionsContext";
|
|
5
5
|
import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
|
|
6
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
7
|
+
|
|
8
|
+
import { LegacyActionsRegistryAdapter } from "./LegacyActionsRegistryAdapter";
|
|
9
|
+
|
|
10
|
+
const { log_debug } = createLogger({
|
|
11
|
+
subsystem: "ActionsProvider",
|
|
12
|
+
category: "ActionRegistration",
|
|
13
|
+
});
|
|
6
14
|
|
|
7
15
|
type Props = {
|
|
8
16
|
children: React.ReactNode;
|
|
@@ -36,19 +44,17 @@ const abstractIdentifier = (actionPlugins: Plugin[]): PluginsIdMap =>
|
|
|
36
44
|
* Component returning children.
|
|
37
45
|
* Can be used to create Component from children
|
|
38
46
|
*/
|
|
39
|
-
const ChildrenWrapper = ({
|
|
40
|
-
children
|
|
41
|
-
}: {
|
|
42
|
-
children: React.ReactElement<any>;
|
|
43
|
-
}) => {
|
|
44
|
-
return children;
|
|
47
|
+
const ChildrenWrapper = ({ children }: { children: React.ReactNode }) => {
|
|
48
|
+
return <>{children}</>;
|
|
45
49
|
};
|
|
46
50
|
|
|
47
51
|
/**
|
|
48
52
|
* It wraps children in multiple context providers
|
|
49
53
|
* @param contexts - Array of React Context Providers
|
|
50
54
|
*/
|
|
51
|
-
const contextComposer = (
|
|
55
|
+
const contextComposer = (
|
|
56
|
+
contexts: Plugin[]
|
|
57
|
+
): React.ComponentType<React.PropsWithChildren> =>
|
|
52
58
|
R.compose(...contexts)(ChildrenWrapper);
|
|
53
59
|
|
|
54
60
|
/**
|
|
@@ -69,6 +75,19 @@ export function ActionsProvider(props: Props) {
|
|
|
69
75
|
[plugins]
|
|
70
76
|
);
|
|
71
77
|
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
const count = Object.keys(actionPlugins).length;
|
|
80
|
+
|
|
81
|
+
if (count > 0) {
|
|
82
|
+
log_debug(
|
|
83
|
+
`ActionsProvider: composed ${count} action plugin(s) into context`,
|
|
84
|
+
{ identifiers: Object.keys(actionPlugins) }
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
log_debug("ActionsProvider: no action plugins to compose");
|
|
88
|
+
}
|
|
89
|
+
}, [actionPlugins]);
|
|
90
|
+
|
|
72
91
|
const contextProviders = React.useMemo((): [Plugin] | [] => {
|
|
73
92
|
try {
|
|
74
93
|
const providers = R.compose(
|
|
@@ -88,7 +107,7 @@ export function ActionsProvider(props: Props) {
|
|
|
88
107
|
? contextComposer(contextProviders)
|
|
89
108
|
: React.Fragment,
|
|
90
109
|
[]
|
|
91
|
-
)
|
|
110
|
+
) as React.ComponentType<React.PropsWithChildren>;
|
|
92
111
|
|
|
93
112
|
const contextValue = React.useMemo(
|
|
94
113
|
() => ({ actions: actionPlugins }),
|
|
@@ -97,7 +116,10 @@ export function ActionsProvider(props: Props) {
|
|
|
97
116
|
|
|
98
117
|
return (
|
|
99
118
|
<ActionsContext.Provider value={contextValue}>
|
|
100
|
-
<Context>
|
|
119
|
+
<Context>
|
|
120
|
+
<LegacyActionsRegistryAdapter actionPlugins={actionPlugins} />
|
|
121
|
+
{children}
|
|
122
|
+
</Context>
|
|
101
123
|
</ActionsContext.Provider>
|
|
102
124
|
);
|
|
103
125
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as R from "ramda";
|
|
3
|
+
|
|
4
|
+
import { uiActionsRegistry } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
|
|
5
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
6
|
+
|
|
7
|
+
const { log_debug, log_warning } = createLogger({
|
|
8
|
+
subsystem: "LegacyActionsRegistryAdapter",
|
|
9
|
+
category: "ActionRegistration",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
type LegacyActionPlugin = Record<string, any> & {
|
|
13
|
+
identifier: string;
|
|
14
|
+
module: {
|
|
15
|
+
context?: React.Context<any>;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Bridges a single legacy action plugin (one that exposes `module.context`)
|
|
22
|
+
* into the `uiActionsRegistry`.
|
|
23
|
+
*
|
|
24
|
+
* Reactivity note: legacy stateful actions rely on React Context re-renders to
|
|
25
|
+
* propagate their latest value to subscribed UI (via `useActions`). We keep
|
|
26
|
+
* that mechanism intact and only *mirror* the current value into the registry
|
|
27
|
+
* through a ref, so registry-based consumers always read the freshest value at
|
|
28
|
+
* call time without changing legacy reactivity.
|
|
29
|
+
*/
|
|
30
|
+
function LegacyActionBridge({ plugin }: { plugin: LegacyActionPlugin }) {
|
|
31
|
+
// `plugin.module.context` is stable for the lifetime of the plugin, so this
|
|
32
|
+
// single `useContext` call is safe and rules-of-hooks compliant.
|
|
33
|
+
const value = React.useContext(plugin.module.context as React.Context<any>);
|
|
34
|
+
|
|
35
|
+
const valueRef = React.useRef(value);
|
|
36
|
+
valueRef.current = value;
|
|
37
|
+
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
if (value == null) {
|
|
40
|
+
log_warning(
|
|
41
|
+
`LegacyActionBridge: context value for "${plugin.identifier}" is null/undefined – skipping registration`,
|
|
42
|
+
{ identifier: plugin.identifier }
|
|
43
|
+
);
|
|
44
|
+
} else {
|
|
45
|
+
log_debug(
|
|
46
|
+
`LegacyActionBridge: context value ready for "${plugin.identifier}", registering in UIActionsRegistry`,
|
|
47
|
+
{ identifier: plugin.identifier }
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const unregister = uiActionsRegistry.registerActionProvider(
|
|
52
|
+
plugin.identifier,
|
|
53
|
+
() =>
|
|
54
|
+
valueRef.current
|
|
55
|
+
? [{ identifier: plugin.identifier, action: valueRef.current }]
|
|
56
|
+
: []
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
log_debug(
|
|
61
|
+
`LegacyActionBridge: unmounting bridge for "${plugin.identifier}"`,
|
|
62
|
+
{ identifier: plugin.identifier }
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
unregister();
|
|
66
|
+
};
|
|
67
|
+
}, [plugin.identifier]);
|
|
68
|
+
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type Props = {
|
|
73
|
+
actionPlugins: Record<string, LegacyActionPlugin>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Registers every legacy action plugin's live context value into the
|
|
78
|
+
* `uiActionsRegistry`. It must be rendered *inside* the composed context
|
|
79
|
+
* providers (see `ActionsProvider`) so that each plugin's context is populated.
|
|
80
|
+
*
|
|
81
|
+
* This is the compatibility layer that lets new, registry-based consumers read
|
|
82
|
+
* actions coming from old plugins that still export `contextProvider`/`context`.
|
|
83
|
+
*/
|
|
84
|
+
export function LegacyActionsRegistryAdapter({ actionPlugins }: Props) {
|
|
85
|
+
const bridgedPlugins = React.useMemo(
|
|
86
|
+
() =>
|
|
87
|
+
R.values(actionPlugins).filter(
|
|
88
|
+
(plugin) => plugin?.module?.context != null
|
|
89
|
+
),
|
|
90
|
+
[actionPlugins]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
log_debug(
|
|
94
|
+
`LegacyActionsRegistryAdapter: bridging ${bridgedPlugins.length} legacy action plugin(s)`,
|
|
95
|
+
{ identifiers: bridgedPlugins.map((p) => p.identifier) }
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
{bridgedPlugins.map((plugin) => (
|
|
101
|
+
<LegacyActionBridge key={plugin.identifier} plugin={plugin} />
|
|
102
|
+
))}
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
LegacyActionsRegistryAdapter.displayName = "LegacyActionsRegistryAdapter";
|
package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
|
-
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
3
2
|
import * as feedLoader from "@applicaster/zapp-react-native-utils/reactHooks/feed/useFeedLoader";
|
|
4
3
|
import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
5
4
|
import { waitFor, cleanup, renderHook } from "@testing-library/react-native";
|
|
6
5
|
import nock from "nock";
|
|
7
|
-
import * as R from "ramda";
|
|
8
6
|
import React from "react";
|
|
9
|
-
import {
|
|
10
|
-
import configureStore from "redux-mock-store";
|
|
7
|
+
import { mergeDeepRight } from "ramda";
|
|
11
8
|
import * as helpers from "../../../helpers";
|
|
9
|
+
import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
|
|
10
|
+
|
|
12
11
|
import {
|
|
13
12
|
noTargetScreenError,
|
|
14
13
|
resolveError,
|
|
@@ -24,6 +23,7 @@ const rivers: Record<string, Partial<ZappRiver>> = {
|
|
|
24
23
|
home: true,
|
|
25
24
|
},
|
|
26
25
|
B0987: {
|
|
26
|
+
type: "any",
|
|
27
27
|
id: "B0987",
|
|
28
28
|
},
|
|
29
29
|
C5678: {
|
|
@@ -42,7 +42,7 @@ const contentTypes: ZappContentTypes = {
|
|
|
42
42
|
const endpoint = "http://feed.com";
|
|
43
43
|
|
|
44
44
|
const pipesEndpoints: ZappPipesEndpoints = {
|
|
45
|
-
[
|
|
45
|
+
[endpoint]: {
|
|
46
46
|
context_keys: [],
|
|
47
47
|
context_obj: [],
|
|
48
48
|
},
|
|
@@ -55,7 +55,6 @@ const navigator = {
|
|
|
55
55
|
goHome: jest.fn(),
|
|
56
56
|
} as any;
|
|
57
57
|
|
|
58
|
-
const mockStore = configureStore();
|
|
59
58
|
jest.spyOn(useNavigationHooks, "useNavigation").mockReturnValue(navigator);
|
|
60
59
|
|
|
61
60
|
const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
|
|
@@ -80,31 +79,17 @@ jest.mock("../../../logger", () => ({
|
|
|
80
79
|
// to use import instead of require it's required to use jest.mock above
|
|
81
80
|
const { useOpenSchemeHandler } = require("../useOpenSchemeHandler");
|
|
82
81
|
|
|
83
|
-
const
|
|
84
|
-
const store = mockStore(
|
|
85
|
-
R.mergeDeepRight(
|
|
86
|
-
{ rivers, contentTypes, pipesEndpoints, appData },
|
|
87
|
-
storeProps
|
|
88
|
-
)
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
appStore.set(store);
|
|
92
|
-
|
|
93
|
-
const Wrapper = ({ children }: { children: React.ReactChild }) => (
|
|
94
|
-
/* @ts-ignore */
|
|
95
|
-
<Provider store={store}>{children}</Provider>
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return Wrapper;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const testHook = async ({ url, query, storeProps = {}, tests }) => {
|
|
102
|
-
const wrapper = getWrapper(storeProps);
|
|
82
|
+
const mockStoreObj = { rivers, contentTypes, pipesEndpoints, appData };
|
|
103
83
|
|
|
84
|
+
const testHook = async ({ url, query, storeProps = {}, tests }: any) => {
|
|
104
85
|
const callback = jest.fn((fn) => fn(tests));
|
|
105
86
|
|
|
106
87
|
renderHook(() => useOpenSchemeHandler({ url, query, onFinish: callback }), {
|
|
107
|
-
wrapper
|
|
88
|
+
wrapper: ({ children }) => (
|
|
89
|
+
<WrappedWithProviders store={mergeDeepRight(mockStoreObj, storeProps)}>
|
|
90
|
+
{children}
|
|
91
|
+
</WrappedWithProviders>
|
|
92
|
+
),
|
|
108
93
|
});
|
|
109
94
|
|
|
110
95
|
await waitFor(() => expect(callback).toHaveBeenCalled());
|
package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { renderHook } from "@testing-library/react-
|
|
2
|
+
import { renderHook } from "@testing-library/react-native";
|
|
3
3
|
import * as URLHandlersMap from "..";
|
|
4
4
|
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
import configureStore from "redux-mock-store";
|
|
7
7
|
|
|
8
8
|
import { log_warning } from "../../../logger";
|
|
9
|
+
import { handleActionSchemeUrl } from "../useUrlSchemeHandler";
|
|
10
|
+
import { appStore } from "../../../../../../zapp-react-native-redux/AppStore";
|
|
11
|
+
|
|
12
|
+
type UrlSchemeHandlerArgs = {
|
|
13
|
+
query: Record<string, unknown>;
|
|
14
|
+
url: string;
|
|
15
|
+
onFinish?: (callback: () => void) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type PluginType = "general" | "player";
|
|
19
|
+
|
|
20
|
+
interface ZappPlugin {
|
|
21
|
+
urlScheme?: {
|
|
22
|
+
host: string;
|
|
23
|
+
handler: (args: UrlSchemeHandlerArgs) => void;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface QuickBrickPlugin {
|
|
28
|
+
module: ZappPlugin;
|
|
29
|
+
name: string;
|
|
30
|
+
identifier: string;
|
|
31
|
+
type: PluginType;
|
|
32
|
+
}
|
|
9
33
|
|
|
10
34
|
const mockStore = configureStore();
|
|
11
35
|
|
|
@@ -14,153 +38,222 @@ jest.mock("../../../logger", () => ({
|
|
|
14
38
|
log_warning: jest.fn(),
|
|
15
39
|
}));
|
|
16
40
|
|
|
17
|
-
const
|
|
18
|
-
|
|
41
|
+
const mockHandler = jest.fn(({ onFinish }) => {
|
|
42
|
+
onFinish?.(() => {});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const mockComplexHandler = jest.fn(({ onFinish }) => {
|
|
46
|
+
onFinish?.(() => {});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const lambdaPlugin: QuickBrickPlugin = {
|
|
50
|
+
module: {} as ZappPlugin,
|
|
19
51
|
name: "Lambda plugin",
|
|
20
52
|
identifier: "someplugin",
|
|
21
|
-
type: "general"
|
|
53
|
+
type: "general",
|
|
22
54
|
};
|
|
23
55
|
|
|
24
|
-
const pluginWithHandler = {
|
|
56
|
+
const pluginWithHandler: QuickBrickPlugin = {
|
|
25
57
|
name: "Plugin handling scheme",
|
|
26
58
|
identifier: "plugin-with-handler",
|
|
27
|
-
type: "general"
|
|
59
|
+
type: "general",
|
|
28
60
|
module: {
|
|
29
61
|
urlScheme: {
|
|
30
62
|
host: "foo",
|
|
31
|
-
handler:
|
|
32
|
-
|
|
33
|
-
|
|
63
|
+
handler: mockHandler,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const pluginWithComplexHandler: QuickBrickPlugin = {
|
|
69
|
+
name: "Plugin with nested handler",
|
|
70
|
+
identifier: "plugin-with-nested-handler",
|
|
71
|
+
type: "general",
|
|
72
|
+
module: {
|
|
73
|
+
urlScheme: {
|
|
74
|
+
host: "complex",
|
|
75
|
+
handler: mockComplexHandler,
|
|
34
76
|
},
|
|
35
|
-
}
|
|
77
|
+
},
|
|
36
78
|
};
|
|
37
79
|
|
|
38
|
-
const plugins
|
|
80
|
+
const plugins = [lambdaPlugin, pluginWithHandler, pluginWithComplexHandler];
|
|
39
81
|
|
|
40
82
|
const { useUrlSchemeHandler } = require("../useUrlSchemeHandler");
|
|
41
83
|
|
|
42
84
|
describe("useUrlSchemeHandler", () => {
|
|
43
|
-
|
|
44
|
-
// log_warning.mockClear();
|
|
45
|
-
// });
|
|
85
|
+
const store = mockStore({ plugins });
|
|
46
86
|
|
|
47
|
-
|
|
87
|
+
appStore.set(store);
|
|
48
88
|
|
|
49
|
-
const wrapper: React.FC
|
|
89
|
+
const wrapper: React.FC = ({ children }) => (
|
|
50
90
|
<Provider store={store}>{children}</Provider>
|
|
51
91
|
);
|
|
52
92
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const onFinish = jest.fn();
|
|
56
|
-
const url = "test://present?foo=bar";
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
jest.clearAllMocks();
|
|
57
95
|
|
|
58
|
-
URLHandlersMap.schemeHandlerHooks.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
() =>
|
|
62
|
-
useUrlSchemeHandler({
|
|
63
|
-
url,
|
|
64
|
-
onFinish,
|
|
65
|
-
}),
|
|
66
|
-
{ wrapper }
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
expect(presentSpy).toBeCalledWith({ query: { foo: "bar" }, url, onFinish });
|
|
96
|
+
Object.keys(URLHandlersMap.schemeHandlerHooks).forEach((key) => {
|
|
97
|
+
delete (URLHandlersMap.schemeHandlerHooks as any)[key];
|
|
98
|
+
});
|
|
70
99
|
});
|
|
71
100
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
101
|
+
describe("Basic URL scheme handling", () => {
|
|
102
|
+
it("handles query params correctly", () => {
|
|
103
|
+
const testHandler = jest.fn();
|
|
104
|
+
(URLHandlersMap.schemeHandlerHooks as any).test = testHandler;
|
|
105
|
+
const testUrl = "test://test?foo=bar";
|
|
106
|
+
|
|
107
|
+
renderHook(
|
|
108
|
+
() =>
|
|
109
|
+
useUrlSchemeHandler({
|
|
110
|
+
url: testUrl,
|
|
111
|
+
onFinish: jest.fn(),
|
|
112
|
+
}),
|
|
113
|
+
{ wrapper }
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(testHandler).toBeCalledWith({
|
|
117
|
+
query: { foo: "bar" },
|
|
118
|
+
url: testUrl,
|
|
119
|
+
onFinish: expect.any(Function),
|
|
120
|
+
});
|
|
77
121
|
});
|
|
78
122
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
url,
|
|
83
|
-
onFinish,
|
|
84
|
-
}),
|
|
85
|
-
{ wrapper }
|
|
86
|
-
);
|
|
123
|
+
it("handles missing scheme handlers gracefully", () => {
|
|
124
|
+
const testUrl = "test://unknown?foo=bar";
|
|
125
|
+
const finishCallback = jest.fn();
|
|
87
126
|
|
|
88
|
-
|
|
127
|
+
const onFinish = jest.fn((cb) => {
|
|
128
|
+
cb();
|
|
129
|
+
finishCallback();
|
|
130
|
+
});
|
|
89
131
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
132
|
+
renderHook(
|
|
133
|
+
() =>
|
|
134
|
+
useUrlSchemeHandler({
|
|
135
|
+
url: testUrl,
|
|
136
|
+
onFinish,
|
|
137
|
+
}),
|
|
138
|
+
{ wrapper }
|
|
139
|
+
);
|
|
94
140
|
|
|
95
|
-
|
|
96
|
-
const url = "test://present?foo=bar";
|
|
97
|
-
const onFinish = jest.fn();
|
|
141
|
+
expect(finishCallback).toBeCalled();
|
|
98
142
|
|
|
99
|
-
|
|
100
|
-
onFinish();
|
|
143
|
+
expect(log_warning).toBeCalledWith(expect.stringContaining(testUrl));
|
|
101
144
|
});
|
|
102
|
-
|
|
103
|
-
URLHandlersMap.schemeHandlerHooks.present = presentSpy;
|
|
104
|
-
|
|
105
|
-
renderHook(
|
|
106
|
-
() =>
|
|
107
|
-
useUrlSchemeHandler({
|
|
108
|
-
url,
|
|
109
|
-
onFinish,
|
|
110
|
-
}),
|
|
111
|
-
{ wrapper }
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
expect(onFinish).toBeCalled();
|
|
115
145
|
});
|
|
116
146
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
147
|
+
describe("Plugin-based scheme handling", () => {
|
|
148
|
+
it("resolves and calls plugin handlers", () => {
|
|
149
|
+
const testUrl = "test://foo?param=test";
|
|
150
|
+
const onFinish = jest.fn();
|
|
151
|
+
|
|
152
|
+
renderHook(
|
|
153
|
+
() =>
|
|
154
|
+
useUrlSchemeHandler({
|
|
155
|
+
url: testUrl,
|
|
156
|
+
onFinish,
|
|
157
|
+
}),
|
|
158
|
+
{ wrapper }
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(mockHandler).toBeCalledWith({
|
|
162
|
+
query: { param: "test" },
|
|
163
|
+
url: testUrl,
|
|
164
|
+
onFinish,
|
|
165
|
+
});
|
|
122
166
|
});
|
|
123
167
|
|
|
124
|
-
|
|
125
|
-
|
|
168
|
+
it("handles complex plugin configurations", () => {
|
|
169
|
+
const testUrl = "test://complex?param=nested";
|
|
170
|
+
const onFinish = jest.fn();
|
|
171
|
+
|
|
172
|
+
renderHook(
|
|
173
|
+
() =>
|
|
174
|
+
useUrlSchemeHandler({
|
|
175
|
+
url: testUrl,
|
|
176
|
+
onFinish,
|
|
177
|
+
}),
|
|
178
|
+
{ wrapper }
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect(mockComplexHandler).toBeCalledWith({
|
|
182
|
+
query: { param: "nested" },
|
|
183
|
+
url: testUrl,
|
|
184
|
+
onFinish,
|
|
185
|
+
});
|
|
126
186
|
});
|
|
127
187
|
|
|
128
|
-
|
|
188
|
+
it("ignores plugins without urlScheme", () => {
|
|
189
|
+
const testUrl = "test://nonexistent?param=value";
|
|
190
|
+
const finishCallback = jest.fn();
|
|
191
|
+
|
|
192
|
+
const onFinish = jest.fn((cb) => {
|
|
193
|
+
cb();
|
|
194
|
+
finishCallback();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
renderHook(
|
|
198
|
+
() =>
|
|
199
|
+
useUrlSchemeHandler({
|
|
200
|
+
url: testUrl,
|
|
201
|
+
onFinish,
|
|
202
|
+
}),
|
|
203
|
+
{ wrapper }
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
expect(lambdaPlugin.module).not.toHaveProperty("urlScheme");
|
|
207
|
+
expect(finishCallback).toBeCalled();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
129
210
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
url,
|
|
134
|
-
onFinish,
|
|
135
|
-
}),
|
|
136
|
-
{ wrapper }
|
|
137
|
-
);
|
|
211
|
+
describe("Action scheme handling", () => {
|
|
212
|
+
it("handles action schemes using plugins", () => {
|
|
213
|
+
const testUrl = "test://foo?action=test";
|
|
138
214
|
|
|
139
|
-
|
|
215
|
+
handleActionSchemeUrl({
|
|
216
|
+
url: testUrl,
|
|
217
|
+
plugins,
|
|
218
|
+
} as any);
|
|
140
219
|
|
|
141
|
-
|
|
142
|
-
|
|
220
|
+
expect(mockHandler).toBeCalledWith({
|
|
221
|
+
query: { action: "test" },
|
|
222
|
+
url: testUrl,
|
|
223
|
+
});
|
|
224
|
+
});
|
|
143
225
|
|
|
144
|
-
|
|
145
|
-
|
|
226
|
+
it("throws for unknown action schemes", () => {
|
|
227
|
+
const testUrl = "test://unknown?action=test";
|
|
146
228
|
|
|
147
|
-
|
|
148
|
-
|
|
229
|
+
expect(() => {
|
|
230
|
+
handleActionSchemeUrl({
|
|
231
|
+
url: testUrl,
|
|
232
|
+
plugins,
|
|
233
|
+
} as any);
|
|
234
|
+
}).toThrow(/Non of the installed plugins/);
|
|
149
235
|
});
|
|
150
236
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
237
|
+
it("handles malformed URLs gracefully", () => {
|
|
238
|
+
const testUrl = "invalid-url";
|
|
239
|
+
const finishCallback = jest.fn();
|
|
240
|
+
|
|
241
|
+
const onFinish = jest.fn((cb) => {
|
|
242
|
+
cb();
|
|
243
|
+
finishCallback();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
renderHook(
|
|
247
|
+
() =>
|
|
248
|
+
useUrlSchemeHandler({
|
|
249
|
+
url: testUrl,
|
|
250
|
+
onFinish,
|
|
251
|
+
}),
|
|
252
|
+
{ wrapper }
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
expect(log_warning).toBeCalled();
|
|
256
|
+
expect(finishCallback).toBeCalled();
|
|
162
257
|
});
|
|
163
|
-
|
|
164
|
-
expect(onFinish).toBeCalled();
|
|
165
258
|
});
|
|
166
259
|
});
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useAppSelector,
|
|
3
|
-
selectContentTypes,
|
|
4
|
-
selectRivers,
|
|
5
|
-
} from "@applicaster/zapp-react-native-redux";
|
|
1
|
+
import { useContentTypes } from "@applicaster/zapp-react-native-redux";
|
|
6
2
|
import { ZappPipesEntryContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
7
3
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
8
4
|
import { useEffect } from "react";
|
|
@@ -24,6 +20,7 @@ import {
|
|
|
24
20
|
withInitialPlayerState,
|
|
25
21
|
} from "./utils";
|
|
26
22
|
import { log_warning } from "../../../logger";
|
|
23
|
+
import { useRivers } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
27
24
|
|
|
28
25
|
async function handleQuery({
|
|
29
26
|
query,
|
|
@@ -101,8 +98,8 @@ async function handleQuery({
|
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
export function useOpenSchemeHandler({ query, url, onFinish }) {
|
|
104
|
-
const rivers =
|
|
105
|
-
const contentTypes =
|
|
101
|
+
const rivers = useRivers();
|
|
102
|
+
const contentTypes = useContentTypes();
|
|
106
103
|
const navigator = useNavigation();
|
|
107
104
|
const homeId = getHomeScreenId(rivers);
|
|
108
105
|
const homeRoute = `/river/${homeId}`;
|