@applicaster/zapp-react-native-utils 13.0.0-rc.16 → 13.0.0-rc.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actionsExecutor/ActionExecutorContext.tsx +12 -1
- package/alertUtils/alert.ts +148 -0
- package/alertUtils/index.ts +1 -148
- package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
- package/appUtils/contextKeysManager/contextResolver.ts +73 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +6 -6
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
- package/appUtils/orientationHelper.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +1 -1
- package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
- package/manifestUtils/__tests__/createConfig.test.js +18 -16
- package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
- package/navigationUtils/__tests__/itemTypes.test.js +2 -2
- package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
- package/package.json +3 -2
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -1
- package/reactHooks/cell-click/__tests__/index.test.js +5 -2
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
- package/reactHooks/feed/usePipesCacheReset.ts +5 -5
- package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
- package/reactHooks/layout/__tests__/index.test.tsx +10 -10
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
- package/reactHooks/navigation/__tests__/index.test.tsx +0 -4
- package/reactHooks/navigation/index.ts +22 -214
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
- package/reactHooks/navigation/useGetTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useIsScreenActive.ts +17 -0
- package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
- package/reactHooks/navigation/useNavigationType.ts +15 -0
- package/reactHooks/navigation/usePathname.ts +4 -0
- package/reactHooks/navigation/useRoute.ts +100 -0
- package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +2 -3
- package/reactUtils/__tests__/reactUtils.test.js +10 -28
- package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +19 -19
- package/reactUtils/createContext/__tests__/__snapshots__/index.test.js.snap +2 -2
- package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -3
- package/reactUtils/createContext/__tests__/helpers.test.js +8 -8
- package/theme/__mocks__/index.ts +4 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createLogger } from "../../logger";
|
|
2
|
+
import { ContextKeysManager } from "./index";
|
|
3
|
+
import * as R from "ramda";
|
|
4
|
+
|
|
5
|
+
const { log_error } = createLogger({
|
|
6
|
+
subsystem: "contextResolver",
|
|
7
|
+
category: "General",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
interface IResolver {
|
|
11
|
+
resolve: (string) => Promise<string | number | object>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class EntryResolver implements IResolver {
|
|
15
|
+
entry: ZappEntry;
|
|
16
|
+
|
|
17
|
+
constructor(entry: ZappEntry) {
|
|
18
|
+
this.entry = entry;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async resolve(key: string) {
|
|
22
|
+
if (!key || key.length === 0) {
|
|
23
|
+
return this.entry;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return R.view(R.lensPath(key.split(".")), this.entry);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class ContextResolver implements IResolver {
|
|
31
|
+
resolve = async (compositeKey: string) =>
|
|
32
|
+
ContextKeysManager.instance.getKey(compositeKey);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const resolveObjectValues = async (
|
|
36
|
+
data: Record<string, any>,
|
|
37
|
+
resolvers: Record<string, IResolver> = null
|
|
38
|
+
) => {
|
|
39
|
+
const entries = Object.entries(data);
|
|
40
|
+
|
|
41
|
+
const exResolvers = { ctx: new ContextResolver(), ...resolvers };
|
|
42
|
+
|
|
43
|
+
const resolvedEntries = await Promise.all(
|
|
44
|
+
entries.map(async ([key, value]) => {
|
|
45
|
+
const regex = /@{([^/]+)\/([^}]*)}/;
|
|
46
|
+
|
|
47
|
+
if (typeof value !== "string") {
|
|
48
|
+
return [key, value];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const match = (value as string).match(regex);
|
|
52
|
+
|
|
53
|
+
if (match) {
|
|
54
|
+
const contextResolverName = match[1];
|
|
55
|
+
const compositeKey = match[2];
|
|
56
|
+
|
|
57
|
+
const resolver = exResolvers[contextResolverName] || exResolvers.ctx;
|
|
58
|
+
const resolvedValue = await resolver.resolve(compositeKey);
|
|
59
|
+
|
|
60
|
+
return [key, resolvedValue];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
log_error("resolveObjectValues: invalid context string", {
|
|
64
|
+
key,
|
|
65
|
+
value,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return [key, null];
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return Object.fromEntries(resolvedEntries);
|
|
73
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`focusManager should be defined 1`] = `
|
|
4
|
-
|
|
4
|
+
{
|
|
5
5
|
"blur": [Function],
|
|
6
6
|
"disableFocus": [Function],
|
|
7
7
|
"enableFocus": [Function],
|
|
8
8
|
"focusableTree": Tree {
|
|
9
9
|
"loadingCounter": 0,
|
|
10
|
-
"root":
|
|
11
|
-
"children":
|
|
10
|
+
"root": {
|
|
11
|
+
"children": [],
|
|
12
12
|
"component": null,
|
|
13
13
|
"id": "root",
|
|
14
14
|
"lastFocusedItem": null,
|
|
@@ -39,12 +39,12 @@ Object {
|
|
|
39
39
|
`;
|
|
40
40
|
|
|
41
41
|
exports[`focusManagerIOS should be defined 1`] = `
|
|
42
|
-
|
|
42
|
+
{
|
|
43
43
|
"focus": [Function],
|
|
44
44
|
"focusableTree": Tree {
|
|
45
45
|
"loadingCounter": 0,
|
|
46
|
-
"root":
|
|
47
|
-
"children":
|
|
46
|
+
"root": {
|
|
47
|
+
"children": [],
|
|
48
48
|
"component": null,
|
|
49
49
|
"id": "root",
|
|
50
50
|
"lastFocusedItem": null,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`keyCodes keyCode returns an object for a given key event 1`] = `
|
|
4
|
-
|
|
4
|
+
{
|
|
5
5
|
"direction": [Function],
|
|
6
6
|
"matches": [Function],
|
|
7
7
|
"matchesAny": [Function],
|
|
8
|
-
"value":
|
|
8
|
+
"value": {
|
|
9
9
|
"code": "Enter",
|
|
10
10
|
"keyCode": 13,
|
|
11
11
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as ReactNative from "react-native";
|
|
3
3
|
import { isTV, platformSelect } from "../reactUtils";
|
|
4
4
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
5
|
-
import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
5
|
+
import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks/device/useIsTablet";
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
QUICK_BRICK_EVENTS,
|
|
@@ -58,7 +58,7 @@ export class PlayerNative extends Player {
|
|
|
58
58
|
return this.playerState.contentPosition;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
currentPlayerComponent = (): ReactComponent<
|
|
61
|
+
currentPlayerComponent = (): ReactComponent<PlayerRefProps> =>
|
|
62
62
|
this.playerComponent?.current;
|
|
63
63
|
|
|
64
64
|
getState = () => this.playerState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`shiftArray shifts the n first items from the head to the tail of the array with a positive offset 1`] = `
|
|
4
|
-
|
|
4
|
+
[
|
|
5
5
|
"bar",
|
|
6
6
|
"baz",
|
|
7
7
|
42,
|
|
@@ -10,7 +10,7 @@ Array [
|
|
|
10
10
|
`;
|
|
11
11
|
|
|
12
12
|
exports[`shiftArray shifts the n first items from the head to the tail of the array with a positive offset 2`] = `
|
|
13
|
-
|
|
13
|
+
[
|
|
14
14
|
"baz",
|
|
15
15
|
42,
|
|
16
16
|
"foo",
|
|
@@ -19,7 +19,7 @@ Array [
|
|
|
19
19
|
`;
|
|
20
20
|
|
|
21
21
|
exports[`shiftArray shifts the n last items from the tail to the head of the array with a negative offset 1`] = `
|
|
22
|
-
|
|
22
|
+
[
|
|
23
23
|
42,
|
|
24
24
|
"foo",
|
|
25
25
|
"bar",
|
|
@@ -28,7 +28,7 @@ Array [
|
|
|
28
28
|
`;
|
|
29
29
|
|
|
30
30
|
exports[`shiftArray shifts the n last items from the tail to the head of the array with a negative offset 2`] = `
|
|
31
|
-
|
|
31
|
+
[
|
|
32
32
|
"baz",
|
|
33
33
|
42,
|
|
34
34
|
"foo",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`functionUtils subscriber can be invoked without args 1`] = `
|
|
4
|
-
|
|
5
|
-
"handlers":
|
|
4
|
+
{
|
|
5
|
+
"handlers": {},
|
|
6
6
|
"invokeHandler": [Function],
|
|
7
7
|
"on": [Function],
|
|
8
8
|
"removeHandler": [Function],
|
|
@@ -10,9 +10,9 @@ Object {
|
|
|
10
10
|
`;
|
|
11
11
|
|
|
12
12
|
exports[`functionUtils subscriber returns the original object with additional methods 1`] = `
|
|
13
|
-
|
|
13
|
+
{
|
|
14
14
|
"foo": "bar",
|
|
15
|
-
"handlers":
|
|
15
|
+
"handlers": {},
|
|
16
16
|
"invokeHandler": [Function],
|
|
17
17
|
"method": [Function],
|
|
18
18
|
"on": [Function],
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const styles = {
|
|
1
|
+
const mockStyles = {
|
|
4
2
|
fields: [{ key: "field_1", initial_value: 1 }],
|
|
5
3
|
label: "styles",
|
|
6
4
|
};
|
|
7
5
|
|
|
8
|
-
const
|
|
6
|
+
const mockStylesWithGroup = {
|
|
9
7
|
fields: [
|
|
10
8
|
{
|
|
11
9
|
group: true,
|
|
@@ -15,26 +13,28 @@ const stylesWithGroup = {
|
|
|
15
13
|
],
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
const
|
|
19
|
-
styles: jest.fn(() => ({ styles })),
|
|
16
|
+
const mockGenerators = {
|
|
17
|
+
styles: jest.fn(() => ({ styles: mockStyles })),
|
|
20
18
|
stylesGroup: jest.fn(() => ({
|
|
21
|
-
styles:
|
|
19
|
+
styles: mockStylesWithGroup,
|
|
22
20
|
})),
|
|
23
|
-
customConfiguration: jest.fn(() => ({ custom_configuration: [
|
|
21
|
+
customConfiguration: jest.fn(() => ({ custom_configuration: [mockStyles] })),
|
|
24
22
|
customConfigurationGroup: jest.fn(() => ({
|
|
25
|
-
custom_configuration: [
|
|
23
|
+
custom_configuration: [mockStylesWithGroup],
|
|
26
24
|
})),
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
jest.
|
|
27
|
+
jest.doMock("../defaultManifestConfigurations", () => ({
|
|
30
28
|
defaultConfigurations: {
|
|
31
|
-
styles:
|
|
32
|
-
stylesGroup:
|
|
33
|
-
customConfiguration:
|
|
34
|
-
customConfigurationGroup:
|
|
29
|
+
styles: mockGenerators.styles,
|
|
30
|
+
stylesGroup: mockGenerators.stylesGroup,
|
|
31
|
+
customConfiguration: mockGenerators.customConfiguration,
|
|
32
|
+
customConfigurationGroup: mockGenerators.customConfigurationGroup,
|
|
35
33
|
},
|
|
36
34
|
}));
|
|
37
35
|
|
|
36
|
+
const { createConfig } = require("../createConfig");
|
|
37
|
+
|
|
38
38
|
describe("createConfig", () => {
|
|
39
39
|
it("should return a function", () => {
|
|
40
40
|
const currentResult = createConfig(jest.fn());
|
|
@@ -78,7 +78,9 @@ describe("createConfig", () => {
|
|
|
78
78
|
extend: "styles",
|
|
79
79
|
})(props);
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
console.log(mockGenerators.styles.mock.calls);
|
|
82
|
+
|
|
83
|
+
expect(mockGenerators.styles).toBeCalledWith(props);
|
|
82
84
|
});
|
|
83
85
|
|
|
84
86
|
it("should return base configuration if manifest is not provided", () => {
|
|
@@ -88,7 +90,7 @@ describe("createConfig", () => {
|
|
|
88
90
|
extend: "styles",
|
|
89
91
|
})({});
|
|
90
92
|
|
|
91
|
-
expect(currentResult).toEqual({ styles });
|
|
93
|
+
expect(currentResult).toEqual({ styles: mockStyles });
|
|
92
94
|
});
|
|
93
95
|
|
|
94
96
|
describe("Data merging", () => {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`getNavigationProps returns the props otherwise 1`] = `
|
|
4
|
-
|
|
5
|
-
"assets":
|
|
4
|
+
{
|
|
5
|
+
"assets": {
|
|
6
6
|
"appLogo": "appLogo.png",
|
|
7
7
|
},
|
|
8
8
|
"home": false,
|
|
9
|
-
"nav_items":
|
|
10
|
-
|
|
9
|
+
"nav_items": [
|
|
10
|
+
{
|
|
11
11
|
"type": "label",
|
|
12
12
|
},
|
|
13
13
|
],
|
|
14
|
-
"rules":
|
|
14
|
+
"rules": {},
|
|
15
15
|
"selected": "A1234",
|
|
16
|
-
"styles":
|
|
16
|
+
"styles": {
|
|
17
17
|
"style": "foo",
|
|
18
18
|
},
|
|
19
19
|
"title": "testTitle",
|
|
@@ -61,8 +61,8 @@ describe("getTypeMatcher", () => {
|
|
|
61
61
|
|
|
62
62
|
describe("isItemOfType", () => {
|
|
63
63
|
it("is a curried function", () => {
|
|
64
|
-
expect(itemIsOfType(river, SCREEN_TYPES.RIVER)).
|
|
65
|
-
expect(itemIsOfType(river)).
|
|
64
|
+
expect(itemIsOfType(river, SCREEN_TYPES.RIVER)).toBeTruthy();
|
|
65
|
+
expect(itemIsOfType(river)).toBeInstanceOf(Function);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
it("returns true if the item is of the given type", () => {
|
|
@@ -243,7 +243,7 @@ describe("getTargetRoute", () => {
|
|
|
243
243
|
it("returns a valid path when initial pathname is /", () => {
|
|
244
244
|
const targetRoute = getTargetRoute(river, "/", { layoutVersion });
|
|
245
245
|
expect(targetRoute).toEqual(`/river/${river.id}`);
|
|
246
|
-
expect(targetRoute).not.
|
|
246
|
+
expect(targetRoute).not.toContainEntry("//");
|
|
247
247
|
});
|
|
248
248
|
});
|
|
249
249
|
|
|
@@ -273,7 +273,7 @@ describe("getTargetRoute", () => {
|
|
|
273
273
|
it("returns a valid path when initial pathname is /", () => {
|
|
274
274
|
const targetRoute = getTargetRoute(river, "/", { layoutVersion });
|
|
275
275
|
expect(targetRoute).toEqual(`/river/${river.id}`);
|
|
276
|
-
expect(targetRoute).not.
|
|
276
|
+
expect(targetRoute).not.toContainEntry("//");
|
|
277
277
|
});
|
|
278
278
|
});
|
|
279
279
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-rc.
|
|
3
|
+
"version": "13.0.0-rc.17",
|
|
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-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-rc.17",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"immer": "*",
|
|
45
45
|
"react": "17.0.2",
|
|
46
46
|
"react-native": "0.68.6",
|
|
47
|
+
"uglify-js": "*",
|
|
47
48
|
"validate-color": "*",
|
|
48
49
|
"zustand": "*"
|
|
49
50
|
},
|
|
@@ -5,14 +5,14 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
|
|
|
5
5
|
|
|
6
6
|
import { waitFor } from "@testing-library/react-native";
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const mockNavigator = {
|
|
9
9
|
getPathname: () => "pathnameMock",
|
|
10
10
|
push: jest.fn(),
|
|
11
11
|
data: {},
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
|
|
15
|
-
useNavigation: () =>
|
|
15
|
+
useNavigation: () => mockNavigator,
|
|
16
16
|
useRoute: () => ({ pathname: "pathnameMock" }),
|
|
17
17
|
useProfilerLogging: () => {
|
|
18
18
|
return jest.fn();
|
|
@@ -26,6 +26,9 @@ jest.mock("@applicaster/zapp-react-native-utils/analyticsUtils/", () => ({
|
|
|
26
26
|
}));
|
|
27
27
|
|
|
28
28
|
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
29
|
+
...jest.requireActual(
|
|
30
|
+
"@applicaster/zapp-react-native-ui-components/Contexts"
|
|
31
|
+
),
|
|
29
32
|
ZappPipesEntryContext: {
|
|
30
33
|
useZappPipesContext: jest.fn(() => [undefined, jest.fn()]),
|
|
31
34
|
},
|
|
@@ -7,12 +7,12 @@ const appData = {
|
|
|
7
7
|
sdk_version: "2.0.0",
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const mockUseInflatedUrl = jest.fn();
|
|
11
11
|
|
|
12
12
|
jest.mock(
|
|
13
13
|
"@applicaster/zapp-react-native-utils/reactHooks/feed/useInflatedUrl",
|
|
14
14
|
() => ({
|
|
15
|
-
useInflatedUrl:
|
|
15
|
+
useInflatedUrl: mockUseInflatedUrl,
|
|
16
16
|
})
|
|
17
17
|
);
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ const { useBuildPipesUrl } = require("../useBuildPipesUrl");
|
|
|
20
20
|
|
|
21
21
|
describe("useBuildPipesUrl", () => {
|
|
22
22
|
it("returns the proper url", async () => {
|
|
23
|
-
|
|
23
|
+
mockUseInflatedUrl.mockReturnValue("http://foo.com/show/show-1");
|
|
24
24
|
const url = "http://foo.com/show/{{showId}}";
|
|
25
25
|
|
|
26
26
|
const mapping = {
|
|
@@ -65,7 +65,7 @@ describe("useBuildPipesUrl", () => {
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it("returns empty object if url is not in endpoints", async () => {
|
|
68
|
-
|
|
68
|
+
mockUseInflatedUrl.mockReturnValue("http://foobar.com/show-1");
|
|
69
69
|
const url = "http://foobar.com/{{showId}}";
|
|
70
70
|
|
|
71
71
|
const mapping = {
|
|
@@ -6,42 +6,41 @@ import { Provider } from "react-redux";
|
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import configureStore from "redux-mock-store";
|
|
8
8
|
import thunk from "redux-thunk";
|
|
9
|
-
import * as
|
|
9
|
+
import * as useRouteHook from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute";
|
|
10
10
|
import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
11
|
+
import { useFeedLoader } from "../useFeedLoader";
|
|
11
12
|
|
|
12
13
|
const mockStore = configureStore([thunk]);
|
|
13
14
|
|
|
14
|
-
jest.useFakeTimers();
|
|
15
|
+
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
15
16
|
|
|
16
|
-
const
|
|
17
|
+
const mockLogger = {
|
|
17
18
|
warning: jest.fn(),
|
|
18
19
|
log: jest.fn(),
|
|
19
20
|
info: jest.fn(),
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
+
const mockNavigator: any = {
|
|
23
24
|
currentRoute: "/river/A1234",
|
|
24
25
|
getStack: jest.fn(() => []),
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const
|
|
28
|
+
const mockRouteData: any = {
|
|
28
29
|
screenData: {},
|
|
29
30
|
pathname: "/river/A1234",
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
jest.
|
|
33
|
+
jest.doMock("../../logger", () => ({
|
|
33
34
|
reactHooksLogger: {
|
|
34
|
-
addSubsystem: jest.fn(() =>
|
|
35
|
+
addSubsystem: jest.fn(() => mockLogger),
|
|
35
36
|
},
|
|
36
37
|
}));
|
|
37
38
|
|
|
38
39
|
jest
|
|
39
40
|
.spyOn(useNavigationHooks, "useNavigation")
|
|
40
|
-
.mockImplementation(() =>
|
|
41
|
+
.mockImplementation(() => mockNavigator);
|
|
41
42
|
|
|
42
|
-
jest.spyOn(
|
|
43
|
-
|
|
44
|
-
const { useFeedLoader } = require("../useFeedLoader");
|
|
43
|
+
jest.spyOn(useRouteHook, "useRoute").mockImplementation(() => mockRouteData);
|
|
45
44
|
|
|
46
45
|
const mockZappPipesData = {
|
|
47
46
|
data: {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { useDispatch } from "react-redux";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
usePipesContexts,
|
|
7
|
-
} from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils";
|
|
3
|
+
|
|
4
|
+
import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
|
|
5
|
+
import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
|
|
8
6
|
import { clearPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
9
7
|
|
|
8
|
+
import { useRoute } from "../navigation/useRoute";
|
|
9
|
+
|
|
10
10
|
/**
|
|
11
11
|
* reset river components cache when screen is unmounted
|
|
12
12
|
* @param {string} riverId screen id
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { renderHook, act } from "@testing-library/react-
|
|
3
|
-
import { render } from "@testing-library/react-native";
|
|
2
|
+
import { renderHook, render, act } from "@testing-library/react-native";
|
|
4
3
|
import { View } from "react-native";
|
|
5
4
|
|
|
6
5
|
import { useSequentialLoader, useSequentialRenderItem } from "..";
|
|
@@ -66,26 +65,28 @@ describe("flatList hooks", () => {
|
|
|
66
65
|
|
|
67
66
|
expect(result.current.allLoaded).toBe(false);
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
(
|
|
71
|
-
onLoadFinished
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
act(() => {
|
|
69
|
+
result.current.renderItem(
|
|
70
|
+
({ onLoadFinished }) => {
|
|
71
|
+
onLoadFinished();
|
|
72
|
+
},
|
|
73
|
+
{ index: 1 }
|
|
74
|
+
);
|
|
75
|
+
});
|
|
75
76
|
|
|
76
77
|
expect(result.current.allLoaded).toBe(true);
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
80
|
|
|
80
81
|
describe("Rendering wrapper", () => {
|
|
81
|
-
it("wraps the elements in the View with display: none style", () => {
|
|
82
|
+
it("wraps the elements in the View with display: none style", async () => {
|
|
82
83
|
const element1 = { id: 1 };
|
|
83
84
|
const element2 = { id: 2 };
|
|
84
85
|
const mockData = [element1, element2];
|
|
85
86
|
|
|
86
87
|
const { result } = renderHook(() => useSequentialRenderItem(mockData));
|
|
87
88
|
|
|
88
|
-
const
|
|
89
|
+
const res = render(
|
|
89
90
|
result.current.renderItem(
|
|
90
91
|
() => {
|
|
91
92
|
return <View testID={"test"} />;
|
|
@@ -94,7 +95,9 @@ describe("flatList hooks", () => {
|
|
|
94
95
|
)
|
|
95
96
|
);
|
|
96
97
|
|
|
97
|
-
const element =
|
|
98
|
+
const element = res.root.findByProps({
|
|
99
|
+
testID: "sequential-river-wrapper-1",
|
|
100
|
+
});
|
|
98
101
|
|
|
99
102
|
expect(element.props.style.display).toEqual("none");
|
|
100
103
|
});
|
|
@@ -106,14 +109,16 @@ describe("flatList hooks", () => {
|
|
|
106
109
|
|
|
107
110
|
const { result } = renderHook(() => useSequentialRenderItem(mockData));
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
(
|
|
111
|
-
onLoadFinished
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
act(() => {
|
|
113
|
+
result.current.renderItem(
|
|
114
|
+
({ onLoadFinished }) => {
|
|
115
|
+
onLoadFinished();
|
|
116
|
+
},
|
|
117
|
+
{ item: element1, index: 0 }
|
|
118
|
+
);
|
|
119
|
+
});
|
|
115
120
|
|
|
116
|
-
const {
|
|
121
|
+
const { root } = render(
|
|
117
122
|
result.current.renderItem(
|
|
118
123
|
({ onLoadFinished }) => {
|
|
119
124
|
onLoadFinished();
|
|
@@ -124,7 +129,9 @@ describe("flatList hooks", () => {
|
|
|
124
129
|
)
|
|
125
130
|
);
|
|
126
131
|
|
|
127
|
-
const element =
|
|
132
|
+
const element = root.findByProps({
|
|
133
|
+
testID: "sequential-river-wrapper-1",
|
|
134
|
+
});
|
|
128
135
|
|
|
129
136
|
expect(element.props.style.display).toEqual("flex");
|
|
130
137
|
});
|
|
@@ -136,7 +143,7 @@ describe("flatList hooks", () => {
|
|
|
136
143
|
|
|
137
144
|
const { result } = renderHook(() => useSequentialRenderItem(mockData));
|
|
138
145
|
|
|
139
|
-
const {
|
|
146
|
+
const { root } = render(
|
|
140
147
|
result.current.renderItem(
|
|
141
148
|
({ onLoadFinished }) => {
|
|
142
149
|
onLoadFinished();
|
|
@@ -147,7 +154,9 @@ describe("flatList hooks", () => {
|
|
|
147
154
|
)
|
|
148
155
|
);
|
|
149
156
|
|
|
150
|
-
const element =
|
|
157
|
+
const element = root.findByProps({
|
|
158
|
+
testID: "sequential-river-wrapper-1",
|
|
159
|
+
});
|
|
151
160
|
|
|
152
161
|
expect(element.props.style.display).toEqual("none");
|
|
153
162
|
});
|