@applicaster/zapp-react-native-utils 13.0.0-alpha.3244448100 → 13.0.0-alpha.3285365953
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/README.md +0 -10
- package/actionsExecutor/ActionExecutor.ts +16 -9
- package/actionsExecutor/ActionExecutorContext.tsx +74 -9
- package/alertUtils/alert.ts +148 -0
- package/alertUtils/index.ts +1 -148
- package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
- package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
- package/analyticsUtils/currentScreenProperities.ts +6 -4
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/appUtils/HooksManager/{Hook.js → Hook.ts} +35 -23
- package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +10 -8
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +693 -0
- package/appUtils/HooksManager/__tests__/hook.test.js +196 -184
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +96 -99
- package/appUtils/HooksManager/{constants.js → constants.ts} +1 -1
- package/appUtils/HooksManager/{index.js → index.ts} +122 -113
- package/appUtils/HooksManager/types.ts +119 -0
- package/appUtils/RiverFocusManager/index.js +17 -12
- package/appUtils/accessibilityManager/index.ts +42 -1
- package/appUtils/contextKeysManager/contextResolver.ts +66 -0
- package/appUtils/contextKeysManager/index.ts +2 -2
- package/appUtils/contextKeysManager/utils/index.ts +2 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +7 -6
- package/appUtils/focusManager/index.ts +100 -74
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +25 -3
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -3
- package/appUtils/focusManager/utils/enums.ts +4 -0
- package/appUtils/focusManagerAux/utils/index.ts +4 -3
- package/appUtils/{index.js → index.ts} +1 -1
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +4 -4
- package/appUtils/keyCodes/{index.js → index.ts} +13 -7
- package/appUtils/keyCodes/keys/index.ts +3 -0
- package/appUtils/keyCodes/{keys.android.js → keys/keyEventMapper.ts} +0 -19
- package/appUtils/keyCodes/keys/keys.android.ts +18 -0
- package/appUtils/keyCodes/keys/keys.ios.ts +25 -0
- package/appUtils/keyCodes/keys/keys.ts +15 -0
- package/appUtils/keyCodes/keysByPlatform.ts +8 -0
- package/appUtils/orientationHelper.ts +11 -13
- package/appUtils/platform/const.ts +14 -0
- package/appUtils/platform/platformUtils.ts +47 -18
- package/appUtils/playerManager/index.ts +1 -1
- package/appUtils/playerManager/player.ts +26 -14
- package/appUtils/playerManager/playerNative.ts +19 -4
- package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
- package/domUtils/{cookieManager.js → cookieManager.ts} +1 -2
- package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
- package/equalUtils/index.ts +49 -30
- package/focusManager/FocusManager.ts +11 -1
- package/focusManager/index.ts +49 -4
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
- package/functionUtils/index.ts +36 -19
- package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
- package/idleUtils/index.ts +1 -1
- package/idleUtils/withTimeout.ts +15 -2
- package/logger/const.ts +9 -67
- package/manifestUtils/__tests__/createConfig.test.js +16 -16
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- package/manifestUtils/fonts/index.js +5 -6
- package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
- package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
- package/modalState/index.ts +1 -5
- package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
- package/navigationUtils/__tests__/itemTypes.test.js +2 -2
- package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
- package/navigationUtils/index.ts +17 -8
- package/numberUtils/index.ts +7 -5
- package/package.json +5 -10
- package/playerUtils/configurationGenerator.ts +8 -0
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
- package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
- package/reactHooks/cell-click/__tests__/index.test.js +10 -2
- package/reactHooks/cell-click/index.ts +7 -1
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
- package/reactHooks/feed/useFeedLoader.tsx +5 -3
- package/reactHooks/feed/usePipesCacheReset.ts +5 -5
- package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
- package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
- package/reactHooks/layout/__tests__/index.test.tsx +10 -10
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
- package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
- package/reactHooks/navigation/index.ts +41 -240
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
- package/reactHooks/navigation/useGetTabBarHeight.ts +10 -0
- package/reactHooks/navigation/useIsScreenActive.ts +17 -0
- package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
- package/reactHooks/navigation/useNavigationType.ts +15 -0
- package/reactHooks/navigation/usePathname.ts +4 -0
- package/reactHooks/navigation/useProfilerLogging.ts +15 -0
- package/reactHooks/navigation/useRoute.ts +98 -0
- package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
- package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +0 -4
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +6 -8
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +115 -0
- package/reactHooks/player/__tests__/useTapSeek._test.ts +94 -0
- package/reactHooks/state/useRefWithInitialValue.ts +14 -0
- package/reactHooks/state/useStateFromSubscribe.ts +23 -0
- package/reactHooks/usePluginConfiguration.ts +1 -1
- package/reactHooks/useSubscriberFor.ts +4 -3
- package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
- package/reactUtils/__tests__/reactUtils.test.js +1 -37
- package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
- package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
- package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
- package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
- package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
- package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
- package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
- package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
- package/reactUtils/createContext/__tests__/provider.test.js +4 -6
- package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
- package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
- package/reactUtils/createContext/helpers.ts +6 -1
- package/reactUtils/createContext/index.ts +11 -25
- package/reactUtils/index.ts +0 -25
- package/screenState/index.ts +24 -10
- package/services/js2native.ts +673 -0
- package/testUtils/index.tsx +0 -10
- package/theme/__mocks__/index.ts +4 -0
- package/theme/index.ts +1 -1
- package/time/BackgroundTimer.ts +55 -0
- package/time/Timer.ts +9 -6
- package/types.ts +1 -0
- package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
- package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
- package/appUtils/keyCodes/keys.ios.js +0 -46
- package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
- /package/appUtils/HooksManager/{logger.js → logger.ts} +0 -0
- /package/appUtils/{directionHelper.js → directionHelper.ts} +0 -0
- /package/appUtils/keyCodes/{androidTVKeys.js → androidTVKeys.ts} +0 -0
- /package/appUtils/keyCodes/{keys.web.js → keys/keys.web.ts} +0 -0
- /package/appUtils/keyCodes/{keysByPlatform.js → keys/keysByPlatform.ts} +0 -0
- /package/appUtils/{localizationsHelper.js → localizationsHelper.ts} +0 -0
- /package/domUtils/{logger.js → logger.ts} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
|
|
3
|
+
|
|
4
|
+
import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
5
|
+
|
|
6
|
+
import { useAutoSeek } from "../useAutoSeek";
|
|
7
|
+
|
|
8
|
+
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
9
|
+
|
|
10
|
+
const rewind = jest.fn();
|
|
11
|
+
const forward = jest.fn();
|
|
12
|
+
|
|
13
|
+
jest
|
|
14
|
+
.spyOn(playerManager, "getInstanceController")
|
|
15
|
+
.mockReturnValue({ rewind, forward });
|
|
16
|
+
|
|
17
|
+
describe("useAutoSeek", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
rewind.mockReset();
|
|
20
|
+
forward.mockReset();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("autoSeekStart", () => {
|
|
24
|
+
it("should call forward method on playerInstance", () => {
|
|
25
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
26
|
+
|
|
27
|
+
act(() => {
|
|
28
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
expect(forward).toBeCalled();
|
|
32
|
+
result.current.autoSeekStop();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should call rewind method on playerManager", () => {
|
|
36
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
37
|
+
|
|
38
|
+
act(() => {
|
|
39
|
+
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(rewind).toBeCalled();
|
|
43
|
+
result.current.autoSeekStop();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should call rewind with default skip time", () => {
|
|
47
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
48
|
+
|
|
49
|
+
act(() => {
|
|
50
|
+
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
54
|
+
result.current.autoSeekStop();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should call forward with default skip time", () => {
|
|
58
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
59
|
+
|
|
60
|
+
act(() => {
|
|
61
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
65
|
+
result.current.autoSeekStop();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should call rewind in intervals set in configuration", () => {
|
|
69
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
70
|
+
|
|
71
|
+
act(() => {
|
|
72
|
+
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(rewind).toBeCalled();
|
|
76
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
77
|
+
expect(rewind).toBeCalledTimes(4);
|
|
78
|
+
result.current.autoSeekStop();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should call forward in intervals set in configuration", () => {
|
|
82
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
83
|
+
|
|
84
|
+
act(() => {
|
|
85
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(forward).toBeCalled();
|
|
89
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
90
|
+
expect(forward).toBeCalledTimes(4);
|
|
91
|
+
result.current.autoSeekStop();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("autoSeekStop", () => {
|
|
96
|
+
it("should stop calling playerManager method after autoSeekStop is called", () => {
|
|
97
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
98
|
+
|
|
99
|
+
act(() => {
|
|
100
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(forward).toBeCalled();
|
|
104
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
105
|
+
expect(forward).toBeCalledTimes(4);
|
|
106
|
+
|
|
107
|
+
act(() => {
|
|
108
|
+
result.current.autoSeekStop();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
112
|
+
expect(forward).toBeCalledTimes(4);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
|
|
3
|
+
import { useTapSeek } from "../useTapSeek";
|
|
4
|
+
|
|
5
|
+
import { ON_PRESS_RESET_DURATION, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
6
|
+
|
|
7
|
+
const rewind = jest.fn();
|
|
8
|
+
const forward = jest.fn();
|
|
9
|
+
|
|
10
|
+
jest
|
|
11
|
+
.spyOn(playerManager, "getInstanceController")
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
.mockImplementation(() => ({ rewind, forward }));
|
|
14
|
+
|
|
15
|
+
describe("useTapSeek", () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
rewind.mockReset();
|
|
18
|
+
forward.mockReset();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("forward", () => {
|
|
22
|
+
it("should call forward method on playerManager", () => {
|
|
23
|
+
const { result } = renderHook(() => useTapSeek());
|
|
24
|
+
|
|
25
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
26
|
+
expect(forward).toBeCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should call forward with default skip time", () => {
|
|
30
|
+
const { result } = renderHook(() => useTapSeek());
|
|
31
|
+
|
|
32
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
33
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should multiply skip time for every call", async () => {
|
|
37
|
+
const { result } = renderHook(() => useTapSeek());
|
|
38
|
+
|
|
39
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
40
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
41
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
42
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should reset multiplier if waiting more then resetDuration between press actions", () => {
|
|
46
|
+
const { result, waitFor } = renderHook(() => useTapSeek());
|
|
47
|
+
|
|
48
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
49
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
50
|
+
waitFor(jest.fn(), { timeout: ON_PRESS_RESET_DURATION });
|
|
51
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
52
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("rewind", () => {
|
|
57
|
+
it("should call rewind method on playerManager", () => {
|
|
58
|
+
const { result } = renderHook(() => useTapSeek());
|
|
59
|
+
|
|
60
|
+
result.current(SEEK_TYPE.REWIND);
|
|
61
|
+
expect(rewind).toBeCalled();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should call rewind with default skip time", () => {
|
|
65
|
+
const { result } = renderHook(() => useTapSeek());
|
|
66
|
+
|
|
67
|
+
result.current(SEEK_TYPE.REWIND);
|
|
68
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should multiply skip time for every call", async () => {
|
|
72
|
+
const { result } = renderHook(() => useTapSeek());
|
|
73
|
+
|
|
74
|
+
result.current(SEEK_TYPE.REWIND);
|
|
75
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
76
|
+
result.current(SEEK_TYPE.REWIND);
|
|
77
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("mixed usage", () => {
|
|
82
|
+
it("should reset timer if different type of event is emitted", () => {
|
|
83
|
+
const { result } = renderHook(() => useTapSeek());
|
|
84
|
+
result.current(SEEK_TYPE.REWIND);
|
|
85
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
86
|
+
|
|
87
|
+
result.current(SEEK_TYPE.REWIND);
|
|
88
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
89
|
+
|
|
90
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
91
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* returns a ref with an initial value that is lazily evaluated once
|
|
5
|
+
* */
|
|
6
|
+
export const useRefWithInitialValue = <T>(initialValueGetter: () => T) => {
|
|
7
|
+
const ref = React.useRef<T>(null);
|
|
8
|
+
|
|
9
|
+
if (ref.current === null) {
|
|
10
|
+
ref.current = initialValueGetter();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return ref;
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import type { Subject } from "rxjs";
|
|
3
|
+
|
|
4
|
+
export const useStateFromSubscribe = <T, U>(
|
|
5
|
+
subject: Subject<T>,
|
|
6
|
+
onUpdate: (
|
|
7
|
+
observerValue: T,
|
|
8
|
+
next: React.Dispatch<React.SetStateAction<U>>
|
|
9
|
+
) => void,
|
|
10
|
+
initialValue: U
|
|
11
|
+
) => {
|
|
12
|
+
const [state, setState] = useState<U>(initialValue);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const subscription = subject.subscribe((observer) =>
|
|
16
|
+
onUpdate(observer, setState)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return () => subscription.unsubscribe();
|
|
20
|
+
}, [subject]);
|
|
21
|
+
|
|
22
|
+
return state;
|
|
23
|
+
};
|
|
@@ -4,9 +4,10 @@ import { subscriber } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
|
4
4
|
const subscriberObjects = Object.create({});
|
|
5
5
|
|
|
6
6
|
interface UseSubscriberFor {
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
(
|
|
8
|
+
eventName: string,
|
|
9
|
+
handler?: (...args: unknown[]) => void
|
|
10
|
+
): (...args: unknown[]) => ReturnType<typeof subscriber>;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`addLifeCycleMethods attaches the lifecycle method to the component 1`] = `
|
|
3
|
+
exports[`reactUtils helpers addLifeCycleMethods attaches the lifecycle method to the component 1`] = `
|
|
4
4
|
<View>
|
|
5
5
|
<Text>
|
|
6
6
|
I'm a class component
|
|
@@ -8,7 +8,7 @@ exports[`addLifeCycleMethods attaches the lifecycle method to the component 1`]
|
|
|
8
8
|
</View>
|
|
9
9
|
`;
|
|
10
10
|
|
|
11
|
-
exports[`attachMethodToPrototype attaches a lifecycle method to the component's prototype 1`] = `
|
|
11
|
+
exports[`reactUtils helpers attachMethodToPrototype attaches a lifecycle method to the component's prototype 1`] = `
|
|
12
12
|
<View>
|
|
13
13
|
<Text>
|
|
14
14
|
I'm a class component
|
|
@@ -16,6 +16,18 @@ exports[`attachMethodToPrototype attaches a lifecycle method to the component's
|
|
|
16
16
|
</View>
|
|
17
17
|
`;
|
|
18
18
|
|
|
19
|
-
exports[`attachMethodToPrototype preserves any existing lifecycle method 1`] =
|
|
19
|
+
exports[`reactUtils helpers attachMethodToPrototype preserves any existing lifecycle method 1`] = `
|
|
20
|
+
<View>
|
|
21
|
+
<Text>
|
|
22
|
+
I'm a stateless component
|
|
23
|
+
</Text>
|
|
24
|
+
</View>
|
|
25
|
+
`;
|
|
20
26
|
|
|
21
|
-
exports[`wrapInClass wraps the stateless component in a class 1`] =
|
|
27
|
+
exports[`reactUtils helpers wrapInClass wraps the stateless component in a class 1`] = `
|
|
28
|
+
<View>
|
|
29
|
+
<Text>
|
|
30
|
+
I'm a stateless component
|
|
31
|
+
</Text>
|
|
32
|
+
</View>
|
|
33
|
+
`;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
jest.mock("create-react-ref/lib/createRef", () => jest.fn());
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import * as helpers from "../helpers";
|
|
4
3
|
|
|
@@ -8,13 +7,7 @@ import {
|
|
|
8
7
|
componentDidMount,
|
|
9
8
|
} from "./fixtures";
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
attachLifeCycleMethods,
|
|
13
|
-
createReactRef,
|
|
14
|
-
mergeChildrenProps,
|
|
15
|
-
} = require("../index");
|
|
16
|
-
|
|
17
|
-
const createRef = require("create-react-ref/lib/createRef");
|
|
10
|
+
import { attachLifeCycleMethods, mergeChildrenProps } from "..";
|
|
18
11
|
|
|
19
12
|
describe("attachLifeCycleMethods", () => {
|
|
20
13
|
let addLifeCycleMethodsSpy;
|
|
@@ -48,35 +41,6 @@ describe("attachLifeCycleMethods", () => {
|
|
|
48
41
|
});
|
|
49
42
|
});
|
|
50
43
|
|
|
51
|
-
describe("createReactRef", () => {
|
|
52
|
-
it("calls the React.createRef function if it exists", () => {
|
|
53
|
-
jest.resetModules();
|
|
54
|
-
|
|
55
|
-
jest.doMock("react", () => ({
|
|
56
|
-
...jest.requireActual("react"),
|
|
57
|
-
createRef: jest.fn(),
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
const React = require("react");
|
|
61
|
-
|
|
62
|
-
createReactRef();
|
|
63
|
-
expect(React.createRef).toHaveBeenCalled();
|
|
64
|
-
expect(createRef).not.toHaveBeenCalled();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("calls the polyfill if React.createRef doesn't exist", () => {
|
|
68
|
-
jest.resetModules();
|
|
69
|
-
|
|
70
|
-
jest.doMock("react", () => ({
|
|
71
|
-
...jest.requireActual("react"),
|
|
72
|
-
createRef: undefined,
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
createReactRef();
|
|
76
|
-
expect(createRef).toHaveBeenCalled();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
44
|
describe("mergeChildrenProps", () => {
|
|
81
45
|
it("returns the cloned children with the merged props", () => {
|
|
82
46
|
const Egg = () => React.createElement("Egg");
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { shallowToJson } from "enzyme-to-json";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
4
3
|
|
|
5
4
|
import {
|
|
6
5
|
isClassComponent,
|
|
@@ -20,98 +19,100 @@ import {
|
|
|
20
19
|
} from "./fixtures";
|
|
21
20
|
|
|
22
21
|
describe("reactUtils helpers", () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
describe("isNilOrEmpty", () => {
|
|
23
|
+
it("should return correct output", () => {
|
|
24
|
+
expect(isNilOrEmpty).toBeDefined();
|
|
25
|
+
expect(isNilOrEmpty(null)).toBeTruthy();
|
|
26
|
+
expect(isNilOrEmpty(undefined)).toBeTruthy();
|
|
27
|
+
expect(isNilOrEmpty("")).toBeTruthy();
|
|
28
|
+
expect(isNilOrEmpty([])).toBeTruthy();
|
|
29
|
+
});
|
|
29
30
|
});
|
|
30
|
-
});
|
|
31
31
|
|
|
32
|
-
describe("isClassComponent", () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
describe("isClassComponent", () => {
|
|
33
|
+
it("returns true if the component is a class component", () => {
|
|
34
|
+
expect(isClassComponent(ClassComponent)).toBe(true);
|
|
35
|
+
});
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
it("returns false otherwise", () => {
|
|
38
|
+
expect(isClassComponent(StatelessComponent)).toBe(false);
|
|
39
|
+
});
|
|
39
40
|
});
|
|
40
|
-
});
|
|
41
41
|
|
|
42
|
-
describe("attachMethodToPrototype", () => {
|
|
43
|
-
|
|
42
|
+
describe("attachMethodToPrototype", () => {
|
|
43
|
+
const initialWrapper = render(<ClassComponent />);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
COMPONENT_DID_MOUNT_METHOD
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
componentDidMount.mockClear();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("attaches a lifecycle method to the component's prototype", () => {
|
|
54
|
-
const NewComponent = attachMethodToPrototype(ClassComponent)(
|
|
55
|
-
componentDidMount,
|
|
45
|
+
expect(initialWrapper.toJSON()).not.toHaveProperty(
|
|
56
46
|
COMPONENT_DID_MOUNT_METHOD
|
|
57
47
|
);
|
|
58
48
|
|
|
59
|
-
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
componentDidMount.mockClear();
|
|
51
|
+
});
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
it("attaches a lifecycle method to the component's prototype", () => {
|
|
54
|
+
const NewComponent = attachMethodToPrototype(ClassComponent)(
|
|
55
|
+
componentDidMount,
|
|
56
|
+
COMPONENT_DID_MOUNT_METHOD
|
|
57
|
+
);
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
|
|
68
|
-
componentDidMount,
|
|
69
|
-
COMPONENT_DID_MOUNT_METHOD
|
|
70
|
-
);
|
|
59
|
+
const wrapper = render(<NewComponent />);
|
|
71
60
|
|
|
72
|
-
|
|
61
|
+
expect(wrapper.toJSON(wrapper)).toMatchSnapshot();
|
|
62
|
+
expect(new NewComponent()).toHaveProperty(COMPONENT_DID_MOUNT_METHOD);
|
|
63
|
+
expect(componentDidMount).toHaveBeenCalled();
|
|
64
|
+
});
|
|
73
65
|
|
|
74
|
-
|
|
66
|
+
it("preserves any existing lifecycle method", () => {
|
|
67
|
+
const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
|
|
68
|
+
componentDidMount,
|
|
69
|
+
COMPONENT_DID_MOUNT_METHOD
|
|
70
|
+
);
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
expect(componentDidMount).toHaveBeenCalled();
|
|
78
|
-
expect(existingMethod).toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
72
|
+
expect(componentDidMount).not.toHaveBeenCalled();
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
let NewComponent;
|
|
84
|
-
let wrapper;
|
|
74
|
+
const wrapper = render(<NewComponent />);
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
77
|
+
expect(componentDidMount).toHaveBeenCalled();
|
|
78
|
+
expect(existingMethod).toHaveBeenCalled();
|
|
79
|
+
});
|
|
89
80
|
});
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
});
|
|
82
|
+
describe("wrapInClass", () => {
|
|
83
|
+
let NewComponent;
|
|
84
|
+
let wrapper;
|
|
96
85
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
NewComponent = wrapInClass(StatelessComponent);
|
|
88
|
+
wrapper = render(<NewComponent />);
|
|
89
|
+
});
|
|
100
90
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
it("wraps the stateless component in a class", () => {
|
|
92
|
+
expect(isClassComponent(NewComponent)).toBe(true);
|
|
93
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
94
|
+
});
|
|
104
95
|
});
|
|
105
96
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
97
|
+
describe("addLifeCycleMethods", () => {
|
|
98
|
+
let NewComponent;
|
|
99
|
+
let wrapper;
|
|
109
100
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
101
|
+
beforeEach(() => {
|
|
102
|
+
NewComponent = addLifeCycleMethods({ componentDidMount })(ClassComponent);
|
|
103
|
+
wrapper = render(<NewComponent />);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
componentDidMount.mockClear();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("attaches the lifecycle method to the component", () => {
|
|
111
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
112
|
+
});
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
it("adds the lifecycle method to the component", () => {
|
|
115
|
+
expect(componentDidMount).toHaveBeenCalled();
|
|
116
|
+
});
|
|
116
117
|
});
|
|
117
118
|
});
|
|
@@ -1,106 +1,40 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 1`] = `
|
|
4
|
-
|
|
3
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 1`] = `
|
|
4
|
+
{
|
|
5
5
|
"bar": "bar",
|
|
6
6
|
"foo": "foo",
|
|
7
7
|
}
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
|
|
11
|
-
|
|
12
|
-
"bar": "bar",
|
|
13
|
-
"foo": "invalid foo",
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
|
|
18
|
-
Object {
|
|
19
|
-
"bar": "invalid bar",
|
|
20
|
-
"foo": "invalid foo",
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
|
|
25
|
-
Array [
|
|
26
|
-
Array [
|
|
27
|
-
[Function],
|
|
28
|
-
],
|
|
29
|
-
Array [
|
|
30
|
-
[Function],
|
|
31
|
-
],
|
|
32
|
-
]
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 1`] = `
|
|
36
|
-
Object {
|
|
10
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
|
|
11
|
+
{
|
|
37
12
|
"bar": "bar",
|
|
38
13
|
"foo": "foo",
|
|
39
14
|
}
|
|
40
15
|
`;
|
|
41
16
|
|
|
42
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called
|
|
43
|
-
|
|
17
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
|
|
18
|
+
{
|
|
44
19
|
"bar": "bar",
|
|
45
|
-
"foo": "
|
|
46
|
-
}
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 3`] = `
|
|
50
|
-
Object {
|
|
51
|
-
"bar": "new bar",
|
|
52
|
-
"foo": "new foo",
|
|
20
|
+
"foo": "foo",
|
|
53
21
|
}
|
|
54
22
|
`;
|
|
55
23
|
|
|
56
|
-
exports[`createContextSetters when state validator is provided calls setState when the setters are called
|
|
57
|
-
|
|
58
|
-
|
|
24
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
|
|
25
|
+
[
|
|
26
|
+
[
|
|
59
27
|
[Function],
|
|
60
28
|
],
|
|
61
|
-
|
|
29
|
+
[
|
|
62
30
|
[Function],
|
|
63
31
|
],
|
|
64
32
|
]
|
|
65
33
|
`;
|
|
66
34
|
|
|
67
|
-
exports[`createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
|
|
68
|
-
|
|
35
|
+
exports[`helpers createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
|
|
36
|
+
{
|
|
69
37
|
"bar": "bar",
|
|
70
38
|
"foo": "new foo",
|
|
71
39
|
}
|
|
72
40
|
`;
|
|
73
|
-
|
|
74
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 1`] = `
|
|
75
|
-
Object {
|
|
76
|
-
"bar": "bar",
|
|
77
|
-
"foo": "foo",
|
|
78
|
-
}
|
|
79
|
-
`;
|
|
80
|
-
|
|
81
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 2`] = `
|
|
82
|
-
Object {
|
|
83
|
-
"bar": "bar",
|
|
84
|
-
"foo": "foo",
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
87
|
-
|
|
88
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 3`] = `
|
|
89
|
-
Object {
|
|
90
|
-
"bar": "bar",
|
|
91
|
-
"foo": "foo",
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
94
|
-
|
|
95
|
-
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 4`] = `
|
|
96
|
-
Array [
|
|
97
|
-
Array [
|
|
98
|
-
"trying to invoke setFoo with invalid foo - but it was rejected by the state validator
|
|
99
|
-
skipping context update",
|
|
100
|
-
],
|
|
101
|
-
Array [
|
|
102
|
-
"trying to invoke setBar with invalid bar - but it was rejected by the state validator
|
|
103
|
-
skipping context update",
|
|
104
|
-
],
|
|
105
|
-
]
|
|
106
|
-
`;
|
package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`createContext - when React has the new context API returns the components and the decorators 1`] = `
|
|
4
|
-
|
|
4
|
+
{
|
|
5
5
|
"Consumer": [MockFunction],
|
|
6
6
|
"Provider": [MockFunction],
|
|
7
|
-
"ReactContext":
|
|
7
|
+
"ReactContext": {
|
|
8
8
|
"Consumer": [MockFunction],
|
|
9
9
|
"Provider": [MockFunction],
|
|
10
10
|
},
|