@applicaster/zapp-react-native-utils 13.0.0-rc.13 → 13.0.0-rc.131

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.
Files changed (173) hide show
  1. package/README.md +0 -10
  2. package/actionsExecutor/ActionExecutor.ts +16 -9
  3. package/actionsExecutor/ActionExecutorContext.tsx +229 -17
  4. package/actionsExecutor/consts.ts +4 -0
  5. package/alertUtils/alert.ts +148 -0
  6. package/alertUtils/index.ts +1 -148
  7. package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
  8. package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
  9. package/analyticsUtils/currentScreenProperities.ts +6 -4
  10. package/analyticsUtils/helpers/hooks.ts +1 -1
  11. package/appUtils/HooksManager/Hook.ts +6 -2
  12. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
  13. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
  14. package/appUtils/HooksManager/index.ts +3 -1
  15. package/appUtils/HooksManager/types.ts +5 -2
  16. package/appUtils/__tests__/__snapshots__/localizationsHelper.test.ts.snap +151 -0
  17. package/appUtils/__tests__/allZappLocales.ts +79 -0
  18. package/appUtils/__tests__/{localizationsHelper.test.js → localizationsHelper.test.ts} +11 -0
  19. package/appUtils/accessibilityManager/const.ts +18 -0
  20. package/appUtils/accessibilityManager/index.ts +42 -1
  21. package/appUtils/contextKeysManager/contextResolver.ts +66 -0
  22. package/appUtils/contextKeysManager/index.ts +2 -2
  23. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  24. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +9 -6
  25. package/appUtils/focusManager/index.ios.ts +14 -4
  26. package/appUtils/focusManager/index.ts +108 -69
  27. package/appUtils/focusManager/treeDataStructure/Tree/index.js +23 -0
  28. package/appUtils/focusManager/utils/__tests__/findChild.test.ts +35 -0
  29. package/appUtils/focusManager/utils/enums.ts +4 -0
  30. package/appUtils/focusManager/utils/index.ts +5 -0
  31. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  32. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  33. package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
  34. package/appUtils/keyCodes/index.ts +11 -7
  35. package/appUtils/keyCodes/keys/keysByPlatform.ts +4 -0
  36. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  37. package/appUtils/localizationsHelper.ts +31 -0
  38. package/appUtils/orientationHelper.ts +11 -13
  39. package/appUtils/platform/const.ts +14 -0
  40. package/appUtils/platform/platformUtils.ts +47 -4
  41. package/appUtils/playerManager/index.ts +1 -1
  42. package/appUtils/playerManager/player.ts +42 -18
  43. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +11 -7
  44. package/appUtils/playerManager/playerNative.ts +18 -2
  45. package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
  46. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  47. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  48. package/cellUtils/index.ts +9 -5
  49. package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
  50. package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
  51. package/componentsUtils/__tests__/isGallery.test.ts +33 -0
  52. package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
  53. package/componentsUtils/index.ts +39 -0
  54. package/dateUtils/index.ts +19 -0
  55. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  56. package/equalUtils/index.ts +49 -30
  57. package/focusManager/FocusManager.ts +14 -2
  58. package/focusManager/index.ts +23 -4
  59. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  60. package/functionUtils/index.ts +46 -8
  61. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  62. package/idleUtils/index.ts +1 -1
  63. package/idleUtils/withTimeout.ts +15 -2
  64. package/index.d.ts +0 -12
  65. package/localizationUtils/index.ts +8 -13
  66. package/logger/const.ts +9 -67
  67. package/manifestUtils/__tests__/createConfig.test.js +16 -16
  68. package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
  69. package/manifestUtils/defaultManifestConfigurations/player.js +9 -3
  70. package/manifestUtils/fonts/index.js +5 -6
  71. package/manifestUtils/index.js +2 -0
  72. package/manifestUtils/keys.js +27 -2
  73. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  74. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  75. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  76. package/modalState/__tests__/index.test.ts +51 -0
  77. package/modalState/index.ts +32 -2
  78. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +7 -6
  79. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  80. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  81. package/navigationUtils/index.ts +6 -4
  82. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  83. package/numberUtils/index.ts +11 -5
  84. package/package.json +5 -10
  85. package/playerUtils/configurationGenerator.ts +9 -11
  86. package/playerUtils/index.ts +17 -0
  87. package/reactHooks/advertising/index.ts +5 -5
  88. package/reactHooks/app/useAppState.ts +2 -2
  89. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  90. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
  91. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  92. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  93. package/reactHooks/cell-click/index.ts +7 -1
  94. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  95. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  96. package/reactHooks/feed/useBatchLoading.ts +10 -12
  97. package/reactHooks/feed/useFeedLoader.tsx +18 -9
  98. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  99. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  100. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  101. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  102. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  103. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  104. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  105. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  106. package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
  107. package/reactHooks/navigation/getTabBarHeight.ts +10 -0
  108. package/reactHooks/navigation/index.ts +34 -236
  109. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +19 -0
  110. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  111. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  112. package/reactHooks/navigation/useNavigationPluginData.ts +19 -0
  113. package/reactHooks/navigation/useNavigationType.ts +17 -0
  114. package/reactHooks/navigation/usePathname.ts +4 -0
  115. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  116. package/reactHooks/navigation/useRoute.ts +98 -0
  117. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  118. package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
  119. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
  120. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
  121. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
  122. package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -3
  123. package/reactHooks/player/const.ts +0 -4
  124. package/reactHooks/player/index.ts +0 -6
  125. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +69 -0
  126. package/reactHooks/screen/useScreenBackgroundColor.ts +3 -15
  127. package/reactHooks/state/README.md +79 -0
  128. package/reactHooks/state/ZStoreProvider.tsx +71 -0
  129. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +66 -0
  130. package/reactHooks/state/index.ts +2 -0
  131. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  132. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  133. package/reactHooks/useListenEventBusEvent.ts +1 -1
  134. package/reactHooks/usePluginConfiguration.ts +1 -1
  135. package/reactHooks/useSubscriberFor.ts +4 -3
  136. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  137. package/reactUtils/__tests__/reactUtils.test.js +1 -37
  138. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  139. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
  140. package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
  141. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  142. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  143. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  144. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  145. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  146. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  147. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  148. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  149. package/reactUtils/createContext/helpers.ts +6 -1
  150. package/reactUtils/createContext/index.ts +11 -25
  151. package/reactUtils/index.ts +9 -11
  152. package/screenState/index.ts +24 -10
  153. package/services/js2native.ts +673 -0
  154. package/testUtils/index.tsx +0 -10
  155. package/theme/__mocks__/index.ts +4 -0
  156. package/theme/index.ts +1 -1
  157. package/time/BackgroundTimer.ts +55 -0
  158. package/time/Timer.ts +9 -6
  159. package/typeGuards/index.ts +3 -0
  160. package/types.ts +1 -0
  161. package/utils/README.md +30 -0
  162. package/utils/chunk.ts +5 -0
  163. package/utils/index.ts +5 -0
  164. package/utils/times.ts +5 -0
  165. package/zappFrameworkUtils/localStorageHelper.ts +38 -10
  166. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  167. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  168. package/zappFrameworkUtils/types.ts +11 -0
  169. package/reactHooks/player/useAutoSeek.tsx +0 -87
  170. package/reactHooks/player/useSeek.tsx +0 -66
  171. package/reactHooks/player/useTapSeek.tsx +0 -58
  172. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  173. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import { render, screen } from "@testing-library/react-native";
