@applicaster/zapp-react-native-utils 12.0.0-rc.14 → 12.0.0-rc.141
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/ActionExecutorContext.tsx +16 -8
- package/analyticsUtils/AnalyticPlayerListener.ts +141 -0
- package/analyticsUtils/AnalyticsEvents/index.ts +13 -0
- package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
- package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
- package/analyticsUtils/PlayerAnalyticsManager.ts +90 -0
- package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
- package/analyticsUtils/analyticsPlugins.ts +25 -0
- package/analyticsUtils/events.ts +12 -0
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/analyticsUtils/index.tsx +12 -0
- package/analyticsUtils/{analyticsTracker.ts → playerAnalyticsTracker.ts} +19 -10
- package/appUtils/HooksManager/index.js +3 -1
- package/appUtils/accessibilityManager/const.ts +50 -0
- package/appUtils/accessibilityManager/hooks.ts +40 -0
- package/appUtils/accessibilityManager/index.ts +155 -0
- package/appUtils/accessibilityManager/logger.ts +5 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
- package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
- package/appUtils/focusManager/__tests__/index.test.ts +2 -3
- package/appUtils/focusManager/index.ts +76 -57
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +75 -35
- package/appUtils/focusManager/utils/index.ts +100 -0
- package/appUtils/focusManagerAux/index.ts +76 -0
- package/appUtils/focusManagerAux/utils/index.ts +100 -0
- package/appUtils/index.js +2 -0
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
- package/appUtils/keyCodes/keys.web.js +9 -0
- package/appUtils/keyCodes/keysByPlatform.js +11 -1
- package/appUtils/platform/const.ts +25 -0
- package/appUtils/platform/index.ts +3 -0
- package/appUtils/platform/platformUtils.ts +218 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
- package/appUtils/playerManager/conts.ts +6 -0
- package/appUtils/playerManager/index.ts +20 -32
- package/appUtils/playerManager/nativePlayerManager.ts +12 -0
- package/appUtils/playerManager/player.ts +56 -7
- package/appUtils/playerManager/playerFactory.ts +20 -5
- package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +57 -0
- package/appUtils/playerManager/playerNative.ts +41 -15
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +8 -2
- package/appUtils/playerManager/usePlayerState.tsx +20 -23
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
- package/arrayUtils/index.ts +16 -0
- package/booleanUtils/index.ts +4 -4
- package/cellUtils/__tests__/cellUtils.test.ts +48 -0
- package/cellUtils/__tests__/fixtures.ts +13 -0
- package/cellUtils/index.ts +78 -7
- package/dateUtils/index.ts +11 -0
- package/focusManager/FocusManager.ts +20 -5
- package/focusManager/__tests__/FocusManager.test.ts +0 -1
- package/focusManager/index.ts +1 -1
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
- package/functionUtils/__tests__/functionUtils.test.js +244 -248
- package/functionUtils/index.ts +38 -0
- package/headersUtils/index.ts +1 -0
- package/index.d.ts +15 -0
- package/inflatedUrlUtils/index.ts +4 -4
- package/keyboardState/index.ts +0 -0
- package/localizationUtils/__tests__/localizationUtils.test.ts +78 -55
- package/localizationUtils/index.ts +13 -19
- package/logger/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +131 -1
- package/manifestUtils/index.js +5 -1
- package/manifestUtils/keys.js +2 -1
- package/manifestUtils/secondaryImage/index.js +18 -15
- package/modalState/index.ts +57 -0
- package/navigationUtils/index.ts +105 -8
- package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
- package/numberUtils/__tests__/toNumber.test.ts +2 -2
- package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +66 -0
- package/numberUtils/__tests__/toPositiveNumberWithDefaultZero.test.ts +66 -0
- package/numberUtils/index.ts +27 -16
- package/package.json +3 -2
- package/playerUtils/configurationGenerator.ts +131 -1
- package/playerUtils/imaScriptDom.ts +59 -0
- package/pluginUtils/index.ts +20 -7
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
- package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
- package/reactHooks/cell-click/__tests__/index.test.js +16 -3
- package/reactHooks/cell-click/index.ts +30 -16
- package/reactHooks/debugging/__tests__/index.test.js +81 -11
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +69 -6
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
- package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
- package/reactHooks/feed/useBatchLoading.ts +52 -28
- package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
- package/reactHooks/feed/useFeedRefresh.tsx +9 -7
- package/reactHooks/feed/useInflatedUrl.ts +44 -15
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +66 -59
- package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
- package/reactHooks/layout/types/index.ts +2 -0
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +134 -0
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
- package/reactHooks/layout/useDimensions/useDimensions.ts +15 -7
- package/reactHooks/navigation/__mocks__/index.ts +15 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +240 -81
- package/reactHooks/navigation/index.ts +240 -81
- package/reactHooks/player/useAutoSeek.tsx +9 -7
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
- package/reactHooks/resolvers/useCellResolver.ts +5 -1
- package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
- package/reactHooks/screen/index.ts +4 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
- package/reactHooks/screen/useScreenContext.ts +4 -4
- package/reactHooks/screen/useScreenData.ts +1 -1
- package/reactHooks/screen/useTargetScreenData.ts +7 -0
- package/reactHooks/state/useRivers.ts +3 -1
- package/reactHooks/useConfiguration.ts +2 -2
- package/reactHooks/useListenEventBusEvent.ts +1 -4
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
- package/reactUtils/index.ts +104 -0
- package/riverComponetsMeasurementProvider/index.tsx +2 -2
- package/services/localStorageServiceSync.web.ts +48 -0
- package/services/sessionStorageServiceSync.web.ts +32 -0
- package/services/storageServiceSync.web.ts +24 -0
- package/services/storageWebUtils.web.ts +10 -0
- package/stringUtils/index.ts +5 -0
- package/testUtils/getByTestId.ts +14 -0
- package/testUtils/index.tsx +71 -23
- package/types.ts +4 -0
- package/appUtils/focusManager/FocusableEvents.ts +0 -8
- package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
- package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
|
@@ -13,10 +13,7 @@ export const useListenEventBusEvent = (
|
|
|
13
13
|
// TODO: remove after implementing ReactNativeEventBusBridge on iOS
|
|
14
14
|
if (Platform.OS === "android") {
|
|
15
15
|
// subscribe to DeviceEventEmitter using subsciption ID
|
|
16
|
-
const sub = DeviceEventEmitter.addListener(
|
|
17
|
-
subscriptionID,
|
|
18
|
-
handler
|
|
19
|
-
);
|
|
16
|
+
const sub = DeviceEventEmitter.addListener(subscriptionID, handler);
|
|
20
17
|
|
|
21
18
|
// ask native to start routing these events to RN
|
|
22
19
|
ReactNativeEventBusBridge.subscribe(subscriptionID, { [source]: events });
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
usePickFromState,
|
|
4
|
-
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
|
|
5
3
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
4
|
+
import { useRivers } from "../../state";
|
|
6
5
|
|
|
7
6
|
export const useVideoModalScreenData = ():
|
|
8
7
|
| (ZappEntry & { targetScreen: any }) // TODO: fix ZappEntry type ( was ZappRiver but conflict )
|
|
@@ -12,11 +11,13 @@ export const useVideoModalScreenData = ():
|
|
|
12
11
|
} = useNavigation();
|
|
13
12
|
|
|
14
13
|
const contentTypes = useContentTypes();
|
|
15
|
-
const
|
|
14
|
+
const rivers = useRivers();
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
return React.useMemo(() => {
|
|
17
|
+
if (item?.type?.value) {
|
|
18
|
+
const screenId = contentTypes[item?.type?.value].screen_id;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
return { ...item, targetScreen: rivers?.[screenId] };
|
|
21
|
+
}
|
|
22
|
+
}, [item]);
|
|
22
23
|
};
|
package/reactUtils/index.ts
CHANGED
|
@@ -108,3 +108,107 @@ export const isAndroidPlatform = () => Platform.OS === "android";
|
|
|
108
108
|
export const isTvOSPlatform = () => getPlatform() === "tvos";
|
|
109
109
|
|
|
110
110
|
export const isAndroidTVPlatform = () => getPlatform() === "android_tv";
|
|
111
|
+
|
|
112
|
+
declare global {
|
|
113
|
+
interface Window {
|
|
114
|
+
VIZIO?: {
|
|
115
|
+
Chromevox: {
|
|
116
|
+
play: (text: string) => void;
|
|
117
|
+
};
|
|
118
|
+
exitApplication: () => void;
|
|
119
|
+
setClosedCaptionHandler: (
|
|
120
|
+
callback: (isCCEnabled: boolean) => void
|
|
121
|
+
) => void;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Platforms found in userAgent string, please note that simulators
|
|
128
|
+
* might not have the same agents that the devices have
|
|
129
|
+
*/
|
|
130
|
+
export const PLATFORMS = {
|
|
131
|
+
webos: "Web0S",
|
|
132
|
+
tizen: "Tizen",
|
|
133
|
+
samsung: "SMART-TV",
|
|
134
|
+
mac: "Mac",
|
|
135
|
+
win: "Win",
|
|
136
|
+
linux: "Linux",
|
|
137
|
+
iphone: "iPhone",
|
|
138
|
+
android: "Android",
|
|
139
|
+
mobile: "Mobile",
|
|
140
|
+
vizio: "VIZIO",
|
|
141
|
+
smartcast: "SmartCast",
|
|
142
|
+
conjure: "Conjure",
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Simple way of identifying if we have access to the tizen APIs
|
|
147
|
+
*/
|
|
148
|
+
export const hasTizen = typeof window?.tizen !== "undefined";
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Simple way of identifying if we have access to the webOS APIs
|
|
152
|
+
*/
|
|
153
|
+
export const hasWebOS = typeof window?.webOS !== "undefined";
|
|
154
|
+
|
|
155
|
+
export const getUserAgent = () => window?.navigator?.userAgent;
|
|
156
|
+
|
|
157
|
+
export const isLgPlatform = () => {
|
|
158
|
+
const userAgent = getUserAgent();
|
|
159
|
+
|
|
160
|
+
if (!userAgent) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Note: LG uses the number 0 in their userAgent, possibly because of Palm WebOS
|
|
165
|
+
return hasWebOS || userAgent.includes(PLATFORMS.webos);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const isSamsungPlatform = () => {
|
|
169
|
+
const userAgent = getUserAgent();
|
|
170
|
+
|
|
171
|
+
if (!userAgent) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
hasTizen ||
|
|
177
|
+
userAgent.includes(PLATFORMS.samsung) ||
|
|
178
|
+
userAgent.includes(PLATFORMS.tizen)
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Checks if we are on the Vizio platform by using the userAgent string
|
|
184
|
+
*
|
|
185
|
+
* Use this method when you need to identify the platform on runtime
|
|
186
|
+
* before the VIZIO Companion Library has loaded
|
|
187
|
+
*/
|
|
188
|
+
export const isVizioPlatform = () => {
|
|
189
|
+
const userAgent = getUserAgent();
|
|
190
|
+
|
|
191
|
+
if (!userAgent) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const isVizioAgent =
|
|
196
|
+
userAgent.includes(PLATFORMS.vizio) ||
|
|
197
|
+
userAgent.includes(PLATFORMS.smartcast) ||
|
|
198
|
+
userAgent.includes(PLATFORMS.conjure);
|
|
199
|
+
|
|
200
|
+
return isVizioAgent;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Checks if we are on the Vizio platform by checking for the global VIZIO object
|
|
205
|
+
* and the VIZIO Companion Library. This method does not use the userAgent string,
|
|
206
|
+
* because it mainly checks whether we have access to apis, which may not be available yet
|
|
207
|
+
*/
|
|
208
|
+
export const hasVizioAPIs = () => {
|
|
209
|
+
const hasAPIs =
|
|
210
|
+
typeof window.VIZIO !== "undefined" &&
|
|
211
|
+
window?.applicaster?.vizioLibraryDidLoad;
|
|
212
|
+
|
|
213
|
+
return hasAPIs;
|
|
214
|
+
};
|
|
@@ -3,7 +3,7 @@ import { NativeModules, StyleSheet, View } from "react-native";
|
|
|
3
3
|
import { getXray } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
4
|
|
|
5
5
|
import { isApplePlatform, isWeb } from "../reactUtils";
|
|
6
|
-
import {
|
|
6
|
+
import { useRivers } from "../reactHooks/state";
|
|
7
7
|
|
|
8
8
|
const layoutReducer = (state, { payload }) => {
|
|
9
9
|
return state.map((item, index, _state) => ({
|
|
@@ -58,7 +58,7 @@ export const ScreenLoadingMeasurements = ({
|
|
|
58
58
|
numberOfComponents,
|
|
59
59
|
riverId,
|
|
60
60
|
}: Props) => {
|
|
61
|
-
const
|
|
61
|
+
const rivers = useRivers();
|
|
62
62
|
const screenData = rivers?.[riverId];
|
|
63
63
|
|
|
64
64
|
const [itemsLayout, dispatchItemLayout] = React.useReducer(
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_STORAGE_NAMESPACE,
|
|
3
|
+
getWebStorageKey,
|
|
4
|
+
NAMESPACE_STORAGE_SEPARATOR_WEB,
|
|
5
|
+
} from "./storageWebUtils.web";
|
|
6
|
+
|
|
7
|
+
export function saveSync(
|
|
8
|
+
key: string,
|
|
9
|
+
value: string,
|
|
10
|
+
namespace: string = DEFAULT_STORAGE_NAMESPACE
|
|
11
|
+
) {
|
|
12
|
+
const storageWebKey = getWebStorageKey(key, namespace);
|
|
13
|
+
|
|
14
|
+
return localStorage.setItem(storageWebKey, value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getSync(
|
|
18
|
+
key: string,
|
|
19
|
+
namespace: string = DEFAULT_STORAGE_NAMESPACE
|
|
20
|
+
) {
|
|
21
|
+
const storageWebKey = getWebStorageKey(key, namespace);
|
|
22
|
+
|
|
23
|
+
return localStorage.getItem(storageWebKey);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getAllSync(namespace: string = DEFAULT_STORAGE_NAMESPACE) {
|
|
27
|
+
const allItems = {};
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
30
|
+
const key = localStorage.key(i);
|
|
31
|
+
|
|
32
|
+
if (key && key.startsWith(namespace + NAMESPACE_STORAGE_SEPARATOR_WEB)) {
|
|
33
|
+
const itemKey = key.split(NAMESPACE_STORAGE_SEPARATOR_WEB)[1];
|
|
34
|
+
allItems[itemKey] = localStorage.getItem(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return allItems;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function removeSync(
|
|
42
|
+
key: string,
|
|
43
|
+
namespace: string = DEFAULT_STORAGE_NAMESPACE
|
|
44
|
+
) {
|
|
45
|
+
const storageWebKey = getWebStorageKey(key, namespace);
|
|
46
|
+
|
|
47
|
+
return localStorage.removeItem(storageWebKey);
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_STORAGE_NAMESPACE,
|
|
3
|
+
getWebStorageKey,
|
|
4
|
+
} from "./storageWebUtils.web";
|
|
5
|
+
|
|
6
|
+
export function saveSync(
|
|
7
|
+
key: string,
|
|
8
|
+
value: string,
|
|
9
|
+
namespace: string = DEFAULT_STORAGE_NAMESPACE
|
|
10
|
+
) {
|
|
11
|
+
const storageWebKey = getWebStorageKey(key, namespace);
|
|
12
|
+
|
|
13
|
+
return sessionStorage.setItem(storageWebKey, value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getSync(
|
|
17
|
+
key: string,
|
|
18
|
+
namespace: string = DEFAULT_STORAGE_NAMESPACE
|
|
19
|
+
) {
|
|
20
|
+
const storageWebKey = getWebStorageKey(key, namespace);
|
|
21
|
+
|
|
22
|
+
return sessionStorage.getItem(storageWebKey);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function removeSync(
|
|
26
|
+
key: string,
|
|
27
|
+
namespace: string = DEFAULT_STORAGE_NAMESPACE
|
|
28
|
+
) {
|
|
29
|
+
const storageWebKey = getWebStorageKey(key, namespace);
|
|
30
|
+
|
|
31
|
+
return sessionStorage.removeItem(storageWebKey);
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DEFAULT_STORAGE_NAMESPACE } from "./storageWebUtils.web";
|
|
2
|
+
import { getSync as getLocalStorage } from "./localStorageServiceSync.web";
|
|
3
|
+
import { getSync as getSessionStorage } from "./sessionStorageServiceSync.web";
|
|
4
|
+
|
|
5
|
+
export const getFromSessionOrLocalStorage = (
|
|
6
|
+
key: string,
|
|
7
|
+
namespace: string = DEFAULT_STORAGE_NAMESPACE
|
|
8
|
+
) => getSessionStorage(key, namespace) || getLocalStorage(key, namespace);
|
|
9
|
+
|
|
10
|
+
export const resolveStorageContextKey = (storageKey: string) => {
|
|
11
|
+
if (!storageKey) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const splitKey = storageKey.split(".");
|
|
16
|
+
const namespaceOrKey = splitKey[0];
|
|
17
|
+
const key = splitKey[1];
|
|
18
|
+
|
|
19
|
+
if (!key) {
|
|
20
|
+
return getFromSessionOrLocalStorage(key);
|
|
21
|
+
} else {
|
|
22
|
+
return getFromSessionOrLocalStorage(key, namespaceOrKey);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const DEFAULT_STORAGE_NAMESPACE = "applicaster.v2";
|
|
2
|
+
|
|
3
|
+
export const NAMESPACE_STORAGE_SEPARATOR_WEB = "_::_";
|
|
4
|
+
|
|
5
|
+
export const getWebStorageKey = (
|
|
6
|
+
key: String,
|
|
7
|
+
namespace: String = DEFAULT_STORAGE_NAMESPACE
|
|
8
|
+
) => {
|
|
9
|
+
return `${namespace}${NAMESPACE_STORAGE_SEPARATOR_WEB}${key}`;
|
|
10
|
+
};
|
package/stringUtils/index.ts
CHANGED
|
@@ -152,3 +152,8 @@ export function objectToCamelCase(obj) {
|
|
|
152
152
|
export function isString(value: unknown): value is string {
|
|
153
153
|
return typeof value === "string" || value instanceof String;
|
|
154
154
|
}
|
|
155
|
+
|
|
156
|
+
/** Checks if a value is a non-empty string */
|
|
157
|
+
export function isNotEmptyString(value: unknown): value is string {
|
|
158
|
+
return isString(value) && value.length > 0;
|
|
159
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const getByTestId = (wrapper, testId) => {
|
|
2
|
+
try {
|
|
3
|
+
if (wrapper?.getByTestId) {
|
|
4
|
+
return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
|
|
5
|
+
} else if (wrapper?.root?.findByProps) {
|
|
6
|
+
return wrapper.root.findAllByProps({ testID: testId })?.[0] ?? undefined;
|
|
7
|
+
}
|
|
8
|
+
} catch (e) {
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
console.log("getByTestId E:", e);
|
|
11
|
+
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
package/testUtils/index.tsx
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
|
|
3
|
-
import React from "react";
|
|
3
|
+
import React, { PropsWithChildren } from "react";
|
|
4
4
|
import { View } from "react-native";
|
|
5
5
|
|
|
6
6
|
import { Provider } from "react-redux";
|
|
7
7
|
import thunk from "redux-thunk";
|
|
8
8
|
import configureStore from "redux-mock-store";
|
|
9
|
+
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
10
|
+
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
9
11
|
|
|
10
12
|
import { render } from "@testing-library/react-native";
|
|
13
|
+
import { AnalyticsProvider } from "../analyticsUtils";
|
|
14
|
+
import { ThemeContext } from "../theme";
|
|
15
|
+
|
|
16
|
+
export { getByTestId } from "./getByTestId";
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
|
|
@@ -19,17 +25,6 @@ import { render } from "@testing-library/react-native";
|
|
|
19
25
|
export const testIDEquals = (testId: any): boolean =>
|
|
20
26
|
R.compose(R.equals(testId), R.invoker(1, "prop")("testID"));
|
|
21
27
|
|
|
22
|
-
export const getByTestId = (wrapper, testId) => {
|
|
23
|
-
try {
|
|
24
|
-
return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
|
|
25
|
-
} catch (e) {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.log("getByTestId E:", e);
|
|
28
|
-
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
28
|
/** Helper function for react-test-renderer, accepts type and renderer
|
|
34
29
|
* * @param {*} type React Component type instance or name of component
|
|
35
30
|
* * @param {*} renderer renderer instance
|
|
@@ -45,11 +40,11 @@ export const findByType = (type, renderer) => {
|
|
|
45
40
|
export function createComponentMock(mockName, hasChildren = false) {
|
|
46
41
|
return hasChildren
|
|
47
42
|
? jest.fn(({ children }) => (
|
|
48
|
-
<View
|
|
43
|
+
<View testID={mockName}>
|
|
49
44
|
{typeof children === "function" ? children() : children}
|
|
50
45
|
</View>
|
|
51
46
|
))
|
|
52
|
-
: jest.fn(() => <View
|
|
47
|
+
: jest.fn(() => <View testID={mockName} />);
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
const initialState = {
|
|
@@ -62,16 +57,65 @@ const initialState = {
|
|
|
62
57
|
AppContainer: createComponentMock("appContainer", true),
|
|
63
58
|
DisplayError: createComponentMock("displayError"),
|
|
64
59
|
},
|
|
65
|
-
rivers:
|
|
60
|
+
rivers: { id: "A1234", home: true },
|
|
66
61
|
appSettings: {},
|
|
67
62
|
plugins: [],
|
|
68
|
-
appState: { appReady: true },
|
|
63
|
+
appState: { appReady: true, appLaunched: true },
|
|
64
|
+
pluginConfigurations: {},
|
|
65
|
+
appData: { layoutVersion: "v1" },
|
|
66
|
+
zappPipes: {},
|
|
67
|
+
contentTypes: null,
|
|
69
68
|
};
|
|
70
69
|
|
|
71
|
-
export const WrappedWithProviders = ({
|
|
72
|
-
|
|
70
|
+
export const WrappedWithProviders = ({
|
|
71
|
+
children,
|
|
72
|
+
store: storeObj = {},
|
|
73
|
+
}: any) => {
|
|
74
|
+
const _store = configureStore([thunk])(
|
|
75
|
+
R.mergeDeepRight(initialState, { ...storeObj })
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
appStore.set(_store);
|
|
73
79
|
|
|
74
|
-
return
|
|
80
|
+
return (
|
|
81
|
+
<ThemeContext.Provider
|
|
82
|
+
value={{
|
|
83
|
+
themes: {
|
|
84
|
+
light: {
|
|
85
|
+
component_margin_top: 0,
|
|
86
|
+
component_margin_bottom: 0,
|
|
87
|
+
component_margin_left: 0,
|
|
88
|
+
component_margin_right: 0,
|
|
89
|
+
component_padding_top: 0,
|
|
90
|
+
component_padding_bottom: 0,
|
|
91
|
+
component_padding_left: 0,
|
|
92
|
+
component_padding_right: 0,
|
|
93
|
+
component_gutter_vertical: 0,
|
|
94
|
+
component_gutter_horizontal: 0,
|
|
95
|
+
component_corner_radius: 0,
|
|
96
|
+
app_background_color: "rgba(0,0,0,0)",
|
|
97
|
+
screen_margin_top: 0,
|
|
98
|
+
screen_margin_bottom: 0,
|
|
99
|
+
component_anchor_point_y: 0,
|
|
100
|
+
assets: "",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
selectedThemeId: "light",
|
|
104
|
+
setSelectedThemeId: () => {},
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
<SafeAreaProvider
|
|
108
|
+
initialMetrics={{
|
|
109
|
+
insets: { top: 0, left: 0, right: 0, bottom: 0 },
|
|
110
|
+
frame: { x: 0, y: 0, width: 0, height: 0 },
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<Provider store={_store}>
|
|
114
|
+
<AnalyticsProvider>{children}</AnalyticsProvider>
|
|
115
|
+
</Provider>
|
|
116
|
+
</SafeAreaProvider>
|
|
117
|
+
</ThemeContext.Provider>
|
|
118
|
+
);
|
|
75
119
|
};
|
|
76
120
|
|
|
77
121
|
/**
|
|
@@ -80,8 +124,12 @@ export const WrappedWithProviders = ({ children, store = {} }: any) => {
|
|
|
80
124
|
* @param store optional store to pass to the provider
|
|
81
125
|
* @returns
|
|
82
126
|
*/
|
|
83
|
-
export const renderWithProviders = (component,
|
|
84
|
-
return render(
|
|
85
|
-
|
|
86
|
-
|
|
127
|
+
export const renderWithProviders = (component, storeObj?: unknown) => {
|
|
128
|
+
return render(component, {
|
|
129
|
+
wrapper: function TestWrapper({ children }: PropsWithChildren<any>) {
|
|
130
|
+
return (
|
|
131
|
+
<WrappedWithProviders store={storeObj}>{children}</WrappedWithProviders>
|
|
132
|
+
);
|
|
133
|
+
},
|
|
134
|
+
});
|
|
87
135
|
};
|
package/types.ts
CHANGED