@applicaster/zapp-react-native-utils 15.1.12 → 15.1.13-alpha.4042438573

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": "15.1.12",
3
+ "version": "15.1.13-alpha.4042438573",
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": "15.1.12",
30
+ "@applicaster/applicaster-types": "15.1.13-alpha.4042438573",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -7,6 +7,7 @@ import { waitFor } from "@testing-library/react-native";
7
7
 
8
8
  const mockNavigator = {
9
9
  getPathname: () => "pathnameMock",
10
+ currentRoute: "pathnameMock",
10
11
  push: jest.fn(),
11
12
  data: {},
12
13
  };
@@ -31,6 +32,7 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
31
32
  ),
32
33
  useTargetScreenData: jest.fn(() => ({})),
33
34
  useCurrentScreenData: jest.fn(() => ({})),
35
+ useScreenContext: jest.fn(() => ({})),
34
36
  }));
35
37
 
36
38
  jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
@@ -68,6 +70,12 @@ const wrapper = ({ children }) => (
68
70
  </CellTapContext.Provider>
69
71
  );
70
72
 
73
+ const actionExecutorWrapper = ({ children }) => (
74
+ <ActionExecutorContext.Provider value={actionExecutor}>
75
+ {children}
76
+ </ActionExecutorContext.Provider>
77
+ );
78
+
71
79
  describe("useCellClick", () => {
72
80
  it("returns a function", () => {
73
81
  const { result } = renderHook(() => useCellClick(mockProps));
@@ -97,4 +105,60 @@ describe("useCellClick", () => {
97
105
 
98
106
  cleanup();
99
107
  });
108
+
109
+ it("does not push when the cell finishes a hook", async () => {
110
+ mockNavigator.push.mockClear();
111
+
112
+ const item = {
113
+ id: "profile-1",
114
+ type: { value: "feed" },
115
+ extensions: {
116
+ tap_actions: {
117
+ actions: [
118
+ { type: "sessionStorageSet" },
119
+ { type: "finishHook", options: { success: true } },
120
+ ],
121
+ },
122
+ },
123
+ };
124
+
125
+ const { result } = renderHook(() => useCellClick({ item }), {
126
+ wrapper: actionExecutorWrapper,
127
+ });
128
+
129
+ await result.current();
130
+
131
+ await waitFor(() => {
132
+ expect(actionExecutor.handleEntryActions).toHaveBeenCalled();
133
+ });
134
+
135
+ expect(mockNavigator.push).not.toHaveBeenCalled();
136
+ cleanup();
137
+ });
138
+
139
+ it("pushes after tap actions that do not finish a hook", async () => {
140
+ mockNavigator.push.mockClear();
141
+
142
+ const item = {
143
+ id: "episode-1",
144
+ type: { value: "feed" },
145
+ extensions: {
146
+ tap_actions: {
147
+ actions: [{ type: "sessionStorageSet" }],
148
+ },
149
+ },
150
+ };
151
+
152
+ const { result } = renderHook(() => useCellClick({ item }), {
153
+ wrapper: actionExecutorWrapper,
154
+ });
155
+
156
+ await result.current();
157
+
158
+ await waitFor(() => {
159
+ expect(mockNavigator.push).toHaveBeenCalled();
160
+ });
161
+
162
+ cleanup();
163
+ });
100
164
  });
@@ -82,6 +82,12 @@ export const useCellClick = ({
82
82
 
83
83
  logOnPress(selectedItem, pathname, component, onCellTap);
84
84
 
85
+ const tapActions = selectedItem?.extensions?.tap_actions?.actions;
86
+
87
+ const finishesHook =
88
+ Array.isArray(tapActions) &&
89
+ tapActions.some((action) => action?.type === "finishHook");
90
+
85
91
  if (selectedItem) {
86
92
  await actionExecutor?.handleEntryActions(selectedItem, {
87
93
  component,
@@ -99,20 +105,21 @@ export const useCellClick = ({
99
105
  url: selectedItem.link.href,
100
106
  });
101
107
  }
102
- } else {
103
- if (isFunction(onCellTap)) {
104
- onCellTap?.(selectedItem, _index);
105
- } else {
106
- if (currentRoute === pathname || pathname.includes("video-modal")) {
107
- const targetScreen = component?.data?.target;
108
-
109
- push(
110
- R.when(
111
- () => targetScreen,
112
- R.mergeLeft({ screen_type: targetScreen })
113
- )(selectedItem)
114
- );
115
- }
108
+ } else if (isFunction(onCellTap)) {
109
+ onCellTap?.(selectedItem, _index);
110
+ } else if (!finishesHook) {
111
+ // finishHook already completes the hook and navigates to the original
112
+ // target. Pushing the cell as well stacks a second copy of that screen
113
+ // (e.g. home/home after a profile selector hook).
114
+ if (currentRoute === pathname || pathname.includes("video-modal")) {
115
+ const targetScreen = component?.data?.target;
116
+
117
+ push(
118
+ R.when(
119
+ () => targetScreen,
120
+ R.mergeLeft({ screen_type: targetScreen })
121
+ )(selectedItem)
122
+ );
116
123
  }
117
124
  }
118
125
  },