@applicaster/zapp-react-native-bridge 12.0.0-rc.24 → 12.0.0-rc.26
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/OfflineAssets/__tests__/__snapshots__/fileManager.test.ts.snap +2 -2
- package/OfflineAssets/__tests__/fileManager.test.ts +53 -50
- package/QuickBrick/__tests__/quickBrickModule.test.ts +45 -49
- package/QuickBrick/__tests__/quickBrickModule_noModule.test.ts +8 -7
- package/ZappStorage/__tests__/__snapshots__/localStorage.test.ts.snap +12 -12
- package/ZappStorage/__tests__/__snapshots__/sessionStorage.test.ts.snap +12 -12
- package/ZappStorage/__tests__/localStorage.test.ts +383 -383
- package/ZappStorage/__tests__/localStorageAndroid.test.ts +3 -6
- package/ZappStorage/__tests__/sessionStorage.test.ts +415 -394
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`deleteFolders deletes each provided path 1`] = `true`;
|
|
3
|
+
exports[`fileManager deleteFolders deletes each provided path 1`] = `true`;
|
|
4
4
|
|
|
5
|
-
exports[`storeFiles calls the store file function of the native module with the provided args 1`] = `
|
|
5
|
+
exports[`fileManager storeFiles calls the store file function of the native module with the provided args 1`] = `
|
|
6
6
|
Object {
|
|
7
7
|
"http://file": true,
|
|
8
8
|
"http://file2": true,
|
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
+
import * as ReactNative from "react-native";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
NativeModules: {
|
|
5
|
-
OfflineAssetsBridge: {
|
|
6
|
-
storeFiles: jest.fn((files) => {
|
|
7
|
-
if (files.includes("fail")) throw new Error("Error storing file");
|
|
4
|
+
const { NativeModules } = ReactNative;
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const OfflineAssetsBridge = {
|
|
7
|
+
storeFiles: jest.fn((files) => {
|
|
8
|
+
if (files.includes("fail")) throw new Error("Error storing file");
|
|
9
|
+
|
|
10
|
+
return Promise.resolve(
|
|
11
|
+
files.reduce((acc, curr) => {
|
|
12
|
+
return R.assoc(curr.url, true, acc);
|
|
13
|
+
}, {})
|
|
14
|
+
);
|
|
15
|
+
}),
|
|
16
|
+
delete: jest.fn((file) => {
|
|
17
|
+
if (file.includes("fail")) throw new Error("Error deleting file");
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
19
|
+
return Promise.resolve(true);
|
|
20
|
+
}),
|
|
21
|
+
getFilesDirectory: jest.fn(() => Promise.resolve("/native/path/")),
|
|
22
|
+
};
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
NativeModules: { OfflineAssetsBridge },
|
|
27
|
-
} = require("react-native");
|
|
24
|
+
NativeModules.OfflineAssetsBridge = OfflineAssetsBridge;
|
|
28
25
|
|
|
29
26
|
const { storeFiles, deleteFolders, getNativeRootPath } = require("..");
|
|
30
27
|
|
|
@@ -34,47 +31,53 @@ function clearMocks() {
|
|
|
34
31
|
OfflineAssetsBridge.getFilesDirectory.mockClear();
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
describe("
|
|
38
|
-
|
|
34
|
+
describe("fileManager", () => {
|
|
35
|
+
describe("storeFiles", () => {
|
|
36
|
+
beforeEach(clearMocks);
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
it("calls the store file function of the native module with the provided args", async () => {
|
|
39
|
+
const files = [{ url: "http://file" }, { url: "http://file2" }];
|
|
40
|
+
const options = {};
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
const result = await storeFiles(files, options);
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
expect(OfflineAssetsBridge.storeFiles).toHaveBeenCalledWith(
|
|
45
|
+
files,
|
|
46
|
+
options
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(result).toMatchSnapshot();
|
|
50
|
+
});
|
|
48
51
|
});
|
|
49
|
-
});
|
|
50
52
|
|
|
51
|
-
describe("deleteFolders", () => {
|
|
52
|
-
|
|
53
|
+
describe("deleteFolders", () => {
|
|
54
|
+
beforeEach(clearMocks);
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
it("deletes each provided path", async () => {
|
|
57
|
+
const folders = ["folder1", "folder2", "folder3"];
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
const result = await deleteFolders(folders);
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
expect.assertions(folders.length + 2);
|
|
62
|
+
expect(result).toMatchSnapshot();
|
|
63
|
+
expect(OfflineAssetsBridge.delete).toHaveBeenCalledTimes(folders.length);
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
folders.forEach((folder, index) => {
|
|
66
|
+
expect(OfflineAssetsBridge.delete).toHaveBeenNthCalledWith(
|
|
67
|
+
index + 1,
|
|
68
|
+
folder
|
|
69
|
+
);
|
|
70
|
+
});
|
|
68
71
|
});
|
|
69
72
|
});
|
|
70
|
-
});
|
|
71
73
|
|
|
72
|
-
describe("getNativeRootPath", () => {
|
|
73
|
-
|
|
74
|
+
describe("getNativeRootPath", () => {
|
|
75
|
+
beforeEach(clearMocks);
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
it("returns the native root path", async () => {
|
|
78
|
+
const nativePath = await OfflineAssetsBridge.getFilesDirectory();
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
await expect(getNativeRootPath()).resolves.toEqual(nativePath);
|
|
81
|
+
});
|
|
79
82
|
});
|
|
80
83
|
});
|
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
foo: "bar",
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
});
|
|
1
|
+
import * as ReactNative from "react-native";
|
|
2
|
+
|
|
3
|
+
ReactNative.NativeModules.QuickBrickCommunicationModule = {
|
|
4
|
+
quickBrickEvent: jest.fn(),
|
|
5
|
+
accountId: 123,
|
|
6
|
+
accountsAccountId: "accountsAccountIDString1234",
|
|
7
|
+
broadcasterId: 145,
|
|
8
|
+
bundleIdentifier: "com.apptestname",
|
|
9
|
+
initialProps: {
|
|
10
|
+
foo: "bar",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
19
13
|
|
|
20
14
|
const {
|
|
21
15
|
sendQuickBrickEvent,
|
|
22
16
|
getAppData,
|
|
23
17
|
getLegacyInitialProps,
|
|
24
|
-
} = require("
|
|
18
|
+
} = require("..");
|
|
25
19
|
|
|
26
20
|
const eventName = "event";
|
|
27
21
|
const payload = {};
|
|
@@ -33,44 +27,46 @@ const bundleIdentifier = "com.apptestname";
|
|
|
33
27
|
|
|
34
28
|
const { NativeModules } = require("react-native");
|
|
35
29
|
|
|
36
|
-
describe("
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
describe("QuickBrickModule", () => {
|
|
31
|
+
describe("sendQuickBrickEvent", () => {
|
|
32
|
+
it("invokes the native module", () => {
|
|
33
|
+
sendQuickBrickEvent(eventName, payload);
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
expect(
|
|
36
|
+
NativeModules.QuickBrickCommunicationModule.quickBrickEvent
|
|
37
|
+
).toHaveBeenCalledWith(eventName, payload);
|
|
38
|
+
});
|
|
44
39
|
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
it("passes an empty object as payload if not provided", () => {
|
|
41
|
+
sendQuickBrickEvent(eventName);
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
expect(
|
|
44
|
+
NativeModules.QuickBrickCommunicationModule.quickBrickEvent
|
|
45
|
+
).toHaveBeenCalledWith(eventName, {});
|
|
46
|
+
});
|
|
52
47
|
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
NativeModules.QuickBrickCommunicationModule.quickBrickEvent.mockRestore();
|
|
50
|
+
});
|
|
55
51
|
});
|
|
56
|
-
});
|
|
57
52
|
|
|
58
|
-
describe("getAppData", () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
describe("getAppData", () => {
|
|
54
|
+
it("returns the app data", () => {
|
|
55
|
+
const appData = getAppData();
|
|
56
|
+
expect(appData).toHaveProperty("accountId", accountId);
|
|
57
|
+
expect(appData).toHaveProperty("accountsAccountId", accountsAccountId);
|
|
58
|
+
expect(appData).toHaveProperty("broadcasterId", broadcasterId);
|
|
59
|
+
expect(appData).toHaveProperty("bundleIdentifier", bundleIdentifier);
|
|
60
|
+
});
|
|
65
61
|
});
|
|
66
|
-
});
|
|
67
62
|
|
|
68
|
-
describe("getLegacyInitialProps", () => {
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
describe("getLegacyInitialProps", () => {
|
|
64
|
+
it("returns the initial props", () => {
|
|
65
|
+
const initialProps = getLegacyInitialProps();
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
expect(initialProps).toEqual(
|
|
68
|
+
NativeModules.QuickBrickCommunicationModule.initialProps
|
|
69
|
+
);
|
|
70
|
+
});
|
|
75
71
|
});
|
|
76
72
|
});
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
Foo: jest.fn(),
|
|
3
|
-
};
|
|
1
|
+
const { NativeModules } = require("react-native");
|
|
4
2
|
|
|
5
|
-
jest.
|
|
6
|
-
NativeModules: mock_NativeModules,
|
|
7
|
-
}));
|
|
3
|
+
NativeModules.Foo = jest.fn();
|
|
8
4
|
|
|
9
5
|
jest.mock("../../logger", () => ({
|
|
10
6
|
bridgeLogger: {
|
|
@@ -16,7 +12,7 @@ const {
|
|
|
16
12
|
sendQuickBrickEvent,
|
|
17
13
|
getAppData,
|
|
18
14
|
getLegacyInitialProps,
|
|
19
|
-
} = require("../
|
|
15
|
+
} = require("../");
|
|
20
16
|
|
|
21
17
|
const eventName = "event";
|
|
22
18
|
const payload = {};
|
|
@@ -24,6 +20,11 @@ const payload = {};
|
|
|
24
20
|
const { bridgeLogger } = require("../../logger");
|
|
25
21
|
|
|
26
22
|
describe("when QuickBrickCommunication Module is undefined", () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
jest.unmock("react-native");
|
|
25
|
+
jest.resetModules();
|
|
26
|
+
});
|
|
27
|
+
|
|
27
28
|
describe("sendQuickBrickEvent", () => {
|
|
28
29
|
it("throws an error", () => {
|
|
29
30
|
expect(() => sendQuickBrickEvent(eventName, payload)).toThrow();
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`localStorage
|
|
3
|
+
exports[`localStorage getAllItems throws if an error happen on native side 1`] = `"An error occured while getting an item from native storage: namespace not found"`;
|
|
4
4
|
|
|
5
|
-
exports[`localStorage
|
|
5
|
+
exports[`localStorage getItem throws if key is null 1`] = `"Requested key is null or undefined"`;
|
|
6
6
|
|
|
7
|
-
exports[`localStorage
|
|
7
|
+
exports[`localStorage getItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
|
|
8
8
|
|
|
9
|
-
exports[`localStorage
|
|
9
|
+
exports[`localStorage getItem throws if there is an error on the native side 1`] = `"An error occured while getting an item from native storage: failed to get item"`;
|
|
10
10
|
|
|
11
|
-
exports[`localStorage
|
|
11
|
+
exports[`localStorage removeItem throws if a native error is thrown 1`] = `"An error occured while removing an item from native storage: failed to remove item"`;
|
|
12
12
|
|
|
13
|
-
exports[`localStorage
|
|
13
|
+
exports[`localStorage removeItem throws if key is null 1`] = `"Requested key is null or undefined"`;
|
|
14
14
|
|
|
15
|
-
exports[`localStorage
|
|
15
|
+
exports[`localStorage removeItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
|
|
16
16
|
|
|
17
|
-
exports[`localStorage
|
|
17
|
+
exports[`localStorage setItem throws if key is null 1`] = `"Requested key is null or undefined"`;
|
|
18
18
|
|
|
19
|
-
exports[`localStorage
|
|
19
|
+
exports[`localStorage setItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
|
|
20
20
|
|
|
21
|
-
exports[`localStorage
|
|
21
|
+
exports[`localStorage setItem throws if there is an error in the native module 1`] = `"An error occured while setting an item in native storage: failed to set item"`;
|
|
22
22
|
|
|
23
|
-
exports[`localStorage
|
|
23
|
+
exports[`localStorage setItem throws if value is null 1`] = `"Value to set in storage cannot be null or undefined"`;
|
|
24
24
|
|
|
25
|
-
exports[`localStorage
|
|
25
|
+
exports[`localStorage setItem throws if value is undefined 1`] = `"Value to set in storage cannot be null or undefined"`;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`sessionStorage
|
|
3
|
+
exports[`sessionStorage getAllItems throws if an error happen on native side 1`] = `"An error occured while getting an item from native storage: namespace not found"`;
|
|
4
4
|
|
|
5
|
-
exports[`sessionStorage
|
|
5
|
+
exports[`sessionStorage getItem throws if key is null 1`] = `"Requested key is null or undefined"`;
|
|
6
6
|
|
|
7
|
-
exports[`sessionStorage
|
|
7
|
+
exports[`sessionStorage getItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
|
|
8
8
|
|
|
9
|
-
exports[`sessionStorage
|
|
9
|
+
exports[`sessionStorage getItem throws if there is an error on the native side 1`] = `"An error occured while getting an item from native storage: failed to get item"`;
|
|
10
10
|
|
|
11
|
-
exports[`sessionStorage
|
|
11
|
+
exports[`sessionStorage removeItem throws if a native error is thrown 1`] = `"An error occured while removing an item from native storage: failed to remove item"`;
|
|
12
12
|
|
|
13
|
-
exports[`sessionStorage
|
|
13
|
+
exports[`sessionStorage removeItem throws if key is null 1`] = `"Requested key is null or undefined"`;
|
|
14
14
|
|
|
15
|
-
exports[`sessionStorage
|
|
15
|
+
exports[`sessionStorage removeItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
|
|
16
16
|
|
|
17
|
-
exports[`sessionStorage
|
|
17
|
+
exports[`sessionStorage setItem throws if key is null 1`] = `"Requested key is null or undefined"`;
|
|
18
18
|
|
|
19
|
-
exports[`sessionStorage
|
|
19
|
+
exports[`sessionStorage setItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
|
|
20
20
|
|
|
21
|
-
exports[`sessionStorage
|
|
21
|
+
exports[`sessionStorage setItem throws if there is an error in the native module 1`] = `"An error occured while setting an item in native storage: failed to set item"`;
|
|
22
22
|
|
|
23
|
-
exports[`sessionStorage
|
|
23
|
+
exports[`sessionStorage setItem throws if value is null 1`] = `"Value to set in storage cannot be null or undefined"`;
|
|
24
24
|
|
|
25
|
-
exports[`sessionStorage
|
|
25
|
+
exports[`sessionStorage setItem throws if value is undefined 1`] = `"Value to set in storage cannot be null or undefined"`;
|