3
+ import { Text } from "react-native";
4
+ import { ZStoreProvider, useZStore } from "../ZStoreProvider";
5
+ import { useStore } from "zustand";
6
+
7
+ interface TestState {
8
+ value: string;
9
+ }
10
+
11
+ // Test component that uses the store
12
+ const TestComponent = ({ storeName }: { storeName: string }) => {
13
+ const store = useZStore(storeName);
14
+ const value = useStore(store, (state: any) => (state as TestState).value);
15
+
16
+ return <Text testID="test-value">{value}</Text>;
17
+ };
18
+
19
+ // Test component that provides a store
20
+ const TestProvider = ({ children }: { children: React.ReactNode }) => {
21
+ return (
22
+ <ZStoreProvider name="testStore" value={{ value: "test-value" }}>
23
+ {children}
24
+ </ZStoreProvider>
25
+ );
26
+ };
27
+
28
+ describe("ZStoreProvider and useZStore", () => {
29
+ it("should provide a store and allow access via useZStore", () => {
30
+ render(
31
+ <TestProvider>
32
+ <TestComponent storeName="testStore" />
33
+ </TestProvider>
34
+ );
35
+
36
+ expect(screen.getByTestId("test-value").props.children).toBe("test-value");
37
+ });
38
+
39
+ it("should throw error when useZStore is used outside provider", () => {
40
+ // Suppress console.error for this test
41
+ const originalError = console.error;
42
+ console.error = jest.fn();
43
+
44
+ expect(() => {
45
+ render(<TestComponent storeName="testStore" />);
46
+ }).toThrow("useZStore must be used within a ZStoreProvider");
47
+
48
+ console.error = originalError;
49
+ });
50
+
51
+ it("should throw error when store name is not found", () => {
52
+ // Suppress console.error for this test
53
+ const originalError = console.error;
54
+ console.error = jest.fn();
55
+
56
+ expect(() => {
57
+ render(
58
+ <TestProvider>
59
+ <TestComponent storeName="nonExistentStore" />
60
+ </TestProvider>
61
+ );
62
+ }).toThrow('Store with name "nonExistentStore" not found');
63
+
64
+ console.error = originalError;
65
+ });
66
+ });
@@ -1,3 +1,5 @@
1
1
  export { useRivers } from "./useRivers";
