@applicaster/zapp-react-native-utils 13.0.0-alpha.1605643562 → 13.0.0-alpha.1673005505

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 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(".")
@@ -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;
@@ -250,7 +250,17 @@ class FocusManager {
250
250
  }
251
251
 
252
252
  onDisableFocusChange = (id) => {
253
- if (FocusManager.instance.isFocused(id)) {
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.1605643562",
3
+ "version": "13.0.0-alpha.1673005505",
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.1605643562",
31
+ "@applicaster/applicaster-types": "13.0.0-alpha.1673005505",
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 React, { useEffect, useMemo } from "react";
2
- import { BackHandler, InteractionManager, NativeModules } from "react-native";
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
- React.useEffect(() => {
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 = React.useContext(ZappHookModalContext.ReactContext);
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
+ );
@@ -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}`);
97
+
96
98
  this.clearLongPressThresholdTimeout();
97
99
  this.clearSeekCompleteTimeout();
98
100
  this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
@@ -117,6 +119,7 @@ export class TVSeekController
117
119
  };
118
120
 
119
121
  onSeekEnd = () => {
122
+ log_debug("onSeekEnd: Seek ended");
120
123
  this.clearLongPressThresholdTimeout();
121
124
  this.currentSeekController.onSeekEnd();
122
125
  };
@@ -174,6 +177,8 @@ export class TVSeekController
174
177
  }
175
178
  }
176
179
 
180
+ log_debug(`handleDelayedSeek: currentPos: ${currentPos} targetPos:${targetPos}, initiallyPaused: ${this.isPlayerInitiallyPaused}`);
181
+
177
182
  this.delayedSeekPosition = targetPos;
178
183
  this.delayedSeekProgressSubject.next(targetPos);
179
184
  };
@@ -46,7 +46,7 @@ export class TapSeekController implements ISeekController {
46
46
  };
47
47
 
48
48
  reset = () => {
49
- log_debug("{this.title}: Reset states");
49
+ log_debug(`${this.title}: Reset states`);
50
50
 
51
51
  this.seekIncrementalStrategy.reset();
52
52
  };
@@ -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`] = `<StatelessComponent />`;
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`] = `<StatelessComponent />`;
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 { shallow } from "enzyme";
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
- it("should have isNilOrEmpty", () => {
24
- expect(isNilOrEmpty).toBeDefined();
25
- expect(isNilOrEmpty(null)).toBeTruthy();
26
- expect(isNilOrEmpty(undefined)).toBeTruthy();
27
- expect(isNilOrEmpty("")).toBeTruthy();
28
- expect(isNilOrEmpty([])).toBeTruthy();
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
- it("returns true if the component is a class component", () => {
34
- expect(isClassComponent(ClassComponent)).toBe(true);
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
- it("returns false otherwise", () => {
38
- expect(isClassComponent(StatelessComponent)).toBe(false);
37
+ it("returns false otherwise", () => {
38
+ expect(isClassComponent(StatelessComponent)).toBe(false);
39
+ });
39
40
  });
40
- });
41
41
 
42
- describe("attachMethodToPrototype", () => {
43
- const initialWrapper = shallow(<ClassComponent />);
42
+ describe("attachMethodToPrototype", () => {
43
+ const initialWrapper = render(<ClassComponent />);
44
44
 
45
- expect(initialWrapper.instance()).not.toHaveProperty(
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
- const wrapper = shallow(<NewComponent />);
49
+ afterEach(() => {
50
+ componentDidMount.mockClear();
51
+ });
60
52
 
61
- expect(shallowToJson(wrapper)).toMatchSnapshot();
62
- expect(wrapper.instance()).toHaveProperty(COMPONENT_DID_MOUNT_METHOD);
63
- expect(componentDidMount).toHaveBeenCalled();
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
- it("preserves any existing lifecycle method", () => {
67
- const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
68
- componentDidMount,
69
- COMPONENT_DID_MOUNT_METHOD
70
- );
59
+ const wrapper = render(<NewComponent />);
71
60
 
72
- expect(componentDidMount).not.toHaveBeenCalled();
61
+ expect(wrapper.toJSON(wrapper)).toMatchSnapshot();
62
+ expect(new NewComponent()).toHaveProperty(COMPONENT_DID_MOUNT_METHOD);
63
+ expect(componentDidMount).toHaveBeenCalled();
64
+ });
73
65
 
74
- const wrapper = shallow(<NewComponent />);
66
+ it("preserves any existing lifecycle method", () => {
67
+ const NewComponent = attachMethodToPrototype(ComponentWithLifeCycle)(
68
+ componentDidMount,
69
+ COMPONENT_DID_MOUNT_METHOD
70
+ );
75
71
 
76
- expect(shallowToJson(wrapper)).toMatchSnapshot();
77
- expect(componentDidMount).toHaveBeenCalled();
78
- expect(existingMethod).toHaveBeenCalled();
79
- });
80
- });
72
+ expect(componentDidMount).not.toHaveBeenCalled();
81
73
 
82
- describe("wrapInClass", () => {
83
- let NewComponent;
84
- let wrapper;
74
+ const wrapper = render(<NewComponent />);
85
75
 
86
- beforeEach(() => {
87
- NewComponent = wrapInClass(StatelessComponent);
88
- wrapper = shallow(<NewComponent />);
76
+ expect(wrapper.toJSON()).toMatchSnapshot();
77
+ expect(componentDidMount).toHaveBeenCalled();
78
+ expect(existingMethod).toHaveBeenCalled();
79
+ });
89
80
  });
90
81
 
91
- it("wraps the stateless component in a class", () => {
92
- expect(isClassComponent(NewComponent)).toBe(true);
93
- expect(shallowToJson(wrapper)).toMatchSnapshot();
94
- });
95
- });
82
+ describe("wrapInClass", () => {
83
+ let NewComponent;
84
+ let wrapper;
96
85
 
97
- describe("addLifeCycleMethods", () => {
98
- let NewComponent;
99
- let wrapper;
86
+ beforeEach(() => {
87
+ NewComponent = wrapInClass(StatelessComponent);
88
+ wrapper = render(<NewComponent />);
89
+ });
100
90
 
101
- beforeEach(() => {
102
- NewComponent = addLifeCycleMethods({ componentDidMount })(ClassComponent);
103
- wrapper = shallow(<NewComponent />);
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
- afterEach(() => {
107
- componentDidMount.mockClear();
108
- });
97
+ describe("addLifeCycleMethods", () => {
98
+ let NewComponent;
99
+ let wrapper;
109
100
 
110
- it("attaches the lifecycle method to the component", () => {
111
- expect(shallowToJson(wrapper)).toMatchSnapshot();
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
- it("adds the lifecycle method to the component", () => {
115
- expect(componentDidMount).toHaveBeenCalled();
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 & the validator passes 2`] = `
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": "new 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 & the validator passes 4`] = `
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
- <mockConstructor
5
- value={
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,8 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`createConsumer creates a context consumer function 1`] = `
4
- <Child
5
- context="foo"
6
- setContext={[MockFunction]}
7
- />
4
+ <View>
5
+ foo
6
+ </View>
8
7
  `;
@@ -1,7 +1,11 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`withProvider decorates a component with the provider 1`] = `
4
- <Provider>
5
- <Component />
6
- </Provider>
4
+ <View>
5
+ <View>
6
+ <Text>
7
+ I am a Component
8
+ </Text>
9
+ </View>
10
+ </View>
7
11
  `;
@@ -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
- const mockLogger = {
13
- warning: jest.fn(),
14
- };
15
-
16
- jest.mock("../../logger", () => ({
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
- it("returns a setter name for the given property name", () => {
32
- expect(getSetterName("fooBar")).toBe("setFooBar");
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
- render() {
50
- return (
51
- <View>
52
- <Text>I am a component</Text>
53
- </View>
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
- const wrapper = shallow(<Component />);
59
- const instance = wrapper.instance();
60
- const setStateSpy = jest.spyOn(instance, "setState");
63
+ let instance;
61
64
 
62
- beforeEach(() => {
63
- instance.resetInitialState();
64
- setStateSpy.mockClear();
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
- it("calls setState when the setters are called & the validator passes", () => {
76
- expect(instance.state).toMatchSnapshot();
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
- instance.setFoo("new foo");
79
- expect(instance.state).toMatchSnapshot();
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
- it("skips the update if the state validator doesn't pass", () => {
90
- expect(instance.state).toMatchSnapshot();
76
+ instance.setBar("new bar");
77
+ expect(instance.state.bar).toEqual("new bar");
78
+ });
91
79
 
92
- instance.setFoo("invalid foo");
93
- expect(instance.state).toMatchSnapshot();
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
- instance.setBar("invalid bar");
96
- expect(instance.state).toMatchSnapshot();
84
+ instance.setFoo("invalid foo");
85
+ expect(instance.state.foo).toEqual("foo");
97
86
 
98
- expect(setStateSpy).not.toHaveBeenCalled();
99
- expect(mockLogger.warning).toHaveBeenCalledTimes(2);
100
- expect(mockLogger.warning.mock.calls).toMatchSnapshot();
101
- });
87
+ instance.setBar("invalid bar");
88
+ expect(instance.state.bar).toEqual("bar");
89
+ });
102
90
 
103
- it("skips the update if the new value is the same as the previous one", () => {
104
- instance.setFoo("new foo");
105
- instance.setFoo("new foo");
106
- expect(instance.state).toMatchSnapshot();
107
- expect(setStateSpy).toHaveBeenCalledTimes(1);
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
- render() {
120
- return (
121
- <View>
122
- <Text>I am a component </Text>
123
- </View>
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
- const wrapper = shallow(<Component />);
129
- const instance = wrapper.instance();
130
- const setStateSpy = jest.spyOn(instance, "setState");
115
+ // const wrapper = new Component();
116
+ const instance = new Component();
117
+ const setStateSpy = jest.spyOn(instance, "setState");
131
118
 
132
- afterEach(() => {
133
- setStateSpy.mockClear();
134
- mockLogger.warning.mockClear();
135
- });
119
+ afterEach(() => {
120
+ setStateSpy.mockClear();
121
+ });
136
122
 
137
- it("adds all properties and setters to the component", () => {
138
- expect(instance).toHaveProperty("setFoo");
139
- expect(instance.setFoo).toBeFunction();
140
- expect(instance).toHaveProperty("setBar");
141
- expect(instance.setBar).toBeFunction();
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
- it("calls setState when the setters are called, no matter what the value is", () => {
145
- expect(instance.state).toMatchSnapshot();
130
+ it("calls setState when the setters are called, no matter what the value is", () => {
131
+ expect(instance.state).toMatchSnapshot();
146
132
 
147
- instance.setFoo("invalid foo");
148
- expect(instance.state).toMatchSnapshot();
133
+ instance.setFoo("invalid foo");
134
+ expect(instance.state).toMatchSnapshot();
149
135
 
150
- instance.setBar("invalid bar");
151
- expect(instance.state).toMatchSnapshot();
136
+ instance.setBar("invalid bar");
137
+ expect(instance.state).toMatchSnapshot();
152
138
 
153
- expect(setStateSpy).toHaveBeenCalledTimes(2);
154
- expect(setStateSpy.mock.calls).toMatchSnapshot();
155
- expect(mockLogger.warning).not.toHaveBeenCalled();
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 { shallow } from "enzyme";
4
- import toJson from "enzyme-to-json";
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 = shallow(
32
+ const wrapper = render(
33
33
  <Provider>
34
34
  <MockChild context={"context"} />
35
35
  </Provider>
36
36
  );
37
37
 
38
- expect(toJson(wrapper)).toMatchSnapshot();
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 { shallow } from "enzyme";
4
- import toJson from "enzyme-to-json";
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
- const Child = (props) => <View>{props.context}</View>;
20
- const DecoratedChild = withConsumer(Child);
15
+ expect(withConsumer).toBeFunction();
21
16
  const newContextValue = "newValue";
22
17
 
23
- const wrapper = shallow(<DecoratedChild />);
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 childWrapper = wrapper.dive();
26
+ const wrapper = render(<DecoratedChild />);
26
27
 
27
- expect(toJson(childWrapper)).toMatchSnapshot();
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 { shallow } from "enzyme";
4
- import toJson from "enzyme-to-json";
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 = shallow(<DecoratedComponent />);
22
+ const wrapper = render(<DecoratedComponent />);
23
23
 
24
- expect(toJson(wrapper)).toMatchSnapshot();
24
+ expect(wrapper.toJSON()).toMatchSnapshot();
25
25
  });
26
26
  });
@@ -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