@applicaster/zapp-react-native-bridge 12.0.0-rc.25 → 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.
@@ -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
- jest.mock("react-native", () => ({
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
- return Promise.resolve(
10
- files.reduce((acc, curr) => {
11
- return R.assoc(curr.url, true, acc);
12
- }, {})
13
- );
14
- }),
15
- delete: jest.fn((file) => {
16
- if (file.includes("fail")) throw new Error("Error deleting file");
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
- return Promise.resolve(true);
19
- }),
20
- getFilesDirectory: jest.fn(() => Promise.resolve("/native/path/")),
21
- },
22
- },
23
- }));
19
+ return Promise.resolve(true);
20
+ }),
21
+ getFilesDirectory: jest.fn(() => Promise.resolve("/native/path/")),
22
+ };
24
23
 
25
- const {
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("storeFiles", () => {
38
- beforeEach(clearMocks);
34
+ describe("fileManager", () => {
35
+ describe("storeFiles", () => {
36
+ beforeEach(clearMocks);
39
37
 
40
- it("calls the store file function of the native module with the provided args", async () => {
41
- const files = [{ url: "http://file" }, { url: "http://file2" }];
42
- const options = {};
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
- const result = await storeFiles(files, options);
42
+ const result = await storeFiles(files, options);
45
43
 
46
- expect(OfflineAssetsBridge.storeFiles).toHaveBeenCalledWith(files, options);
47
- expect(result).toMatchSnapshot();
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
- beforeEach(clearMocks);
53
+ describe("deleteFolders", () => {
54
+ beforeEach(clearMocks);
53
55
 
54
- it("deletes each provided path", async () => {
55
- const folders = ["folder1", "folder2", "folder3"];
56
+ it("deletes each provided path", async () => {
57
+ const folders = ["folder1", "folder2", "folder3"];
56
58
 
57
- const result = await deleteFolders(folders);
59
+ const result = await deleteFolders(folders);
58
60
 
59
- expect.assertions(folders.length + 2);
60
- expect(result).toMatchSnapshot();
61
- expect(OfflineAssetsBridge.delete).toHaveBeenCalledTimes(folders.length);
61
+ expect.assertions(folders.length + 2);
62
+ expect(result).toMatchSnapshot();
63
+ expect(OfflineAssetsBridge.delete).toHaveBeenCalledTimes(folders.length);
62
64
 
63
- folders.forEach((folder, index) => {
64
- expect(OfflineAssetsBridge.delete).toHaveBeenNthCalledWith(
65
- index + 1,
66
- folder
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
- beforeEach(clearMocks);
74
+ describe("getNativeRootPath", () => {
75
+ beforeEach(clearMocks);
74
76
 
75
- it("returns the native root path", async () => {
76
- const nativePath = await OfflineAssetsBridge.getFilesDirectory();
77
+ it("returns the native root path", async () => {
78
+ const nativePath = await OfflineAssetsBridge.getFilesDirectory();
77
79
 
78
- await expect(getNativeRootPath()).resolves.toEqual(nativePath);
80
+ await expect(getNativeRootPath()).resolves.toEqual(nativePath);
81
+ });
79
82
  });
80
83
  });
@@ -1,27 +1,21 @@
1
- jest.mock("react-native", () => {
2
- // We're not using the vars defined below, cause jest doesn't allow mocks to refer
3
- // to out of scope variables, as they would be undefined when jest loads the mock
4
- return {
5
- NativeModules: {
6
- QuickBrickCommunicationModule: {
7
- quickBrickEvent: jest.fn(),
8
- accountId: 123,
9
- accountsAccountId: "accountsAccountIDString1234",
10
- broadcasterId: 145,
11
- bundleIdentifier: "com.apptestname",
12
- initialProps: {
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("../index");
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("sendQuickBrickEvent", () => {
37
- it("invokes the native module", () => {
38
- sendQuickBrickEvent(eventName, payload);
30
+ describe("QuickBrickModule", () => {
31
+ describe("sendQuickBrickEvent", () => {
32
+ it("invokes the native module", () => {
33
+ sendQuickBrickEvent(eventName, payload);
39
34
 
40
- expect(
41
- NativeModules.QuickBrickCommunicationModule.quickBrickEvent
42
- ).toHaveBeenCalledWith(eventName, payload);
43
- });
35
+ expect(
36
+ NativeModules.QuickBrickCommunicationModule.quickBrickEvent
37
+ ).toHaveBeenCalledWith(eventName, payload);
38
+ });
44
39
 
45
- it("passes an empty object as payload if not provided", () => {
46
- sendQuickBrickEvent(eventName);
40
+ it("passes an empty object as payload if not provided", () => {
41
+ sendQuickBrickEvent(eventName);
47
42
 
48
- expect(
49
- NativeModules.QuickBrickCommunicationModule.quickBrickEvent
50
- ).toHaveBeenCalledWith(eventName, {});
51
- });
43
+ expect(
44
+ NativeModules.QuickBrickCommunicationModule.quickBrickEvent
45
+ ).toHaveBeenCalledWith(eventName, {});
46
+ });
52
47
 
53
- afterEach(() => {
54
- NativeModules.QuickBrickCommunicationModule.quickBrickEvent.mockRestore();
48
+ afterEach(() => {
49
+ NativeModules.QuickBrickCommunicationModule.quickBrickEvent.mockRestore();
50
+ });
55
51
  });
56
- });
57
52
 
58
- describe("getAppData", () => {
59
- it("returns the app data", () => {
60
- const appData = getAppData();
61
- expect(appData).toHaveProperty("accountId", accountId);
62
- expect(appData).toHaveProperty("accountsAccountId", accountsAccountId);
63
- expect(appData).toHaveProperty("broadcasterId", broadcasterId);
64
- expect(appData).toHaveProperty("bundleIdentifier", bundleIdentifier);
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
- it("returns the initial props", () => {
70
- const initialProps = getLegacyInitialProps();
63
+ describe("getLegacyInitialProps", () => {
64
+ it("returns the initial props", () => {
65
+ const initialProps = getLegacyInitialProps();
71
66
 
72
- expect(initialProps).toEqual(
73
- NativeModules.QuickBrickCommunicationModule.initialProps
74
- );
67
+ expect(initialProps).toEqual(
68
+ NativeModules.QuickBrickCommunicationModule.initialProps
69
+ );
70
+ });
75
71
  });
76
72
  });
@@ -1,10 +1,6 @@
1
- const mock_NativeModules = {
2
- Foo: jest.fn(),
3
- };
1
+ const { NativeModules } = require("react-native");
4
2
 
5
- jest.mock("react-native", () => ({
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("../index");
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 - getAllItems throws if an error happen on native side 1`] = `"An error occured while getting an item from native storage: namespace not found"`;
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 - getItem throws if key is null 1`] = `"Requested key is null or undefined"`;
5
+ exports[`localStorage getItem throws if key is null 1`] = `"Requested key is null or undefined"`;
6
6
 
7
- exports[`localStorage - getItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
7
+ exports[`localStorage getItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
8
8
 
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"`;
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 - removeItem throws if a native error is thrown 1`] = `"An error occured while removing an item from native storage: failed to remove item"`;
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 - removeItem throws if key is null 1`] = `"Requested key is null or undefined"`;
13
+ exports[`localStorage removeItem throws if key is null 1`] = `"Requested key is null or undefined"`;
14
14
 
15
- exports[`localStorage - removeItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
15
+ exports[`localStorage removeItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
16
16
 
17
- exports[`localStorage - setItem throws if key is null 1`] = `"Requested key is null or undefined"`;
17
+ exports[`localStorage setItem throws if key is null 1`] = `"Requested key is null or undefined"`;
18
18
 
19
- exports[`localStorage - setItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
19
+ exports[`localStorage setItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
20
20
 
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"`;
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 - setItem throws if value is null 1`] = `"Value to set in storage cannot be null or undefined"`;
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 - setItem throws if value is undefined 1`] = `"Value to set in storage cannot be null or undefined"`;
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 - getAllItems throws if an error happen on native side 1`] = `"An error occured while getting an item from native storage: namespace not found"`;
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 - getItem throws if key is null 1`] = `"Requested key is null or undefined"`;
5
+ exports[`sessionStorage getItem throws if key is null 1`] = `"Requested key is null or undefined"`;
6
6
 
7
- exports[`sessionStorage - getItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
7
+ exports[`sessionStorage getItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
8
8
 
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"`;
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 - removeItem throws if a native error is thrown 1`] = `"An error occured while removing an item from native storage: failed to remove item"`;
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 - removeItem throws if key is null 1`] = `"Requested key is null or undefined"`;
13
+ exports[`sessionStorage removeItem throws if key is null 1`] = `"Requested key is null or undefined"`;
14
14
 
15
- exports[`sessionStorage - removeItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
15
+ exports[`sessionStorage removeItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
16
16
 
17
- exports[`sessionStorage - setItem throws if key is null 1`] = `"Requested key is null or undefined"`;
17
+ exports[`sessionStorage setItem throws if key is null 1`] = `"Requested key is null or undefined"`;
18
18
 
19
- exports[`sessionStorage - setItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
19
+ exports[`sessionStorage setItem throws if key is undefined 1`] = `"Requested key is null or undefined"`;
20
20
 
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"`;
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 - setItem throws if value is null 1`] = `"Value to set in storage cannot be null or undefined"`;
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 - setItem throws if value is undefined 1`] = `"Value to set in storage cannot be null or undefined"`;
25
+ exports[`sessionStorage setItem throws if value is undefined 1`] = `"Value to set in storage cannot be null or undefined"`;