2
2
 
3
3
  export { useHomeRiver } from "./useHomeRiver";
4
+
5
+ export { ZStoreProvider, useZStore } from "./ZStoreProvider";
@@ -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
+ };
@@ -23,5 +23,5 @@ export const useListenEventBusEvent = (
23
23
  sub.remove(); // stop listening to DeviceEventEmitter
24
24
  };
25
25
  }
26
- }, []);
26
+ }, [handler, subscriptionID, source, events]);
27
27
  };
@@ -91,7 +91,7 @@ export function useLayoutConfiguration<
91
91
  S extends unknown,
92
92
  G extends unknown,
93
93
  R extends unknown,
94
- L extends unknown
94
+ L extends unknown,
95
95
  >(layoutData, manifest, options: Options = {}) {
96
96
  const keys = options.keys || [
97
97
  "assets",
@@ -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
- (eventName: string, handler?: (...args: unknown[]) => void): (
8
- ...args: unknown[]
9
- ) => ReturnType<typeof subscriber>;
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`] = `<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,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
- const {
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 { 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,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
- Object {
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
- Object {
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 & the validator passes 2`] = `
43
- Object {
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": "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
- 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 & the validator passes 4`] = `
57
- Array [
58
- Array [
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
- Array [
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
- Object {
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
- `;
@@ -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
- Object {
4
+ {
5
5
  "Consumer": [MockFunction],
6
6
  "Provider": [MockFunction],
7
- "ReactContext": Object {
7
+ "ReactContext": {
8
8
  "Consumer": [MockFunction],
9
9
  "Provider": [MockFunction],
10
10
  },
@@ -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
- Object {
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
- Object {
22
- "children": <MockChild
23
- context="context"
24
- />,
25
- "value": Object {
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
  `;