@applicaster/zapp-react-native-utils 16.0.0-rc.52 → 16.0.0-rc.54

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,63 @@
1
+ import { showToastAction } from "../showToast";
2
+ import { postEvent } from "../../../reactHooks/useSubscriberFor";
3
+ import { ActionResult } from "../../ActionExecutor";
4
+
5
+ jest.mock("../../../reactHooks/useSubscriberFor", () => ({
6
+ postEvent: jest.fn(),
7
+ }));
8
+
9
+ describe("showToastAction", () => {
10
+ beforeEach(() => {
11
+ jest.clearAllMocks();
12
+ });
13
+
14
+ it("calls postEvent with showToast payload and returns ActionResult.Success", async () => {
15
+ const action = {
16
+ type: "showToast",
17
+ options: {
18
+ id: "toast-1",
19
+ message: "Added to queue",
20
+ extraMessage: "Extra info",
21
+ timeout: 3000,
22
+ },
23
+ };
24
+
25
+ const result = await showToastAction(action);
26
+
27
+ expect(postEvent).toHaveBeenCalledTimes(1);
28
+
29
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
30
+ {
31
+ id: "toast-1",
32
+ message: "Added to queue",
33
+ extraMessage: "Extra info",
34
+ style: undefined,
35
+ timeout: 3000,
36
+ },
37
+ ]);
38
+
39
+ expect(result).toBe(ActionResult.Success);
40
+ });
41
+
42
+ it("handles missing or empty options without throwing", async () => {
43
+ const action = {
44
+ type: "showToast",
45
+ };
46
+
47
+ const result = await showToastAction(action);
48
+
49
+ expect(postEvent).toHaveBeenCalledTimes(1);
50
+
51
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
52
+ {
53
+ id: undefined,
54
+ message: undefined,
55
+ extraMessage: undefined,
56
+ style: undefined,
57
+ timeout: undefined,
58
+ },
59
+ ]);
60
+
61
+ expect(result).toBe(ActionResult.Success);
62
+ });
63
+ });
@@ -7,8 +7,8 @@ import { postEvent } from "../../reactHooks/useSubscriberFor";
7
7
  * Options for showToast action.
8
8
  */
9
9
  export interface ShowToastActionOptions {
10
- id: string;
11
- message: string;
10
+ id?: string;
11
+ message?: string;
12
12
  extraMessage?: string;
13
13
  style?: any;
14
14
  timeout?: number;
@@ -19,11 +19,11 @@ export const showToastAction: ActionHandler<ShowToastActionOptions> = async (
19
19
  ): Promise<ActionResult> => {
20
20
  postEvent("showToast", [
21
21
  {
22
- id: action.options.id,
23
- message: action.options.message,
24
- extraMessage: action.options.extraMessage,
25
- style: action.options.style,
26
- timeout: action.options.timeout,
22
+ id: action?.options?.id,
23
+ message: action?.options?.message,
24
+ extraMessage: action?.options?.extraMessage,
25
+ style: action?.options?.style,
26
+ timeout: action?.options?.timeout,
27
27
  },
28
28
  ]);
29
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-rc.52",
3
+ "version": "16.0.0-rc.54",
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.52",
30
+ "@applicaster/applicaster-types": "16.0.0-rc.54",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -59,6 +59,8 @@ export async function batchSave(
59
59
  return false;
60
60
  }
61
61
 
62
+ const promises = [];
63
+
62
64
  for (const namespace of Object.keys(storageValues)) {
63
65
  const namespaceData = storageValues[namespace];
64
66
 
@@ -66,10 +68,12 @@ export async function batchSave(
66
68
  const value = namespaceData[key];
67
69
 
68
70
  if (!isNilOrEmpty(value)) {
69
- await storage.setItem(key, value, namespace);
71
+ promises.push(storage.setItem(key, value, namespace));
70
72
  }
71
73
  }
72
74
  }
75
+
76
+ await Promise.all(promises);
73
77
  }
74
78
 
75
79
  export async function batchSaveToLocalStorage(
@@ -82,13 +86,17 @@ export async function batchRemoveFromStorage(
82
86
  storageValues: StorageValuesToRemove,
83
87
  storage: Storage = localStorage
84
88
  ) {
89
+ const promises = [];
90
+
85
91
  for (const namespace of Object.keys(storageValues)) {
86
92
  const namespaceData = storageValues[namespace];
87
93
 
88
94
  for (const key of namespaceData) {
89
- await storage.removeItem(key, namespace);
95
+ promises.push(storage.removeItem(key, namespace));
90
96
  }
91
97
  }
98
+
99
+ await Promise.all(promises);
92
100
  }
93
101
 
94
102
  export async function batchRemoveFromLocalStorage(