@applicaster/zapp-react-native-utils 13.0.0-alpha.5718191297 → 13.0.0-alpha.5771418585
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/appUtils/contextKeysManager/index.ts +2 -2
- package/appUtils/contextKeysManager/utils/index.ts +2 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
- package/appUtils/focusManager/index.ts +9 -0
- package/appUtils/platform/platformUtils.ts +6 -0
- package/appUtils/playerManager/player.ts +8 -7
- package/appUtils/playerManager/playerNative.ts +5 -5
- package/equalUtils/index.ts +10 -3
- package/focusManager/FocusManager.ts +11 -1
- package/package.json +2 -2
- package/reactHooks/navigation/index.ts +7 -19
- package/reactHooks/navigation/useProfilerLogging.ts +15 -0
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +40 -13
- package/reactHooks/player/TVSeekControlller/TapSeekController.ts +10 -3
- package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
- package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
- package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +6 -72
- 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__/provider.test.js +4 -6
- package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
- package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
- package/testUtils/index.tsx +0 -10
package/README.md
CHANGED
|
@@ -376,16 +376,6 @@ useEffect(() => {
|
|
|
376
376
|
}, []);
|
|
377
377
|
```
|
|
378
378
|
|
|
379
|
-
### testUtils
|
|
380
|
-
|
|
381
|
-
`@applicaster/zapp-react-native-utils/testUtils`
|
|
382
|
-
|
|
383
|
-
- `testIDEquals: (testId: any) => boolean | { width: number, height: number }` - Function to be used in tandem with enzyme findWhere
|
|
384
|
-
|
|
385
|
-
```javascript
|
|
386
|
-
wrapper.findWhere(testIDEquals("text"));
|
|
387
|
-
```
|
|
388
|
-
|
|
389
379
|
### appUtils - contextKeysManager
|
|
390
380
|
|
|
391
381
|
`@applicaster/zapp-react-native-utils/appUtils/contextKeyManager`
|
|
@@ -16,12 +16,12 @@ import {
|
|
|
16
16
|
|
|
17
17
|
export { StorageLevel };
|
|
18
18
|
|
|
19
|
-
type KeyNameObj = {
|
|
19
|
+
export type KeyNameObj = {
|
|
20
20
|
namespace: string;
|
|
21
21
|
key: string;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
type KeyName = string | KeyNameObj;
|
|
24
|
+
export type KeyName = string | KeyNameObj;
|
|
25
25
|
|
|
26
26
|
type ParsedKeyAndNamespace = {
|
|
27
27
|
namespace?: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { DEFAULT_NAMESPACE } from "../consts";
|
|
3
|
+
import { KeyName, KeyNameObj } from "../index";
|
|
3
4
|
|
|
4
5
|
const lastDotRegex = /\.([^.]+)$/;
|
|
5
6
|
const splitByLastDot = R.compose(R.init, R.split(lastDotRegex));
|
|
6
7
|
|
|
7
|
-
export function getNamespaceAndKey(namespacedKey) {
|
|
8
|
+
export function getNamespaceAndKey(namespacedKey: KeyName): KeyNameObj {
|
|
8
9
|
if (typeof namespacedKey !== "string") return namespacedKey;
|
|
9
10
|
|
|
10
11
|
const namespacedKeyProps = namespacedKey.includes(".")
|
|
@@ -345,6 +345,14 @@ export const focusManager = (function () {
|
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
+
function pressIn() {
|
|
349
|
+
const currentFocusable = getCurrentFocus();
|
|
350
|
+
|
|
351
|
+
if (currentFocusable) {
|
|
352
|
+
currentFocusable.pressIn(null);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
348
356
|
/**
|
|
349
357
|
* calls the `press` method on the current focus component
|
|
350
358
|
* @public
|
|
@@ -552,6 +560,7 @@ export const focusManager = (function () {
|
|
|
552
560
|
invokeHandler,
|
|
553
561
|
removeHandler,
|
|
554
562
|
longPress,
|
|
563
|
+
pressIn,
|
|
555
564
|
pressOut,
|
|
556
565
|
enableFocus,
|
|
557
566
|
setInitialFocus,
|
|
@@ -77,6 +77,12 @@ export class ClosedCaptioningManager {
|
|
|
77
77
|
|
|
78
78
|
private constructor() {
|
|
79
79
|
this.initialize();
|
|
80
|
+
|
|
81
|
+
window["vizioDebug"] = {
|
|
82
|
+
setCCEnabled: (isCCEnabled: boolean) => {
|
|
83
|
+
this.ccState$.next(isCCEnabled);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
static getInstance(): ClosedCaptioningManager {
|
|
@@ -98,6 +98,7 @@ export class Player {
|
|
|
98
98
|
this.isFullScreenSupported = this.isFullScreenSupported.bind(this);
|
|
99
99
|
this.onPlayerSeekComplete = this.onPlayerSeekComplete.bind(this);
|
|
100
100
|
|
|
101
|
+
this.isPaused = this.isPaused.bind(this);
|
|
101
102
|
this.entryObservable = null;
|
|
102
103
|
}
|
|
103
104
|
|
|
@@ -253,9 +254,9 @@ export class Player {
|
|
|
253
254
|
return this.playerState.seekPosition !== null;
|
|
254
255
|
};
|
|
255
256
|
|
|
256
|
-
isPaused
|
|
257
|
+
isPaused() {
|
|
257
258
|
return !!this.playerState.isPaused;
|
|
258
|
-
}
|
|
259
|
+
}
|
|
259
260
|
|
|
260
261
|
isPlaying = () => {
|
|
261
262
|
return !!this.playerState.isPaused === false;
|
|
@@ -290,11 +291,11 @@ export class Player {
|
|
|
290
291
|
};
|
|
291
292
|
|
|
292
293
|
// Methods to call actions on the player
|
|
293
|
-
seekTo = (_position: number) => {};
|
|
294
|
+
seekTo = async (_position: number) => {};
|
|
294
295
|
|
|
295
|
-
forward = (_deltaTime: number) => {};
|
|
296
|
+
forward = async (_deltaTime: number) => {};
|
|
296
297
|
|
|
297
|
-
rewind = (_deltaTime: number) => {};
|
|
298
|
+
rewind = async (_deltaTime: number) => {};
|
|
298
299
|
|
|
299
300
|
/**
|
|
300
301
|
* Determine whether content is live using three checks
|
|
@@ -701,8 +702,8 @@ export class Player {
|
|
|
701
702
|
onPlayerAttached: this.onPlayerAttached,
|
|
702
703
|
});
|
|
703
704
|
|
|
704
|
-
play = () => {};
|
|
705
|
-
pause = () => {};
|
|
705
|
+
play = async () => {};
|
|
706
|
+
pause = async () => {};
|
|
706
707
|
disableBufferAnimation = (): boolean => true;
|
|
707
708
|
|
|
708
709
|
setPlaybackRate = (_rate) => {};
|
|
@@ -95,7 +95,7 @@ export class PlayerNative extends Player {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
// Methods to call actions on the player
|
|
98
|
-
seekTo = (position: number) => {
|
|
98
|
+
seekTo = async (position: number) => {
|
|
99
99
|
if (!this.playerState.seekableDuration) {
|
|
100
100
|
log_warning("seekTo: Can not seek, video is not seekable");
|
|
101
101
|
|
|
@@ -123,7 +123,7 @@ export class PlayerNative extends Player {
|
|
|
123
123
|
this.logState(PlayerModuleFuncNames.seekTo, { position });
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
forward = (deltaTime: number) => {
|
|
126
|
+
forward = async (deltaTime: number) => {
|
|
127
127
|
if (isEmptyOrNil(this.playerState.contentPosition)) {
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
@@ -139,7 +139,7 @@ export class PlayerNative extends Player {
|
|
|
139
139
|
this.logState(PlayerModuleFuncNames.forward, { deltaTime });
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
-
rewind = (deltaTime: number) => {
|
|
142
|
+
rewind = async (deltaTime: number) => {
|
|
143
143
|
if (isEmptyOrNil(this.playerState.contentPosition)) {
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
@@ -155,13 +155,13 @@ export class PlayerNative extends Player {
|
|
|
155
155
|
this.logState(PlayerModuleFuncNames.rewind, { deltaTime });
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
play = () => {
|
|
158
|
+
play = async () => {
|
|
159
159
|
if (!this.invokeNativeFunction(PlayerModuleFuncNames.play)) {
|
|
160
160
|
this.currentPlayerComponent()?.[PlayerModuleFuncNames.play]?.();
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
-
pause = () => {
|
|
164
|
+
pause = async () => {
|
|
165
165
|
if (!this.invokeNativeFunction(PlayerModuleFuncNames.pause)) {
|
|
166
166
|
this.currentPlayerComponent()?.[PlayerModuleFuncNames.pause]?.();
|
|
167
167
|
}
|
package/equalUtils/index.ts
CHANGED
|
@@ -49,9 +49,16 @@ export const isEqual =
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (compareRemainingKeysBySameValue) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const allKeys = new Set([...Object.keys(prev), ...Object.keys(next)]);
|
|
53
|
+
|
|
54
|
+
const declaredKeys = new Set([
|
|
55
|
+
...byValue,
|
|
56
|
+
...byReference,
|
|
57
|
+
...byComparator.keys,
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const undeclaredKeys = Array.from(allKeys).filter(
|
|
61
|
+
(key) => !declaredKeys.has(key)
|
|
55
62
|
);
|
|
56
63
|
|
|
57
64
|
const isRestKeysEqualAllBySameValue = undeclaredKeys.every((key) =>
|
|
@@ -250,7 +250,17 @@ class FocusManager {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
onDisableFocusChange = (id) => {
|
|
253
|
-
|
|
253
|
+
const isFocused = FocusManager.instance.isFocused(id);
|
|
254
|
+
|
|
255
|
+
const isDescendantFocused = (() => {
|
|
256
|
+
try {
|
|
257
|
+
return FocusManager.instance.isAnyDescendantFocused(id);
|
|
258
|
+
} catch (_e) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
})();
|
|
262
|
+
|
|
263
|
+
if (isFocused || isDescendantFocused) {
|
|
254
264
|
// Move focus to next one
|
|
255
265
|
const nextFocus = FocusManager.instance.focused?.props
|
|
256
266
|
?.nextFocusDown as string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-alpha.
|
|
3
|
+
"version": "13.0.0-alpha.5771418585",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "13.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-alpha.5771418585",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BackHandler
|
|
1
|
+
import { useContext, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { BackHandler } from "react-native";
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
useContentTypes,
|
|
@@ -31,6 +31,8 @@ export { useGetBottomTabBarHeight } from "./useGetBottomTabBarHeight";
|
|
|
31
31
|
|
|
32
32
|
export { useIsScreenActive } from "./useIsScreenActive";
|
|
33
33
|
|
|
34
|
+
export { useProfilerLogging } from "./useProfilerLogging";
|
|
35
|
+
|
|
34
36
|
export {
|
|
35
37
|
useUniqueRouteSuffix,
|
|
36
38
|
useNavbarId,
|
|
@@ -121,10 +123,8 @@ export function isNavBarVisible(
|
|
|
121
123
|
return true;
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
const { ProfilerBridge } = NativeModules;
|
|
125
|
-
|
|
126
126
|
export const useBackHandler = (cb: () => boolean) => {
|
|
127
|
-
|
|
127
|
+
useEffect(() => {
|
|
128
128
|
BackHandler.addEventListener("hardwareBackPress", cb);
|
|
129
129
|
|
|
130
130
|
return () => {
|
|
@@ -158,7 +158,7 @@ export const useZappHooksForEntry = (
|
|
|
158
158
|
setIsHooksExecutionInProgress,
|
|
159
159
|
setIsPresentingFullScreen,
|
|
160
160
|
setIsRunningInBackground,
|
|
161
|
-
}: HookModalContextT =
|
|
161
|
+
}: HookModalContextT = useContext(ZappHookModalContext.ReactContext);
|
|
162
162
|
|
|
163
163
|
const {
|
|
164
164
|
appData: { layoutVersion },
|
|
@@ -256,22 +256,10 @@ export const useZappHooksForEntry = (
|
|
|
256
256
|
}, [entry.id]);
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
-
export const useProfilerLogging = () => {
|
|
260
|
-
const logTimestamp = (data: string) =>
|
|
261
|
-
InteractionManager.runAfterInteractions(() => {
|
|
262
|
-
if (ProfilerBridge && data) {
|
|
263
|
-
ProfilerBridge.updateTimer("navigation", data, Date.now());
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
return logTimestamp;
|
|
268
|
-
};
|
|
269
|
-
|
|
270
259
|
export const useRunIfLongPress = (
|
|
271
260
|
options = { timeout: LONG_KEY_PRESS_TIMEOUT }
|
|
272
261
|
) => {
|
|
273
|
-
const pressTimeout =
|
|
274
|
-
React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
|
|
262
|
+
const pressTimeout = useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
|
|
275
263
|
|
|
276
264
|
const resetTimeout = () => {
|
|
277
265
|
clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { InteractionManager, NativeModules } from "react-native";
|
|
3
|
+
|
|
4
|
+
const { ProfilerBridge } = NativeModules;
|
|
5
|
+
|
|
6
|
+
export const useProfilerLogging = () =>
|
|
7
|
+
useCallback(
|
|
8
|
+
(data: string) =>
|
|
9
|
+
InteractionManager.runAfterInteractions(() => {
|
|
10
|
+
if (ProfilerBridge && data) {
|
|
11
|
+
ProfilerBridge.updateTimer("navigation", data, Date.now());
|
|
12
|
+
}
|
|
13
|
+
}),
|
|
14
|
+
[]
|
|
15
|
+
);
|
|
@@ -23,7 +23,7 @@ export enum SEEK_STRATEGY {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const CONFIG_TAP_SEEK = {
|
|
26
|
-
CLICKS_BEFORE_PAUSE:
|
|
26
|
+
CLICKS_BEFORE_PAUSE: 1,
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const CONFIG_LONG_PRESS = {
|
|
@@ -93,6 +93,8 @@ export class TVSeekController
|
|
|
93
93
|
this.isPlayerInitiallyPaused = this.playerController.isPaused();
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
log_debug(`handleStartSeek: seekType: ${seekType}, initiallyPaused: ${this.isPlayerInitiallyPaused}, isPlayerPaused: ${this.playerController.isPaused()}`);
|
|
97
|
+
|
|
96
98
|
this.clearLongPressThresholdTimeout();
|
|
97
99
|
this.clearSeekCompleteTimeout();
|
|
98
100
|
this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
|
|
@@ -105,27 +107,36 @@ export class TVSeekController
|
|
|
105
107
|
};
|
|
106
108
|
|
|
107
109
|
onForwardPress = (): boolean => {
|
|
110
|
+
log_debug("onForwardPress:");
|
|
111
|
+
|
|
108
112
|
this.handleStartSeek(SEEK_TYPE.FORWARD);
|
|
109
113
|
|
|
110
114
|
return true;
|
|
111
115
|
};
|
|
112
116
|
|
|
113
117
|
onRewindPress = (): boolean => {
|
|
118
|
+
log_debug("onRewindPress:");
|
|
119
|
+
|
|
114
120
|
this.handleStartSeek(SEEK_TYPE.REWIND);
|
|
115
121
|
|
|
116
122
|
return true;
|
|
117
123
|
};
|
|
118
124
|
|
|
119
125
|
onSeekEnd = () => {
|
|
126
|
+
log_debug("onSeekEnd: Seek ended");
|
|
120
127
|
this.clearLongPressThresholdTimeout();
|
|
121
128
|
this.currentSeekController.onSeekEnd();
|
|
122
129
|
};
|
|
123
130
|
|
|
124
131
|
onRewindPressOut = () => {
|
|
132
|
+
log_debug("onRewindPressOut:");
|
|
133
|
+
|
|
125
134
|
this.onSeekEnd();
|
|
126
135
|
};
|
|
127
136
|
|
|
128
137
|
onForwardPressOut = () => {
|
|
138
|
+
log_debug("onForwardPressOut:");
|
|
139
|
+
|
|
129
140
|
this.onSeekEnd();
|
|
130
141
|
};
|
|
131
142
|
|
|
@@ -138,7 +149,9 @@ export class TVSeekController
|
|
|
138
149
|
};
|
|
139
150
|
|
|
140
151
|
handleDelayedSeek = (offset: number = 0) => {
|
|
141
|
-
this.
|
|
152
|
+
if (this.delayedSeekPosition === null) {
|
|
153
|
+
void this.handlePlayerPause();
|
|
154
|
+
}
|
|
142
155
|
|
|
143
156
|
const currentPos =
|
|
144
157
|
this.delayedSeekPosition === null
|
|
@@ -174,36 +187,46 @@ export class TVSeekController
|
|
|
174
187
|
}
|
|
175
188
|
}
|
|
176
189
|
|
|
190
|
+
log_debug(`handleDelayedSeek: currentPos: ${currentPos} targetPos:${targetPos}, initiallyPaused: ${this.isPlayerInitiallyPaused}`);
|
|
191
|
+
|
|
177
192
|
this.delayedSeekPosition = targetPos;
|
|
178
193
|
this.delayedSeekProgressSubject.next(targetPos);
|
|
179
194
|
};
|
|
180
195
|
|
|
181
|
-
handleSeekTo = (newPosition: number) => {
|
|
182
|
-
this.playerController.seekTo(newPosition);
|
|
196
|
+
handleSeekTo = async (newPosition: number) => {
|
|
197
|
+
await this.playerController.seekTo(newPosition);
|
|
198
|
+
|
|
199
|
+
log_debug(
|
|
200
|
+
`handleSeekTo: isPlayerInitiallyPaused: ${this.isPlayerInitiallyPaused} CallPlayerPlay: ${this.isPlayerInitiallyPaused ? "NO" : "YES"}`
|
|
201
|
+
);
|
|
183
202
|
|
|
184
203
|
if (!this.isPlayerInitiallyPaused) {
|
|
185
|
-
this.playerController.play();
|
|
204
|
+
await this.playerController.play();
|
|
186
205
|
}
|
|
187
206
|
};
|
|
188
207
|
|
|
189
|
-
handleSeek = (offset: number) => {
|
|
190
|
-
this.playerController[this.currentSeekType](offset);
|
|
208
|
+
handleSeek = async (offset: number) => {
|
|
209
|
+
await this.playerController[this.currentSeekType](offset);
|
|
210
|
+
|
|
211
|
+
log_debug(
|
|
212
|
+
`handleSeek: isPlayerInitiallyPaused: ${this.isPlayerInitiallyPaused} CallPlayerPlay: ${this.isPlayerInitiallyPaused ? "NO" : "YES"}`
|
|
213
|
+
);
|
|
191
214
|
|
|
192
215
|
if (!this.isPlayerInitiallyPaused) {
|
|
193
|
-
this.playerController.play();
|
|
216
|
+
await this.playerController.play();
|
|
194
217
|
}
|
|
195
218
|
};
|
|
196
219
|
|
|
197
220
|
handleSeekComplete = () => {
|
|
198
221
|
this.clearSeekCompleteTimeout();
|
|
199
222
|
|
|
200
|
-
this.seekEndTimeout = setTimeout(() => {
|
|
223
|
+
this.seekEndTimeout = setTimeout(async () => {
|
|
201
224
|
if (this.delayedSeekPosition !== null) {
|
|
202
|
-
this.handleSeekTo(this.delayedSeekPosition);
|
|
225
|
+
await this.handleSeekTo(this.delayedSeekPosition);
|
|
203
226
|
}
|
|
204
227
|
|
|
205
228
|
log_debug(
|
|
206
|
-
`handleSeekComplete: Seek finished, type: ${this.currentSeekController.title}, seekPosition: ${this.delayedSeekPosition}. Reset all states and seek position.`
|
|
229
|
+
`handleSeekComplete: Seek finished, type: ${this.currentSeekController.title}, seekPosition: ${this.delayedSeekPosition}, playerPaused: ${this.playerController.isPaused()}. Reset all states and seek position.`
|
|
207
230
|
);
|
|
208
231
|
|
|
209
232
|
this.resetAll();
|
|
@@ -214,12 +237,16 @@ export class TVSeekController
|
|
|
214
237
|
return this.delayedSeekPosition !== null;
|
|
215
238
|
};
|
|
216
239
|
|
|
217
|
-
handlePlayerPause = () => {
|
|
240
|
+
handlePlayerPause = async () => {
|
|
241
|
+
log_debug(
|
|
242
|
+
`handleSeek: handlePlayerPause isPlayerPaused: ${this.playerController.isPaused()}`
|
|
243
|
+
);
|
|
244
|
+
|
|
218
245
|
if (this.playerController.isPaused()) {
|
|
219
246
|
return;
|
|
220
247
|
}
|
|
221
248
|
|
|
222
|
-
this.playerController.pause();
|
|
249
|
+
await this.playerController.pause();
|
|
223
250
|
};
|
|
224
251
|
|
|
225
252
|
clearSeekCompleteTimeout = () => {
|
|
@@ -12,6 +12,8 @@ interface TapPressConfig {
|
|
|
12
12
|
|
|
13
13
|
export class TapSeekController implements ISeekController {
|
|
14
14
|
readonly title = "TapSeek";
|
|
15
|
+
private lastFastSeekExit = 0;
|
|
16
|
+
|
|
15
17
|
constructor(
|
|
16
18
|
private seekControllerDelegate: ISeekControllerDelegate,
|
|
17
19
|
private seekIncrementalStrategy: SeekIncrementalBaseStrategy,
|
|
@@ -23,13 +25,18 @@ export class TapSeekController implements ISeekController {
|
|
|
23
25
|
|
|
24
26
|
const skipTime = this.seekIncrementalStrategy.getSkipTime();
|
|
25
27
|
const seekMultiplier = this.seekIncrementalStrategy.getSkipMultiplier();
|
|
28
|
+
const cooldown = Date.now() - this.lastFastSeekExit > 1000;
|
|
26
29
|
|
|
27
30
|
if (seekMultiplier > this.config.CLICKS_BEFORE_PAUSE) {
|
|
28
31
|
log_debug(
|
|
29
32
|
`${this.title}: handle delayed seek type:${seekType} - skipTime: ${skipTime}, seekMultiplier: ${seekMultiplier}.`
|
|
30
33
|
);
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
if (cooldown) {
|
|
36
|
+
this.seekControllerDelegate.handleDelayedSeek(skipTime);
|
|
37
|
+
} else {
|
|
38
|
+
this.seekControllerDelegate.handleSeek(skipTime);
|
|
39
|
+
}
|
|
33
40
|
} else {
|
|
34
41
|
log_debug(
|
|
35
42
|
`${this.title}: handle seek type:${seekType} - skipTime: ${skipTime}.`
|
|
@@ -46,8 +53,8 @@ export class TapSeekController implements ISeekController {
|
|
|
46
53
|
};
|
|
47
54
|
|
|
48
55
|
reset = () => {
|
|
49
|
-
log_debug(
|
|
50
|
-
|
|
56
|
+
log_debug(`${this.title}: Reset states`);
|
|
57
|
+
this.lastFastSeekExit = Date.now();
|
|
51
58
|
this.seekIncrementalStrategy.reset();
|
|
52
59
|
};
|
|
53
60
|
}
|
|
@@ -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,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,59 +1,27 @@
|
|
|
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`] = `
|
|
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
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
|
-
{
|
|
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
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[Function],
|
|
28
|
-
],
|
|
29
|
-
[
|
|
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`] = `
|
|
10
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
|
|
36
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
|
|
17
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
|
|
43
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
|
-
{
|
|
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
|
|
24
|
+
exports[`helpers createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
|
|
57
25
|
[
|
|
58
26
|
[
|
|
59
27
|
[Function],
|
|
@@ -64,43 +32,9 @@ exports[`createContextSetters when state validator is provided calls setState wh
|
|
|
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`] = `
|
|
35
|
+
exports[`helpers createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
|
|
68
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
|
-
{
|
|
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
|
-
{
|
|
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
|
-
{
|
|
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
|
-
[
|
|
97
|
-
[
|
|
98
|
-
"trying to invoke setFoo with invalid foo - but it was rejected by the state validator
|
|
99
|
-
skipping context update",
|
|
100
|
-
],
|
|
101
|
-
[
|
|
102
|
-
"trying to invoke setBar with invalid bar - but it was rejected by the state validator
|
|
103
|
-
skipping context update",
|
|
104
|
-
],
|
|
105
|
-
]
|
|
106
|
-
`;
|
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`createProvider creates a context Provider component 1`] = `
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"context": "initialValue",
|
|
8
|
-
"otherContext": "otherValue",
|
|
9
|
-
"setContext": [Function],
|
|
10
|
-
"setOtherContext": [Function],
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
>
|
|
14
|
-
<MockChild
|
|
15
|
-
context="context"
|
|
16
|
-
/>
|
|
17
|
-
</mockConstructor>
|
|
18
|
-
`;
|
|
19
|
-
|
|
20
|
-
exports[`createProvider creates a context Provider component 2`] = `
|
|
21
|
-
{
|
|
22
|
-
"children": <MockChild
|
|
23
|
-
context="context"
|
|
24
|
-
/>,
|
|
25
|
-
"value": {
|
|
26
|
-
"context": "initialValue",
|
|
27
|
-
"otherContext": "otherValue",
|
|
28
|
-
"setContext": [Function],
|
|
29
|
-
"setOtherContext": [Function],
|
|
30
|
-
},
|
|
31
|
-
}
|
|
4
|
+
<View>
|
|
5
|
+
context
|
|
6
|
+
</View>
|
|
32
7
|
`;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { shallow } from "enzyme";
|
|
3
2
|
import { View, Text } from "react-native";
|
|
4
3
|
|
|
4
|
+
import { NOOP, getSetterName, createContextSetters } from "../helpers";
|
|
5
|
+
|
|
5
6
|
function stateValidator({ property, value }) {
|
|
6
7
|
return (
|
|
7
8
|
(property === "foo" && value === "new foo") ||
|
|
@@ -9,150 +10,135 @@ function stateValidator({ property, value }) {
|
|
|
9
10
|
);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
reactUtilsLogger: {
|
|
18
|
-
addSubsystem: jest.fn(() => mockLogger),
|
|
19
|
-
},
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
const { NOOP, getSetterName, createContextSetters } = require("../helpers");
|
|
23
|
-
|
|
24
|
-
describe("NOOP", () => {
|
|
25
|
-
it("does nothing", () => {
|
|
26
|
-
expect(NOOP()).toBeUndefined();
|
|
13
|
+
describe("helpers", () => {
|
|
14
|
+
describe("NOOP", () => {
|
|
15
|
+
it("does nothing", () => {
|
|
16
|
+
expect(NOOP()).toBeUndefined();
|
|
17
|
+
});
|
|
27
18
|
});
|
|
28
|
-
});
|
|
29
19
|
|
|
30
|
-
describe("getSetterName", () => {
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
describe("getSetterName", () => {
|
|
21
|
+
it("returns a setter name for the given property name", () => {
|
|
22
|
+
expect(getSetterName("fooBar")).toBe("setFooBar");
|
|
23
|
+
});
|
|
33
24
|
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe("createContextSetters", () => {
|
|
37
|
-
describe("when state validator is provided", () => {
|
|
38
|
-
class Component extends React.Component {
|
|
39
|
-
constructor(props) {
|
|
40
|
-
super(props);
|
|
41
|
-
this.state = { foo: "foo", bar: "bar" };
|
|
42
|
-
createContextSetters(["foo", "bar"], this, { stateValidator });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
resetInitialState() {
|
|
46
|
-
this.setState({ foo: "foo", bar: "bar" });
|
|
47
|
-
}
|
|
48
25
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
26
|
+
describe("createContextSetters", () => {
|
|
27
|
+
describe("when state validator is provided", () => {
|
|
28
|
+
class ClassComponent {
|
|
29
|
+
constructor() {
|
|
30
|
+
this._state = { foo: "foo", bar: "bar" };
|
|
31
|
+
createContextSetters(["foo", "bar"], this, { stateValidator });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
setState(newState) {
|
|
35
|
+
if (typeof newState === "function") {
|
|
36
|
+
this.state = newState(this.state);
|
|
37
|
+
} else {
|
|
38
|
+
this.state = { ...this.state, ...newState };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
set state(val) {
|
|
43
|
+
this._state = val;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get state() {
|
|
47
|
+
return this._state;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getState() {
|
|
51
|
+
return this._state;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
resetInitialState() {
|
|
55
|
+
this.setState({ foo: "foo", bar: "bar" });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
render() {
|
|
59
|
+
return <View testID="test-view">{JSON.stringify(this.state)}</View>;
|
|
60
|
+
}
|
|
55
61
|
}
|
|
56
|
-
}
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
const instance = wrapper.instance();
|
|
60
|
-
const setStateSpy = jest.spyOn(instance, "setState");
|
|
63
|
+
let instance;
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
mockLogger.warning.mockClear();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("adds all properties and setters to the component", () => {
|
|
69
|
-
expect(instance).toHaveProperty("setFoo");
|
|
70
|
-
expect(instance.setFoo).toBeFunction();
|
|
71
|
-
expect(instance).toHaveProperty("setBar");
|
|
72
|
-
expect(instance.setBar).toBeFunction();
|
|
73
|
-
});
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
instance = new ClassComponent();
|
|
67
|
+
});
|
|
74
68
|
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
it("calls setState when the setters are called & the validator passes", () => {
|
|
70
|
+
expect(instance.state.foo).toEqual("foo");
|
|
71
|
+
expect(instance.state.bar).toEqual("bar");
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
instance.setBar("new bar");
|
|
82
|
-
expect(instance.state).toMatchSnapshot();
|
|
83
|
-
|
|
84
|
-
expect(setStateSpy).toHaveBeenCalledTimes(2);
|
|
85
|
-
expect(setStateSpy.mock.calls).toMatchSnapshot();
|
|
86
|
-
expect(mockLogger.warning).not.toHaveBeenCalled();
|
|
87
|
-
});
|
|
73
|
+
instance.setFoo("new foo");
|
|
74
|
+
expect(instance.state.foo).toEqual("new foo");
|
|
88
75
|
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
instance.setBar("new bar");
|
|
77
|
+
expect(instance.state.bar).toEqual("new bar");
|
|
78
|
+
});
|
|
91
79
|
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
it("skips the update if the state validator doesn't pass", () => {
|
|
81
|
+
expect(instance.state.foo).toEqual("foo");
|
|
82
|
+
expect(instance.state.bar).toEqual("bar");
|
|
94
83
|
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
instance.setFoo("invalid foo");
|
|
85
|
+
expect(instance.state.foo).toEqual("foo");
|
|
97
86
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
87
|
+
instance.setBar("invalid bar");
|
|
88
|
+
expect(instance.state.bar).toEqual("bar");
|
|
89
|
+
});
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
it("skips the update if the new value is the same as the previous one", () => {
|
|
92
|
+
instance.setFoo("new foo");
|
|
93
|
+
instance.setFoo("new foo");
|
|
94
|
+
expect(instance.state).toMatchSnapshot();
|
|
95
|
+
});
|
|
108
96
|
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe("when no state validator is provided", () => {
|
|
112
|
-
class Component extends React.Component {
|
|
113
|
-
constructor(props) {
|
|
114
|
-
super(props);
|
|
115
|
-
this.state = { foo: "foo", bar: "bar" };
|
|
116
|
-
createContextSetters(["foo", "bar"], this);
|
|
117
|
-
}
|
|
118
97
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
98
|
+
describe("when no state validator is provided", () => {
|
|
99
|
+
class Component extends React.Component {
|
|
100
|
+
constructor(props) {
|
|
101
|
+
super(props);
|
|
102
|
+
this.state = { foo: "foo", bar: "bar" };
|
|
103
|
+
createContextSetters(["foo", "bar"], this);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
render() {
|
|
107
|
+
return (
|
|
108
|
+
<View>
|
|
109
|
+
<Text>I am a component </Text>
|
|
110
|
+
</View>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
125
113
|
}
|
|
126
|
-
}
|
|
127
114
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
115
|
+
// const wrapper = new Component();
|
|
116
|
+
const instance = new Component();
|
|
117
|
+
const setStateSpy = jest.spyOn(instance, "setState");
|
|
131
118
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
119
|
+
afterEach(() => {
|
|
120
|
+
setStateSpy.mockClear();
|
|
121
|
+
});
|
|
136
122
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
123
|
+
it("adds all properties and setters to the component", () => {
|
|
124
|
+
expect(instance).toHaveProperty("setFoo");
|
|
125
|
+
expect(instance.setFoo).toBeFunction();
|
|
126
|
+
expect(instance).toHaveProperty("setBar");
|
|
127
|
+
expect(instance.setBar).toBeFunction();
|
|
128
|
+
});
|
|
143
129
|
|
|
144
|
-
|
|
145
|
-
|
|
130
|
+
it("calls setState when the setters are called, no matter what the value is", () => {
|
|
131
|
+
expect(instance.state).toMatchSnapshot();
|
|
146
132
|
|
|
147
|
-
|
|
148
|
-
|
|
133
|
+
instance.setFoo("invalid foo");
|
|
134
|
+
expect(instance.state).toMatchSnapshot();
|
|
149
135
|
|
|
150
|
-
|
|
151
|
-
|
|
136
|
+
instance.setBar("invalid bar");
|
|
137
|
+
expect(instance.state).toMatchSnapshot();
|
|
152
138
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
139
|
+
expect(setStateSpy).toHaveBeenCalledTimes(2);
|
|
140
|
+
expect(setStateSpy.mock.calls).toMatchSnapshot();
|
|
141
|
+
});
|
|
156
142
|
});
|
|
157
143
|
});
|
|
158
144
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
5
|
import { View } from "react-native";
|
|
6
6
|
|
|
7
7
|
import { createProvider } from "../provider";
|
|
@@ -29,14 +29,12 @@ describe("createProvider", () => {
|
|
|
29
29
|
it("creates a context Provider component", () => {
|
|
30
30
|
const MockChild = (props) => <View>{props.context}</View>;
|
|
31
31
|
|
|
32
|
-
const wrapper =
|
|
32
|
+
const wrapper = render(
|
|
33
33
|
<Provider>
|
|
34
34
|
<MockChild context={"context"} />
|
|
35
35
|
</Provider>
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
-
expect(
|
|
39
|
-
|
|
40
|
-
expect(wrapper.find(ReactContext.Provider).props()).toMatchSnapshot();
|
|
38
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
41
39
|
});
|
|
42
40
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
5
|
import { View } from "react-native";
|
|
6
6
|
|
|
7
7
|
import { createWithConsumerDecorator } from "../withConsumer";
|
|
@@ -11,21 +11,21 @@ describe("createConsumer", () => {
|
|
|
11
11
|
const { Consumer } = ReactContext;
|
|
12
12
|
const withConsumer = createWithConsumerDecorator(Consumer);
|
|
13
13
|
|
|
14
|
-
it("returns a function", () => {
|
|
15
|
-
expect(withConsumer).toBeFunction();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
14
|
it("creates a context consumer function", () => {
|
|
19
|
-
|
|
20
|
-
const DecoratedChild = withConsumer(Child);
|
|
15
|
+
expect(withConsumer).toBeFunction();
|
|
21
16
|
const newContextValue = "newValue";
|
|
22
17
|
|
|
23
|
-
const
|
|
18
|
+
const Child = (props) => {
|
|
19
|
+
props.setContext(newContextValue);
|
|
20
|
+
|
|
21
|
+
return <View>{props.context}</View>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const DecoratedChild = withConsumer(Child);
|
|
24
25
|
|
|
25
|
-
const
|
|
26
|
+
const wrapper = render(<DecoratedChild />);
|
|
26
27
|
|
|
27
|
-
expect(
|
|
28
|
-
childWrapper.props().setContext(newContextValue);
|
|
28
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
29
29
|
|
|
30
30
|
expect(mockContextData.setContext).toHaveBeenCalledWith(newContextValue);
|
|
31
31
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
5
|
import { View, Text } from "react-native";
|
|
6
6
|
|
|
7
7
|
import { createWithProviderDecorator } from "../withProvider";
|
|
@@ -19,8 +19,8 @@ describe("withProvider", () => {
|
|
|
19
19
|
|
|
20
20
|
const DecoratedComponent = withProvider(Component);
|
|
21
21
|
|
|
22
|
-
const wrapper =
|
|
22
|
+
const wrapper = render(<DecoratedComponent />);
|
|
23
23
|
|
|
24
|
-
expect(
|
|
24
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
25
25
|
});
|
|
26
26
|
});
|
package/testUtils/index.tsx
CHANGED
|
@@ -15,16 +15,6 @@ import { ThemeContext } from "../theme";
|
|
|
15
15
|
|
|
16
16
|
export { getByTestId } from "./getByTestId";
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
|
|
20
|
-
* Example:
|
|
21
|
-
* wrapper.findWhere(testIDEquals('yourID'))
|
|
22
|
-
* @param {*} testId
|
|
23
|
-
* @return boolean
|
|
24
|
-
*/
|
|
25
|
-
export const testIDEquals = (testId: any): boolean =>
|
|
26
|
-
R.compose(R.equals(testId), R.invoker(1, "prop")("testID"));
|
|
27
|
-
|
|
28
18
|
/** Helper function for react-test-renderer, accepts type and renderer
|
|
29
19
|
* * @param {*} type React Component type instance or name of component
|
|
30
20
|
* * @param {*} renderer renderer instance
|