@applicaster/zapp-react-native-utils 16.0.0-rc.4 → 16.0.0-rc.6
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-rc.
|
|
3
|
+
"version": "16.0.0-rc.6",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "16.0.0-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-rc.6",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-native";
|
|
2
|
+
import { useIsStandaloneFullscreen } from "../useIsStandaloneFullscreen";
|
|
3
|
+
|
|
4
|
+
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
5
|
+
import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks");
|
|
8
|
+
jest.mock("@applicaster/zapp-react-native-utils/booleanUtils");
|
|
9
|
+
|
|
10
|
+
const mockUseNavigation = useNavigation as jest.Mock;
|
|
11
|
+
const mockToBoolean = toBooleanWithDefaultFalse as jest.Mock;
|
|
12
|
+
|
|
13
|
+
describe("useIsStandaloneFullscreen", () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
|
|
17
|
+
mockUseNavigation.mockReturnValue({
|
|
18
|
+
canGoBack: jest.fn().mockReturnValue(false),
|
|
19
|
+
screenData: {
|
|
20
|
+
general: { allow_screen_plugin_presentation: true },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
mockToBoolean.mockReturnValue(false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("returns true when cannot go back and screen plugin presentation is allowed", () => {
|
|
28
|
+
mockToBoolean.mockReturnValue(true);
|
|
29
|
+
|
|
30
|
+
const { result } = renderHook(() => useIsStandaloneFullscreen());
|
|
31
|
+
|
|
32
|
+
expect(mockToBoolean).toHaveBeenCalledWith(true);
|
|
33
|
+
expect(result.current).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("returns false when can go back even if screen plugin presentation is allowed", () => {
|
|
37
|
+
mockUseNavigation.mockReturnValue({
|
|
38
|
+
canGoBack: jest.fn().mockReturnValue(true),
|
|
39
|
+
screenData: {
|
|
40
|
+
general: { allow_screen_plugin_presentation: true },
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
mockToBoolean.mockReturnValue(false);
|
|
45
|
+
|
|
46
|
+
const { result } = renderHook(() => useIsStandaloneFullscreen());
|
|
47
|
+
|
|
48
|
+
expect(mockToBoolean).toHaveBeenCalledWith(false);
|
|
49
|
+
expect(result.current).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("returns false when cannot go back but screen plugin presentation is not allowed", () => {
|
|
53
|
+
mockUseNavigation.mockReturnValue({
|
|
54
|
+
canGoBack: jest.fn().mockReturnValue(false),
|
|
55
|
+
screenData: {
|
|
56
|
+
general: { allow_screen_plugin_presentation: false },
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
mockToBoolean.mockReturnValue(false);
|
|
61
|
+
|
|
62
|
+
const { result } = renderHook(() => useIsStandaloneFullscreen());
|
|
63
|
+
|
|
64
|
+
expect(mockToBoolean).toHaveBeenCalledWith(false);
|
|
65
|
+
expect(result.current).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("returns false when screen plugin presentation flag is undefined", () => {
|
|
69
|
+
mockUseNavigation.mockReturnValue({
|
|
70
|
+
canGoBack: jest.fn().mockReturnValue(false),
|
|
71
|
+
screenData: { general: {} },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
mockToBoolean.mockReturnValue(false);
|
|
75
|
+
|
|
76
|
+
const { result } = renderHook(() => useIsStandaloneFullscreen());
|
|
77
|
+
|
|
78
|
+
expect(mockToBoolean).toHaveBeenCalledWith(undefined);
|
|
79
|
+
expect(result.current).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("returns false when navigator is undefined", () => {
|
|
83
|
+
mockUseNavigation.mockReturnValue(undefined);
|
|
84
|
+
mockToBoolean.mockReturnValue(false);
|
|
85
|
+
|
|
86
|
+
const { result } = renderHook(() => useIsStandaloneFullscreen());
|
|
87
|
+
|
|
88
|
+
expect(mockToBoolean).toHaveBeenCalledWith(undefined);
|
|
89
|
+
expect(result.current).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("returns false when screenData is undefined", () => {
|
|
93
|
+
mockUseNavigation.mockReturnValue({
|
|
94
|
+
canGoBack: jest.fn().mockReturnValue(false),
|
|
95
|
+
screenData: undefined,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
mockToBoolean.mockReturnValue(false);
|
|
99
|
+
|
|
100
|
+
const { result } = renderHook(() => useIsStandaloneFullscreen());
|
|
101
|
+
|
|
102
|
+
expect(mockToBoolean).toHaveBeenCalledWith(undefined);
|
|
103
|
+
expect(result.current).toBe(false);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("passes the combined condition through toBooleanWithDefaultFalse", () => {
|
|
107
|
+
mockToBoolean.mockImplementation((val) => Boolean(val));
|
|
108
|
+
|
|
109
|
+
const { result } = renderHook(() => useIsStandaloneFullscreen());
|
|
110
|
+
|
|
111
|
+
expect(mockToBoolean).toHaveBeenCalledWith(true);
|
|
112
|
+
expect(result.current).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -16,3 +16,5 @@ export { useScreenBackgroundColor } from "./useScreenBackgroundColor";
|
|
|
16
16
|
export { useCurrentScreenIsHook } from "./useCurrentScreenIsHook";
|
|
17
17
|
|
|
18
18
|
export { useCurrentScreenIsStartupHook } from "./useCurrentScreenIsStartupHook";
|
|
19
|
+
|
|
20
|
+
export { useIsStandaloneFullscreen } from "./useIsStandaloneFullscreen";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
2
|
+
import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
3
|
+
|
|
4
|
+
export const useIsStandaloneFullscreen = (): boolean => {
|
|
5
|
+
const navigator = useNavigation();
|
|
6
|
+
|
|
7
|
+
return toBooleanWithDefaultFalse(
|
|
8
|
+
!navigator?.canGoBack() &&
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
navigator?.screenData?.general?.allow_screen_plugin_presentation
|
|
11
|
+
);
|
|
12
|
+
};
|