@applicaster/zapp-react-native-ui-components 16.0.0-rc.2 → 16.0.0-rc.20
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/Components/BackgroundImage/BackgroundImage.tsx +42 -0
- package/Components/BackgroundImage/BackgroundImage.tv.android.tsx +28 -0
- package/Components/BackgroundImage/BackgroundImage.tv.ios.tsx +24 -0
- package/Components/BackgroundImage/index.ts +1 -0
- package/Components/CellRendererResolver/index.ts +1 -1
- package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
- package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
- package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
- package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
- package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
- package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
- package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
- package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
- package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
- package/Components/GeneralContentScreen/index.ts +2 -0
- package/Components/Layout/TV/ScreenContainer.tsx +5 -0
- package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
- package/Components/Layout/TV/index.tsx +3 -4
- package/Components/Layout/TV/index.web.tsx +2 -3
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +1 -1
- package/Components/PlayerContainer/PlayerContainer.tsx +7 -7
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
- package/Components/Screen/TV/hooks/__tests__/useAfterPaint.test.ts +60 -0
- package/Components/Screen/TV/hooks/index.ts +2 -0
- package/Components/Screen/TV/hooks/useAfterPaint.ts +23 -0
- package/Components/Screen/TV/index.web.tsx +16 -7
- package/Components/ScreenRevealManager/Overlay.tsx +34 -0
- package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +8 -19
- package/Components/VideoLive/LiveImageManager.ts +56 -45
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +4 -2
- package/Components/VideoModal/utils.ts +6 -1
- package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
- package/Helpers/index.js +7 -40
- package/package.json +5 -5
- package/Components/Layout/TV/LayoutBackground.tsx +0 -31
- package/Helpers/Analytics/index.js +0 -95
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, ViewStyle } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
5
|
+
import {
|
|
6
|
+
selectRemoteConfigurations,
|
|
7
|
+
useAppSelector,
|
|
8
|
+
} from "@applicaster/zapp-react-native-redux";
|
|
9
|
+
|
|
10
|
+
import { getBackgroundImageUrl } from "../Layout/utils";
|
|
11
|
+
|
|
12
|
+
const baseBackgroundStyles = (imageUrl, backgroundColor) =>
|
|
13
|
+
({
|
|
14
|
+
position: "absolute",
|
|
15
|
+
left: 0,
|
|
16
|
+
top: 0,
|
|
17
|
+
right: 0,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
zIndex: -1,
|
|
20
|
+
backgroundSize: "cover",
|
|
21
|
+
background: imageUrl
|
|
22
|
+
? `url(${imageUrl}) no-repeat top center ${backgroundColor}`
|
|
23
|
+
: backgroundColor,
|
|
24
|
+
}) as ViewStyle;
|
|
25
|
+
|
|
26
|
+
export const BackgroundImage = ({ children }: React.PropsWithChildren) => {
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
|
|
29
|
+
const remoteConfigurations = useAppSelector(selectRemoteConfigurations);
|
|
30
|
+
|
|
31
|
+
const backgroundColor = theme.app_background_color;
|
|
32
|
+
const backgroundImageUrl = getBackgroundImageUrl(remoteConfigurations);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<View
|
|
36
|
+
id="background"
|
|
37
|
+
style={baseBackgroundStyles(backgroundImageUrl, backgroundColor)}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</View>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
ImageURISource,
|
|
6
|
+
ImageBackground,
|
|
7
|
+
} from "react-native";
|
|
8
|
+
|
|
9
|
+
import { ASSETS } from "@applicaster/zapp-react-native-ui-components/Helpers";
|
|
10
|
+
|
|
11
|
+
const imageSource: ImageURISource = {
|
|
12
|
+
uri: ASSETS.APP_BACKGROUND_IMAGE,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const styles = StyleSheet.create({
|
|
16
|
+
container: { flex: 1 },
|
|
17
|
+
backgroundImage: { width: "100%", height: "100%" },
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export function BackgroundImage({ children }: React.PropsWithChildren) {
|
|
21
|
+
return (
|
|
22
|
+
<View style={styles.container}>
|
|
23
|
+
<ImageBackground style={styles.backgroundImage} source={imageSource}>
|
|
24
|
+
{children}
|
|
25
|
+
</ImageBackground>
|
|
26
|
+
</View>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, ImageURISource } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { QBImage as Image } from "@applicaster/zapp-react-native-ui-components/Components/Image";
|
|
5
|
+
import { ASSETS } from "@applicaster/zapp-react-native-ui-components/Helpers";
|
|
6
|
+
|
|
7
|
+
const imageSource: ImageURISource = {
|
|
8
|
+
uri: ASSETS.APP_BACKGROUND_IMAGE,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const styles = StyleSheet.create({
|
|
12
|
+
container: { flex: 1 },
|
|
13
|
+
backgroundImage: { width: "100%", height: "100%" },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export function BackgroundImage({ children }: React.PropsWithChildren) {
|
|
17
|
+
return (
|
|
18
|
+
<View style={styles.container}>
|
|
19
|
+
<Image style={styles.backgroundImage} source={imageSource}>
|
|
20
|
+
{children}
|
|
21
|
+
</Image>
|
|
22
|
+
</View>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BackgroundImage } from "./BackgroundImage";
|
|
@@ -83,7 +83,7 @@ export function CellRendererResolver({
|
|
|
83
83
|
|
|
84
84
|
if (!cellRendererPlugin && !isGroup(component)) {
|
|
85
85
|
logger.warning({
|
|
86
|
-
message:
|
|
86
|
+
message: `Could not resolve cell builder plugin: ${component?.component_type}`,
|
|
87
87
|
data: { component },
|
|
88
88
|
});
|
|
89
89
|
}
|
|
@@ -107,7 +107,7 @@ describe("ComponentResolverComponent", () => {
|
|
|
107
107
|
expect(mockLogger.warning).toHaveBeenNthCalledWith(
|
|
108
108
|
1,
|
|
109
109
|
expect.objectContaining({
|
|
110
|
-
message: "Could not resolve cell builder plugin",
|
|
110
|
+
message: "Could not resolve cell builder plugin: foo",
|
|
111
111
|
})
|
|
112
112
|
);
|
|
113
113
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { FocusableGroupNative } from "@applicaster/zapp-react-native-ui-components/Components/NativeFocusables";
|
|
3
3
|
import { BaseFocusable } from "@applicaster/zapp-react-native-ui-components/Components/BaseFocusable";
|
|
4
|
-
|
|
4
|
+
// TODO: Enable when will be feature flags
|
|
5
|
+
// import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
5
6
|
import { LayoutContext } from "@applicaster/zapp-react-native-tvos-app/Context/LayoutContext";
|
|
6
7
|
import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute";
|
|
7
8
|
import { isScreenPlayable } from "@applicaster/zapp-react-native-utils/navigationUtils/itemTypes";
|
|
8
9
|
import { emitNativeRegistered } from "@applicaster/zapp-react-native-utils/appUtils/focusManagerAux/utils/utils.ios";
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
// TODO: Enable when will be feature flags
|
|
12
|
+
// const { log_verbose } = createLogger({
|
|
13
|
+
// subsystem: "General",
|
|
14
|
+
// category: "FocusableGroup",
|
|
15
|
+
// });
|
|
14
16
|
|
|
15
17
|
type FocusableGroupNativeEvent = {
|
|
16
18
|
nativeEvent: {
|
|
@@ -59,12 +61,14 @@ class FocusableGroupComponent extends BaseFocusable<Props> {
|
|
|
59
61
|
} = this.props;
|
|
60
62
|
|
|
61
63
|
const onGroupFocus = ({ nativeEvent }: FocusableGroupNativeEvent) => {
|
|
62
|
-
|
|
64
|
+
// TODO: Enable when will be feature flags
|
|
65
|
+
// log_verbose("FOCUSABLE_GROUP: onGroupFocus", { nativeEvent });
|
|
63
66
|
this.onFocus(this.ref, nativeEvent.focusHeading);
|
|
64
67
|
};
|
|
65
68
|
|
|
66
69
|
const onGroupBlur = ({ nativeEvent }: FocusableGroupNativeEvent) => {
|
|
67
|
-
|
|
70
|
+
// TODO: Enable when will be feature flags
|
|
71
|
+
// log_verbose("FOCUSABLE_GROUP: onGroupBlur", { nativeEvent });
|
|
68
72
|
this.onBlur(this.ref, nativeEvent.focusHeading);
|
|
69
73
|
};
|
|
70
74
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { GeneralContentScreen } from "./GeneralContentScreen";
|
|
3
|
+
import { HookContentFocusGroup } from "./hookFocus";
|
|
4
|
+
import { runInBackground } from "./hookAdapter/runInBackground";
|
|
5
|
+
import { log_error } from "./hookAdapter/logger";
|
|
6
|
+
|
|
7
|
+
type HookComponentProps = HookPluginProps & {
|
|
8
|
+
configuration?: unknown;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function GeneralContentScreenHookComponent(props: HookComponentProps) {
|
|
12
|
+
const { hookPlugin, focused, parentFocus } = props;
|
|
13
|
+
|
|
14
|
+
if (!hookPlugin?.screen_id) {
|
|
15
|
+
log_error(
|
|
16
|
+
"GeneralContentScreenHookAdapter: This component should only be used as a hook, but no hookPlugin was provided."
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<HookContentFocusGroup>
|
|
24
|
+
<GeneralContentScreen
|
|
25
|
+
screenId={hookPlugin.screen_id}
|
|
26
|
+
isScreenWrappedInContainer={false}
|
|
27
|
+
focused={focused}
|
|
28
|
+
parentFocus={parentFocus}
|
|
29
|
+
/>
|
|
30
|
+
</HookContentFocusGroup>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const GeneralContentScreenHookAdapter = {
|
|
35
|
+
isFlowBlocker: () => true,
|
|
36
|
+
presentFullScreen: true,
|
|
37
|
+
Component: GeneralContentScreenHookComponent,
|
|
38
|
+
runInBackground,
|
|
39
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { GeneralContentScreenHookAdapter } from "../GeneralContentScreenHookAdapter";
|
|
4
|
+
import { log_error } from "../hookAdapter/logger";
|
|
5
|
+
|
|
6
|
+
const mockScreenSpy = jest.fn();
|
|
7
|
+
|
|
8
|
+
jest.mock("../GeneralContentScreen", () => ({
|
|
9
|
+
GeneralContentScreen: (props) => {
|
|
10
|
+
const React = require("react");
|
|
11
|
+
const { View } = require("react-native");
|
|
12
|
+
|
|
13
|
+
mockScreenSpy(props);
|
|
14
|
+
|
|
15
|
+
return <View testID="general-content-screen" />;
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
jest.mock("../hookAdapter/runInBackground", () => ({
|
|
20
|
+
runInBackground: jest.fn(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock("../hookAdapter/logger", () => ({
|
|
24
|
+
log_debug: jest.fn(),
|
|
25
|
+
log_error: jest.fn(),
|
|
26
|
+
log_info: jest.fn(),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const { Component } = GeneralContentScreenHookAdapter;
|
|
30
|
+
|
|
31
|
+
describe("GeneralContentScreenHookAdapter", () => {
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
jest.clearAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("renders GeneralContentScreen with the hook plugin screen id", () => {
|
|
37
|
+
const { getByTestId } = render(
|
|
38
|
+
<Component hookPlugin={{ screen_id: "screen-1" }} focused />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(getByTestId("general-content-screen")).toBeDefined();
|
|
42
|
+
|
|
43
|
+
expect(mockScreenSpy).toHaveBeenCalledWith(
|
|
44
|
+
expect.objectContaining({
|
|
45
|
+
screenId: "screen-1",
|
|
46
|
+
isScreenWrappedInContainer: false,
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("renders nothing and logs an error when hookPlugin is missing", () => {
|
|
52
|
+
const { toJSON } = render(<Component />);
|
|
53
|
+
|
|
54
|
+
expect(toJSON()).toBeNull();
|
|
55
|
+
expect(mockScreenSpy).not.toHaveBeenCalled();
|
|
56
|
+
expect(log_error).toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("renders nothing when hookPlugin has no screen_id", () => {
|
|
60
|
+
const { toJSON } = render(<Component hookPlugin={{}} />);
|
|
61
|
+
|
|
62
|
+
expect(toJSON()).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
|
|
5
|
+
import { HookContentFocusGroup } from "../hookFocus/index.web";
|
|
6
|
+
|
|
7
|
+
const mockFocusableGroupSpy = jest.fn();
|
|
8
|
+
const mockUseInitialFocusSpy = jest.fn();
|
|
9
|
+
|
|
10
|
+
const mockModalState = { isRunningInBackground: false };
|
|
11
|
+
|
|
12
|
+
jest.mock("../../FocusableGroup", () => ({
|
|
13
|
+
FocusableGroup: (props) => {
|
|
14
|
+
const React = require("react");
|
|
15
|
+
const { View } = require("react-native");
|
|
16
|
+
|
|
17
|
+
mockFocusableGroupSpy(props);
|
|
18
|
+
|
|
19
|
+
return <View testID="focusable-group">{props.children}</View>;
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
|
|
24
|
+
useContentId: () => "quick-brick-content___route",
|
|
25
|
+
useNavbarId: () => "quick-brick-navbar___route",
|
|
26
|
+
usePathname: () => "hooks-modal/profile-select",
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
jest.mock("../../Screen/TV/hooks", () => ({
|
|
30
|
+
useInitialFocus: () => mockUseInitialFocusSpy(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock("../../../Contexts/ZappHookModalContext", () => ({
|
|
34
|
+
useZappHookModalStore: (selector) => selector(mockModalState),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
describe("HookContentFocusGroup (web)", () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
jest.clearAllMocks();
|
|
40
|
+
mockModalState.isRunningInBackground = false;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("wraps content in a preferred-focus content group and triggers initial focus when presented full screen", () => {
|
|
44
|
+
const { getByTestId } = render(
|
|
45
|
+
<HookContentFocusGroup>
|
|
46
|
+
<View testID="child" />
|
|
47
|
+
</HookContentFocusGroup>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(getByTestId("focusable-group")).toBeDefined();
|
|
51
|
+
expect(getByTestId("child")).toBeDefined();
|
|
52
|
+
expect(mockUseInitialFocusSpy).toHaveBeenCalledTimes(1);
|
|
53
|
+
|
|
54
|
+
expect(mockFocusableGroupSpy).toHaveBeenCalledWith(
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
id: "quick-brick-content___route",
|
|
57
|
+
groupId: "hooks-modal/profile-select",
|
|
58
|
+
nextFocusUp: "quick-brick-navbar___route",
|
|
59
|
+
preferredFocus: true,
|
|
60
|
+
shouldUsePreferredFocus: true,
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("injects the content group id into the wrapped child so its cells register under it", () => {
|
|
66
|
+
render(
|
|
67
|
+
<HookContentFocusGroup>
|
|
68
|
+
<View testID="child" />
|
|
69
|
+
</HookContentFocusGroup>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const child = mockFocusableGroupSpy.mock.calls[0][0].children;
|
|
73
|
+
|
|
74
|
+
expect(child.props.groupId).toBe("quick-brick-content___route");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("renders the child without focus handling when running in background (not full screen)", () => {
|
|
78
|
+
mockModalState.isRunningInBackground = true;
|
|
79
|
+
|
|
80
|
+
const { getByTestId, queryByTestId } = render(
|
|
81
|
+
<HookContentFocusGroup>
|
|
82
|
+
<View testID="child" />
|
|
83
|
+
</HookContentFocusGroup>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(getByTestId("child")).toBeDefined();
|
|
87
|
+
expect(queryByTestId("focusable-group")).toBeNull();
|
|
88
|
+
expect(mockUseInitialFocusSpy).not.toHaveBeenCalled();
|
|
89
|
+
expect(mockFocusableGroupSpy).not.toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { requestToSkipHook } from "../networkService";
|
|
2
|
+
|
|
3
|
+
const mockCall = jest.fn();
|
|
4
|
+
const mockBuildAxiosRequest = jest.fn();
|
|
5
|
+
let mockHelper: Record<string, any>;
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-pipes-v2-client", () => ({
|
|
8
|
+
RequestBuilder: jest.fn().mockImplementation(() => ({
|
|
9
|
+
setEntryContext: jest.fn().mockReturnThis(),
|
|
10
|
+
setScreenContext: jest.fn().mockReturnThis(),
|
|
11
|
+
setUrl: jest.fn().mockReturnThis(),
|
|
12
|
+
buildAxiosRequest: (...args) => mockBuildAxiosRequest(...args),
|
|
13
|
+
call: (...args) => mockCall(...args),
|
|
14
|
+
})),
|
|
15
|
+
PipesClientResponseHelper: jest.fn().mockImplementation(() => mockHelper),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
jest.mock("../logger", () => ({
|
|
19
|
+
log_debug: jest.fn(),
|
|
20
|
+
log_error: jest.fn(),
|
|
21
|
+
log_info: jest.fn(),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
const dataSource = { source: "https://skip-endpoint", mapping: {} };
|
|
25
|
+
const payload = { id: "entry-1" };
|
|
26
|
+
|
|
27
|
+
describe("requestToSkipHook", () => {
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
mockBuildAxiosRequest.mockResolvedValue({ url: "https://skip-endpoint" });
|
|
31
|
+
mockCall.mockResolvedValue({});
|
|
32
|
+
|
|
33
|
+
mockHelper = {
|
|
34
|
+
error: null,
|
|
35
|
+
statusCode: 200,
|
|
36
|
+
responseData: null,
|
|
37
|
+
getLogsData: jest.fn(() => ({})),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("returns true when the endpoint returns a non-empty body", async () => {
|
|
42
|
+
mockHelper.responseData = true;
|
|
43
|
+
|
|
44
|
+
await expect(requestToSkipHook(dataSource, payload)).resolves.toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("treats any truthy payload as skip (hook-screen-wrapper contract)", async () => {
|
|
48
|
+
mockHelper.responseData = { entry: [] };
|
|
49
|
+
|
|
50
|
+
await expect(requestToSkipHook(dataSource, payload)).resolves.toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("returns false when the endpoint returns an empty body", async () => {
|
|
54
|
+
mockHelper.responseData = null;
|
|
55
|
+
|
|
56
|
+
await expect(requestToSkipHook(dataSource, payload)).resolves.toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("throws when the response contains an error", async () => {
|
|
60
|
+
mockHelper.error = new Error("server error");
|
|
61
|
+
|
|
62
|
+
await expect(requestToSkipHook(dataSource, payload)).rejects.toThrow(
|
|
63
|
+
"server error"
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("throws when the request itself fails", async () => {
|
|
68
|
+
mockCall.mockRejectedValue(new Error("network down"));
|
|
69
|
+
|
|
70
|
+
await expect(requestToSkipHook(dataSource, payload)).rejects.toThrow(
|
|
71
|
+
"network down"
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { runInBackground } from "../runInBackground";
|
|
2
|
+
import { shouldSkipHook } from "../validationHelper";
|
|
3
|
+
import { requestToSkipHook } from "../networkService";
|
|
4
|
+
|
|
5
|
+
jest.mock("../validationHelper", () => ({
|
|
6
|
+
shouldSkipHook: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
jest.mock("../networkService", () => ({
|
|
10
|
+
requestToSkipHook: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock("../logger", () => ({
|
|
14
|
+
log_debug: jest.fn(),
|
|
15
|
+
log_error: jest.fn(),
|
|
16
|
+
log_info: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const mockShouldSkipHook = shouldSkipHook as jest.Mock;
|
|
20
|
+
const mockRequestToSkipHook = requestToSkipHook as jest.Mock;
|
|
21
|
+
|
|
22
|
+
const item = { id: "entry-1" };
|
|
23
|
+
const endpoint = { source: "https://skip-endpoint", mapping: {} };
|
|
24
|
+
|
|
25
|
+
describe("runInBackground", () => {
|
|
26
|
+
let callback: jest.Mock;
|
|
27
|
+
let presentUI: jest.Mock;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
jest.clearAllMocks();
|
|
31
|
+
callback = jest.fn();
|
|
32
|
+
presentUI = jest.fn();
|
|
33
|
+
mockShouldSkipHook.mockResolvedValue(false);
|
|
34
|
+
mockRequestToSkipHook.mockResolvedValue(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("presents the UI when no skip rules are configured", async () => {
|
|
38
|
+
await runInBackground(item, callback, {}, presentUI);
|
|
39
|
+
|
|
40
|
+
expect(presentUI).toHaveBeenCalled();
|
|
41
|
+
expect(callback).not.toHaveBeenCalled();
|
|
42
|
+
expect(mockShouldSkipHook).not.toHaveBeenCalled();
|
|
43
|
+
expect(mockRequestToSkipHook).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("finishes the hook when a storage key is found, without calling the endpoint", async () => {
|
|
47
|
+
mockShouldSkipHook.mockResolvedValue(true);
|
|
48
|
+
|
|
49
|
+
const configuration = {
|
|
50
|
+
rules: {
|
|
51
|
+
skip_hook_storage_key: "ns.key",
|
|
52
|
+
skip_hook_endpoint: endpoint,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
57
|
+
|
|
58
|
+
expect(mockShouldSkipHook).toHaveBeenCalledWith("ns.key");
|
|
59
|
+
|
|
60
|
+
expect(callback).toHaveBeenCalledWith({
|
|
61
|
+
success: true,
|
|
62
|
+
error: null,
|
|
63
|
+
payload: item,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(mockRequestToSkipHook).not.toHaveBeenCalled();
|
|
67
|
+
expect(presentUI).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("falls through to the endpoint check when storage keys are not found", async () => {
|
|
71
|
+
const configuration = {
|
|
72
|
+
rules: {
|
|
73
|
+
skip_hook_storage_key: "ns.key",
|
|
74
|
+
skip_hook_endpoint: endpoint,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
79
|
+
|
|
80
|
+
expect(mockRequestToSkipHook).toHaveBeenCalledWith(endpoint, item);
|
|
81
|
+
expect(presentUI).toHaveBeenCalled();
|
|
82
|
+
expect(callback).not.toHaveBeenCalled();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("finishes the hook when the endpoint allows skipping", async () => {
|
|
86
|
+
mockRequestToSkipHook.mockResolvedValue(true);
|
|
87
|
+
|
|
88
|
+
const configuration = {
|
|
89
|
+
rules: { skip_hook_endpoint: endpoint },
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
93
|
+
|
|
94
|
+
expect(callback).toHaveBeenCalledWith({
|
|
95
|
+
success: true,
|
|
96
|
+
error: null,
|
|
97
|
+
payload: item,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(presentUI).not.toHaveBeenCalled();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("ignores an endpoint configuration without a source", async () => {
|
|
104
|
+
const configuration = {
|
|
105
|
+
rules: { skip_hook_endpoint: { mapping: {} } },
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
109
|
+
|
|
110
|
+
expect(mockRequestToSkipHook).not.toHaveBeenCalled();
|
|
111
|
+
expect(presentUI).toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("presents the UI when the endpoint check throws", async () => {
|
|
115
|
+
mockRequestToSkipHook.mockRejectedValue(new Error("network down"));
|
|
116
|
+
|
|
117
|
+
const configuration = {
|
|
118
|
+
rules: { skip_hook_endpoint: endpoint },
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
122
|
+
|
|
123
|
+
expect(presentUI).toHaveBeenCalled();
|
|
124
|
+
expect(callback).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("presents the UI when the storage check throws", async () => {
|
|
128
|
+
mockShouldSkipHook.mockRejectedValue(new Error("storage error"));
|
|
129
|
+
|
|
130
|
+
const configuration = {
|
|
131
|
+
rules: { skip_hook_storage_key: "ns.key" },
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
135
|
+
|
|
136
|
+
expect(presentUI).toHaveBeenCalled();
|
|
137
|
+
expect(callback).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
});
|