@applicaster/zapp-react-native-ui-components 15.0.0-rc.141 → 15.0.0-rc.143
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.
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
|
+
jest.mock(
|
|
6
|
+
"@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration",
|
|
7
|
+
() => ({
|
|
8
|
+
useScreenConfiguration: jest.fn(),
|
|
9
|
+
})
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
jest.mock(
|
|
13
|
+
"@applicaster/zapp-react-native-ui-components/Components/TopCutoffOverlay/hooks",
|
|
14
|
+
() => ({
|
|
15
|
+
useMarginTop: jest.fn(),
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
|
|
20
|
+
useTheme: jest.fn(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
import { TopCutoffOverlay } from "../index";
|
|
24
|
+
import { useMarginTop } from "../hooks";
|
|
25
|
+
import { useScreenConfiguration } from "../../River/useScreenConfiguration";
|
|
26
|
+
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
27
|
+
|
|
28
|
+
// Recursively find a View with position: absolute in the JSON tree
|
|
29
|
+
const findOverlayStyle = (node: any): Record<string, any> | null => {
|
|
30
|
+
if (!node) return null;
|
|
31
|
+
|
|
32
|
+
// Style can be a plain object or an array of style objects
|
|
33
|
+
const styles = Array.isArray(node.props?.style)
|
|
34
|
+
? node.props.style
|
|
35
|
+
: node.props?.style
|
|
36
|
+
? [node.props.style]
|
|
37
|
+
: [];
|
|
38
|
+
|
|
39
|
+
const styleObj = styles.find((s: any) => s?.position === "absolute");
|
|
40
|
+
if (styleObj) return styleObj;
|
|
41
|
+
|
|
42
|
+
const children = node.children || [];
|
|
43
|
+
|
|
44
|
+
if (Array.isArray(children)) {
|
|
45
|
+
for (const child of children) {
|
|
46
|
+
const result = findOverlayStyle(child);
|
|
47
|
+
if (result) return result;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const propChildren = node.props?.children;
|
|
52
|
+
|
|
53
|
+
if (propChildren && Array.isArray(propChildren)) {
|
|
54
|
+
for (const child of propChildren) {
|
|
55
|
+
const result = findOverlayStyle(child);
|
|
56
|
+
if (result) return result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
typeof propChildren === "object" &&
|
|
62
|
+
propChildren !== null &&
|
|
63
|
+
"type" in propChildren
|
|
64
|
+
) {
|
|
65
|
+
return findOverlayStyle(propChildren);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return null;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
describe("TopCutoffOverlay", () => {
|
|
72
|
+
const mockUseMarginTop = useMarginTop as jest.MockedFunction<
|
|
73
|
+
typeof useMarginTop
|
|
74
|
+
>;
|
|
75
|
+
|
|
76
|
+
const mockUseScreenConfig = useScreenConfiguration as jest.MockedFunction<
|
|
77
|
+
typeof useScreenConfiguration
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
const mockUseTheme = useTheme as jest.MockedFunction<typeof useTheme>;
|
|
81
|
+
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
jest.clearAllMocks();
|
|
84
|
+
mockUseMarginTop.mockReturnValue(60);
|
|
85
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "#1a1a1a" });
|
|
86
|
+
mockUseTheme.mockReturnValue({ app_background_color: "#222222" });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("renders children when applyTopCutoff is false", () => {
|
|
90
|
+
const { getByText } = render(
|
|
91
|
+
<TopCutoffOverlay applyTopCutoff={false}>
|
|
92
|
+
<Text>Child content</Text>
|
|
93
|
+
</TopCutoffOverlay>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(getByText("Child content")).toBeTruthy();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("does not render overlay when applyTopCutoff is false", () => {
|
|
100
|
+
const tree = render(
|
|
101
|
+
<TopCutoffOverlay applyTopCutoff={false}>
|
|
102
|
+
<Text>Child content</Text>
|
|
103
|
+
</TopCutoffOverlay>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(findOverlayStyle(tree.toJSON())).toBeNull();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("renders overlay when applyTopCutoff is true (default)", () => {
|
|
110
|
+
const tree = render(
|
|
111
|
+
<TopCutoffOverlay>
|
|
112
|
+
<Text>Child content</Text>
|
|
113
|
+
</TopCutoffOverlay>
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(findOverlayStyle(tree.toJSON())).not.toBeNull();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("renders overlay with correct height from useMarginTop", () => {
|
|
120
|
+
const tree = render(
|
|
121
|
+
<TopCutoffOverlay>
|
|
122
|
+
<Text>Child content</Text>
|
|
123
|
+
</TopCutoffOverlay>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(findOverlayStyle(tree.toJSON())?.height).toBe(60);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("uses screenBackgroundColor from useScreenConfiguration when available", () => {
|
|
130
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "#ff0000" });
|
|
131
|
+
|
|
132
|
+
const tree = render(
|
|
133
|
+
<TopCutoffOverlay>
|
|
134
|
+
<Text>Child content</Text>
|
|
135
|
+
</TopCutoffOverlay>
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#ff0000");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("falls back to themeBackgroundColor when screenBackgroundColor is not available", () => {
|
|
142
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: undefined });
|
|
143
|
+
|
|
144
|
+
const tree = render(
|
|
145
|
+
<TopCutoffOverlay>
|
|
146
|
+
<Text>Child content</Text>
|
|
147
|
+
</TopCutoffOverlay>
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("falls back to transparent when neither screenBackgroundColor nor themeBackgroundColor is available", () => {
|
|
154
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: undefined });
|
|
155
|
+
mockUseTheme.mockReturnValue({});
|
|
156
|
+
|
|
157
|
+
const tree = render(
|
|
158
|
+
<TopCutoffOverlay>
|
|
159
|
+
<Text>Child content</Text>
|
|
160
|
+
</TopCutoffOverlay>
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe(
|
|
164
|
+
"transparent"
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("passes targetScreenId to useMarginTop and useScreenConfiguration", () => {
|
|
169
|
+
render(
|
|
170
|
+
<TopCutoffOverlay targetScreenId="custom-screen-1">
|
|
171
|
+
<Text>Child content</Text>
|
|
172
|
+
</TopCutoffOverlay>
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
expect(mockUseMarginTop).toHaveBeenCalledWith("custom-screen-1");
|
|
176
|
+
expect(mockUseScreenConfig).toHaveBeenCalledWith("custom-screen-1");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("positions overlay at top with left/right 0", () => {
|
|
180
|
+
const tree = render(
|
|
181
|
+
<TopCutoffOverlay>
|
|
182
|
+
<Text>Child content</Text>
|
|
183
|
+
</TopCutoffOverlay>
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const style = findOverlayStyle(tree.toJSON());
|
|
187
|
+
expect(style?.top).toBe(0);
|
|
188
|
+
expect(style?.left).toBe(0);
|
|
189
|
+
expect(style?.right).toBe(0);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("renders children inside the container", () => {
|
|
193
|
+
const { getByText } = render(
|
|
194
|
+
<TopCutoffOverlay>
|
|
195
|
+
<Text>Child content</Text>
|
|
196
|
+
</TopCutoffOverlay>
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
expect(getByText("Child content")).toBeTruthy();
|
|
200
|
+
});
|
|
201
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "15.0.0-rc.
|
|
3
|
+
"version": "15.0.0-rc.143",
|
|
4
4
|
"description": "Applicaster Zapp React Native ui components for the Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "15.0.0-rc.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "15.0.0-rc.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "15.0.0-rc.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "15.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "15.0.0-rc.143",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "15.0.0-rc.143",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "15.0.0-rc.143",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "15.0.0-rc.143",
|
|
35
35
|
"fast-json-stable-stringify": "^2.1.0",
|
|
36
36
|
"promise": "^8.3.0",
|
|
37
37
|
"url": "^0.11.0",
|