@applicaster/quick-brick-core 13.0.0-rc.12 → 13.0.0-rc.121
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/App/ActionsProvider/__tests__/__snapshots__/ActionsProvider.test.js.snap +7 -7
- package/App/AssetCache/__tests__/__snapshots__/assetCache.test.ts.snap +103 -103
- package/App/AssetCache/__tests__/assetCache.test.ts +3 -2
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/__snapshots__/schemeHandlerHooks.test.ts.snap +1 -1
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +45 -116
- package/App/DeepLinking/URLSchemeHandler/__tests__/__snapshots__/URLSchemeHandler.test.tsx.snap +3 -3
- package/App/DeepLinking/URLSchemeListener/URLSchemeContextProvider.tsx +30 -3
- package/App/DeepLinking/URLSchemeListener/__tests__/URLSchemeListener.test.js +40 -0
- package/App/DeepLinking/URLSchemeListener/index.tsx +1 -1
- package/App/ErrorBoundary/__tests__/errorBoundary.test.jsx +232 -0
- package/App/ErrorBoundary/__tests__/store.test.js +143 -0
- package/App/ErrorBoundary/index.tsx +45 -21
- package/App/ErrorBoundary/store.ts +26 -0
- package/App/LoadingOverlay/LoadingOverlayManager.tsx +27 -0
- package/App/LoadingOverlay/index.tsx +49 -0
- package/App/LoadingOverlay/useLoadingOverlayVisibility.tsx +18 -0
- package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/index.tsx +0 -1
- package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +68 -10
- package/App/ModalProvider/ModalBottomSheet/Overlay.tsx +5 -7
- package/App/ModalProvider/ModalBottomSheet/index.tsx +18 -46
- package/App/ModalProvider/ModalPresenter.tsx +1 -1
- package/App/ModalProvider/index.tsx +6 -3
- package/App/NavigationProvider/NavigationProvider.tsx +77 -63
- package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +0 -44
- package/App/NavigationProvider/navigator/__tests__/__snapshots__/reducer.test.ts.snap +189 -189
- package/App/NetworkStatusProvider/utils.ts +0 -1
- package/App/RouteManager/__tests__/__snapshots__/routeManager.test.js.snap +2 -2
- package/App/StoreConnector/__tests__/storeConnector.test.js +17 -11
- package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.tsx +146 -0
- package/App/appLifeCycleManager/index.tsx +6 -7
- package/App/index.tsx +6 -3
- package/App/remoteContextReloader/__tests__/remoteContextReloader.test.js +11 -21
- package/App/remoteContextReloader/consts.ts +2 -0
- package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +31 -6
- package/createZappApp/__tests__/__snapshots__/createZappApp.test.js.snap +5 -128
- package/createZappApp/__tests__/createZappApp.test.js +7 -20
- package/defaults/__tests__/defaults.test.js +3 -4
- package/index.d.ts +1 -1
- package/package.json +26 -14
- package/App/DeepLinking/URLSchemeListener/__tests__/URLSchemeListenerTest.js +0 -177
- package/App/ErrorBoundary/__tests__/__snapshots__/errorBoundary.test.js.snap +0 -9
- package/App/ErrorBoundary/__tests__/errorBoundary.test.js +0 -72
- package/App/ModalProvider/ModalChildrenWrapper/index.web.ts +0 -1
- package/App/NavigationProvider/__tests__/__snapshots__/navigationProvider.test.tsx.snap +0 -70
- package/App/StoreConnector/__tests__/__snapshots__/storeConnector.test.js.snap +0 -35
- package/App/appLifeCycleManager/__tests__/__snapshots__/appLifeCycleManager.test.js.snap +0 -30
- package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.js +0 -134
- package/App/remoteContextReloader/__tests__/__snapshots__/remoteContextReloader.test.js.snap +0 -43
- /package/App/ModalProvider/ModalChildrenWrapper/{index.ios.ts → index.ts} +0 -0
package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
3
3
|
import * as feedLoader from "@applicaster/zapp-react-native-utils/reactHooks/feed/useFeedLoader";
|
|
4
4
|
import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
5
|
-
import { cleanup, renderHook } from "@testing-library/react-
|
|
5
|
+
import { waitFor, cleanup, renderHook } from "@testing-library/react-native";
|
|
6
6
|
import nock from "nock";
|
|
7
7
|
import * as R from "ramda";
|
|
8
8
|
import React from "react";
|
|
@@ -66,13 +66,13 @@ const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
|
|
|
66
66
|
|
|
67
67
|
const setEntryContext = jest.fn();
|
|
68
68
|
|
|
69
|
-
jest.
|
|
69
|
+
jest.doMock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
70
70
|
ZappPipesEntryContext: {
|
|
71
71
|
useZappPipesContext: () => [{}, setEntryContext],
|
|
72
72
|
},
|
|
73
73
|
}));
|
|
74
74
|
|
|
75
|
-
jest.
|
|
75
|
+
jest.doMock("../../../logger", () => ({
|
|
76
76
|
log_info: jest.fn(),
|
|
77
77
|
log_error: jest.fn(),
|
|
78
78
|
log_warning: jest.fn(),
|
|
@@ -80,8 +80,11 @@ jest.mock("../../../logger", () => ({
|
|
|
80
80
|
log_debug: jest.fn(),
|
|
81
81
|
}));
|
|
82
82
|
|
|
83
|
-
jest.useFakeTimers(
|
|
83
|
+
jest.useFakeTimers({
|
|
84
|
+
legacyFakeTimers: true,
|
|
85
|
+
});
|
|
84
86
|
|
|
87
|
+
// to use import instead of require it's required to use jest.mock above
|
|
85
88
|
const { useOpenSchemeHandler } = require("../useOpenSchemeHandler");
|
|
86
89
|
|
|
87
90
|
const getWrapper = (storeProps = {}) => {
|
|
@@ -105,12 +108,13 @@ const getWrapper = (storeProps = {}) => {
|
|
|
105
108
|
const testHook = async ({ url, query, storeProps = {}, tests }) => {
|
|
106
109
|
const wrapper = getWrapper(storeProps);
|
|
107
110
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
const callback = jest.fn((fn) => fn(tests));
|
|
112
|
+
|
|
113
|
+
renderHook(() => useOpenSchemeHandler({ url, query, onFinish: callback }), {
|
|
114
|
+
wrapper,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await waitFor(() => expect(callback).toHaveBeenCalled());
|
|
114
118
|
};
|
|
115
119
|
|
|
116
120
|
function clearMocks() {
|
|
@@ -151,7 +155,7 @@ describe("useOpenSchemeHandler", () => {
|
|
|
151
155
|
|
|
152
156
|
const query = { feed_locator, state: "fullscreen" };
|
|
153
157
|
|
|
154
|
-
it("fetches state and write it to extensions", (
|
|
158
|
+
it("fetches state and write it to extensions", async () => {
|
|
155
159
|
const tests = () => {
|
|
156
160
|
const entry = {
|
|
157
161
|
...entries[0],
|
|
@@ -167,13 +171,9 @@ describe("useOpenSchemeHandler", () => {
|
|
|
167
171
|
pushScreen: true,
|
|
168
172
|
})
|
|
169
173
|
);
|
|
170
|
-
|
|
171
|
-
expect.assertions(1);
|
|
172
|
-
|
|
173
|
-
done();
|
|
174
174
|
};
|
|
175
175
|
|
|
176
|
-
testHook({ url, query, tests });
|
|
176
|
+
await testHook({ url, query, tests });
|
|
177
177
|
});
|
|
178
178
|
});
|
|
179
179
|
|
|
@@ -189,17 +189,16 @@ describe("useOpenSchemeHandler", () => {
|
|
|
189
189
|
type: { value: type },
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
it("doesn't log a warning", (
|
|
192
|
+
it("doesn't log a warning", async () => {
|
|
193
193
|
const tests = () => {
|
|
194
|
-
expect(log_warning).not.
|
|
194
|
+
expect(log_warning).not.toHaveBeenCalled();
|
|
195
195
|
expect.assertions(1);
|
|
196
|
-
done();
|
|
197
196
|
};
|
|
198
197
|
|
|
199
|
-
testHook({ url, query, tests });
|
|
198
|
+
await testHook({ url, query, tests });
|
|
200
199
|
});
|
|
201
200
|
|
|
202
|
-
it("opens the screen type-mapped to the provided value", (
|
|
201
|
+
it("opens the screen type-mapped to the provided value", async () => {
|
|
203
202
|
const tests = () => {
|
|
204
203
|
expect(helperSpy).toHaveBeenCalledWith(
|
|
205
204
|
expect.objectContaining({
|
|
@@ -215,16 +214,12 @@ describe("useOpenSchemeHandler", () => {
|
|
|
215
214
|
isDeepLink: true,
|
|
216
215
|
})
|
|
217
216
|
);
|
|
218
|
-
|
|
219
|
-
expect.assertions(2);
|
|
220
|
-
|
|
221
|
-
done();
|
|
222
217
|
};
|
|
223
218
|
|
|
224
|
-
testHook({ url, query, tests });
|
|
219
|
+
await testHook({ url, query, tests });
|
|
225
220
|
});
|
|
226
221
|
|
|
227
|
-
it("sets the entry context with the provided parameters", (
|
|
222
|
+
it("sets the entry context with the provided parameters", async () => {
|
|
228
223
|
const params = { showId: "abc", param: "value" };
|
|
229
224
|
|
|
230
225
|
const tests = () => {
|
|
@@ -249,13 +244,9 @@ describe("useOpenSchemeHandler", () => {
|
|
|
249
244
|
extensions: { ...params, initial_player_state: "fullscreen" },
|
|
250
245
|
})
|
|
251
246
|
);
|
|
252
|
-
|
|
253
|
-
expect.assertions(3);
|
|
254
|
-
|
|
255
|
-
done();
|
|
256
247
|
};
|
|
257
248
|
|
|
258
|
-
testHook({ url, query: { ...query, ...params }, tests });
|
|
249
|
+
await testHook({ url, query: { ...query, ...params }, tests });
|
|
259
250
|
});
|
|
260
251
|
});
|
|
261
252
|
|
|
@@ -267,17 +258,7 @@ describe("useOpenSchemeHandler", () => {
|
|
|
267
258
|
const url = `app://open?screen_id=${screen_id}`;
|
|
268
259
|
const query = { screen_id };
|
|
269
260
|
|
|
270
|
-
it("
|
|
271
|
-
const tests = () => {
|
|
272
|
-
expect(log_warning).not.toBeCalled();
|
|
273
|
-
expect.assertions(1);
|
|
274
|
-
done();
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
testHook({ url, query, tests });
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it("opens the screen with the provided id", (done) => {
|
|
261
|
+
it("opens the screen with the provided id", async () => {
|
|
281
262
|
const tests = () => {
|
|
282
263
|
expect(helperSpy).toHaveBeenCalledWith(
|
|
283
264
|
expect.objectContaining({
|
|
@@ -290,16 +271,12 @@ describe("useOpenSchemeHandler", () => {
|
|
|
290
271
|
expect(navigator.push).toHaveBeenCalledWith(
|
|
291
272
|
expect.objectContaining({ ...rivers[screen_id], isDeepLink: true })
|
|
292
273
|
);
|
|
293
|
-
|
|
294
|
-
expect.assertions(2);
|
|
295
|
-
|
|
296
|
-
done();
|
|
297
274
|
};
|
|
298
275
|
|
|
299
|
-
testHook({ url, query, tests });
|
|
276
|
+
await testHook({ url, query, tests });
|
|
300
277
|
});
|
|
301
278
|
|
|
302
|
-
it("sets the entry context with the provided parameters", (
|
|
279
|
+
it("sets the entry context with the provided parameters", async () => {
|
|
303
280
|
const params = { showId: "abc", param: "value" };
|
|
304
281
|
|
|
305
282
|
const tests = () => {
|
|
@@ -324,13 +301,9 @@ describe("useOpenSchemeHandler", () => {
|
|
|
324
301
|
extensions: { ...params, initial_player_state: "fullscreen" },
|
|
325
302
|
})
|
|
326
303
|
);
|
|
327
|
-
|
|
328
|
-
expect.assertions(3);
|
|
329
|
-
|
|
330
|
-
done();
|
|
331
304
|
};
|
|
332
305
|
|
|
333
|
-
testHook({ url, query: { ...query, ...params }, tests });
|
|
306
|
+
await testHook({ url, query: { ...query, ...params }, tests });
|
|
334
307
|
});
|
|
335
308
|
});
|
|
336
309
|
|
|
@@ -359,17 +332,7 @@ describe("useOpenSchemeHandler", () => {
|
|
|
359
332
|
const url = `app://open?feed_locator=${encodeURIComponent(feed_locator)}`;
|
|
360
333
|
const query = { feed_locator };
|
|
361
334
|
|
|
362
|
-
it("
|
|
363
|
-
const tests = () => {
|
|
364
|
-
expect(log_warning).not.toBeCalled();
|
|
365
|
-
expect.assertions(1);
|
|
366
|
-
done();
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
testHook({ url, query, tests });
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it("fetches the feed, sets the entryContext, and navigates to the first entry if no other parameter is provided", (done) => {
|
|
335
|
+
it("fetches the feed, sets the entryContext, and navigates to the first entry if no other parameter is provided", async () => {
|
|
373
336
|
const tests = () => {
|
|
374
337
|
const entryWithInitialPlayerState = withInitialPlayerState(
|
|
375
338
|
query,
|
|
@@ -394,16 +357,12 @@ describe("useOpenSchemeHandler", () => {
|
|
|
394
357
|
expect(setEntryContext).toHaveBeenCalledWith(
|
|
395
358
|
entryWithInitialPlayerState
|
|
396
359
|
);
|
|
397
|
-
|
|
398
|
-
expect.assertions(3);
|
|
399
|
-
|
|
400
|
-
done();
|
|
401
360
|
};
|
|
402
361
|
|
|
403
|
-
testHook({ url, query, tests });
|
|
362
|
+
await testHook({ url, query, tests });
|
|
404
363
|
});
|
|
405
364
|
|
|
406
|
-
it("fetches the feed, sets the entryContext, and navigates to the entry with the provided position", (
|
|
365
|
+
it("fetches the feed, sets the entryContext, and navigates to the entry with the provided position", async () => {
|
|
407
366
|
const tests = () => {
|
|
408
367
|
const entryWithInitialPlayerState = withInitialPlayerState(
|
|
409
368
|
query,
|
|
@@ -428,16 +387,12 @@ describe("useOpenSchemeHandler", () => {
|
|
|
428
387
|
expect(setEntryContext).toHaveBeenCalledWith(
|
|
429
388
|
entryWithInitialPlayerState
|
|
430
389
|
);
|
|
431
|
-
|
|
432
|
-
expect.assertions(3);
|
|
433
|
-
|
|
434
|
-
done();
|
|
435
390
|
};
|
|
436
391
|
|
|
437
|
-
testHook({ url, query: { ...query, position: 3 }, tests });
|
|
392
|
+
await testHook({ url, query: { ...query, position: 3 }, tests });
|
|
438
393
|
});
|
|
439
394
|
|
|
440
|
-
it("fetches the feed, sets the entryContext, and navigates to the entry with the provided id", (
|
|
395
|
+
it("fetches the feed, sets the entryContext, and navigates to the entry with the provided id", async () => {
|
|
441
396
|
const tests = () => {
|
|
442
397
|
const entryWithInitialPlayerState = withInitialPlayerState(
|
|
443
398
|
query,
|
|
@@ -462,16 +417,12 @@ describe("useOpenSchemeHandler", () => {
|
|
|
462
417
|
expect(setEntryContext).toHaveBeenCalledWith(
|
|
463
418
|
entryWithInitialPlayerState
|
|
464
419
|
);
|
|
465
|
-
|
|
466
|
-
expect.assertions(3);
|
|
467
|
-
|
|
468
|
-
done();
|
|
469
420
|
};
|
|
470
421
|
|
|
471
|
-
testHook({ url, query: { ...query, id: "entry_3" }, tests });
|
|
422
|
+
await testHook({ url, query: { ...query, id: "entry_3" }, tests });
|
|
472
423
|
});
|
|
473
424
|
|
|
474
|
-
it("fetches the feed, sets the entryContext, and navigates to the entry with the provided id as number", (
|
|
425
|
+
it("fetches the feed, sets the entryContext, and navigates to the entry with the provided id as number", async () => {
|
|
475
426
|
const tests = () => {
|
|
476
427
|
const entryWithInitialPlayerState = withInitialPlayerState(
|
|
477
428
|
query,
|
|
@@ -496,16 +447,12 @@ describe("useOpenSchemeHandler", () => {
|
|
|
496
447
|
expect(setEntryContext).toHaveBeenCalledWith(
|
|
497
448
|
entryWithInitialPlayerState
|
|
498
449
|
);
|
|
499
|
-
|
|
500
|
-
expect.assertions(3);
|
|
501
|
-
|
|
502
|
-
done();
|
|
503
450
|
};
|
|
504
451
|
|
|
505
|
-
testHook({ url, query: { ...query, id: "1234" }, tests });
|
|
452
|
+
await testHook({ url, query: { ...query, id: "1234" }, tests });
|
|
506
453
|
});
|
|
507
454
|
|
|
508
|
-
it("fetches the feed, sets the entryContext, and opens the entry in the provided screen_id", (
|
|
455
|
+
it("fetches the feed, sets the entryContext, and opens the entry in the provided screen_id", async () => {
|
|
509
456
|
const tests = () => {
|
|
510
457
|
const entryWithInitialPlayerState = withInitialPlayerState(
|
|
511
458
|
query,
|
|
@@ -530,20 +477,16 @@ describe("useOpenSchemeHandler", () => {
|
|
|
530
477
|
expect(setEntryContext).toHaveBeenCalledWith(
|
|
531
478
|
entryWithInitialPlayerState
|
|
532
479
|
);
|
|
533
|
-
|
|
534
|
-
expect.assertions(3);
|
|
535
|
-
|
|
536
|
-
done();
|
|
537
480
|
};
|
|
538
481
|
|
|
539
|
-
testHook({
|
|
482
|
+
await testHook({
|
|
540
483
|
url,
|
|
541
484
|
query: { ...query, id: "entry_2", screen_id: "B0987" },
|
|
542
485
|
tests,
|
|
543
486
|
});
|
|
544
487
|
});
|
|
545
488
|
|
|
546
|
-
it("fetches the feed, sets the entryContext, and opens the entry in the screen matching the provided type", (
|
|
489
|
+
it("fetches the feed, sets the entryContext, and opens the entry in the screen matching the provided type", async () => {
|
|
547
490
|
const tests = () => {
|
|
548
491
|
const entryWithInitialPlayerState = withInitialPlayerState(
|
|
549
492
|
query,
|
|
@@ -568,20 +511,16 @@ describe("useOpenSchemeHandler", () => {
|
|
|
568
511
|
expect(setEntryContext).toHaveBeenCalledWith(
|
|
569
512
|
expect.objectContaining(entryWithInitialPlayerState)
|
|
570
513
|
);
|
|
571
|
-
|
|
572
|
-
expect.assertions(3);
|
|
573
|
-
|
|
574
|
-
done();
|
|
575
514
|
};
|
|
576
515
|
|
|
577
|
-
testHook({
|
|
516
|
+
await testHook({
|
|
578
517
|
url,
|
|
579
518
|
query: { ...query, id: "entry_2", type: "show" },
|
|
580
519
|
tests,
|
|
581
520
|
});
|
|
582
521
|
});
|
|
583
522
|
|
|
584
|
-
it("logs an error and redirect to home if it cannot resolve the target screen", (
|
|
523
|
+
it("logs an error and redirect to home if it cannot resolve the target screen", async () => {
|
|
585
524
|
const tests = () => {
|
|
586
525
|
expect(log_warning).toHaveBeenCalledWith(resolveError(url), {
|
|
587
526
|
url,
|
|
@@ -599,12 +538,9 @@ describe("useOpenSchemeHandler", () => {
|
|
|
599
538
|
|
|
600
539
|
expect(navigator.goHome).toHaveBeenCalled();
|
|
601
540
|
expect(setEntryContext).not.toHaveBeenCalled();
|
|
602
|
-
expect.assertions(4);
|
|
603
|
-
|
|
604
|
-
done();
|
|
605
541
|
};
|
|
606
542
|
|
|
607
|
-
testHook({
|
|
543
|
+
await testHook({
|
|
608
544
|
url,
|
|
609
545
|
query: { ...query, id: "entry_2" },
|
|
610
546
|
tests,
|
|
@@ -626,7 +562,7 @@ describe("useOpenSchemeHandler", () => {
|
|
|
626
562
|
const url = `app://open?feed_locator=${encodeURIComponent(feed_locator)}`;
|
|
627
563
|
const query = { feed_locator };
|
|
628
564
|
|
|
629
|
-
it("goes to home screen and logs a warning", (
|
|
565
|
+
it("goes to home screen and logs a warning", async () => {
|
|
630
566
|
const tests = () => {
|
|
631
567
|
expect(log_warning).toHaveBeenCalledWith(resolveError(url), {
|
|
632
568
|
url,
|
|
@@ -643,12 +579,9 @@ describe("useOpenSchemeHandler", () => {
|
|
|
643
579
|
);
|
|
644
580
|
|
|
645
581
|
expect(navigator.goHome).toHaveBeenCalled();
|
|
646
|
-
expect.assertions(3);
|
|
647
|
-
|
|
648
|
-
done();
|
|
649
582
|
};
|
|
650
583
|
|
|
651
|
-
testHook({ url, query, tests });
|
|
584
|
+
await testHook({ url, query, tests });
|
|
652
585
|
});
|
|
653
586
|
});
|
|
654
587
|
|
|
@@ -659,19 +592,15 @@ describe("useOpenSchemeHandler", () => {
|
|
|
659
592
|
const url = "app://open?param=value";
|
|
660
593
|
const query = { param: "value" };
|
|
661
594
|
|
|
662
|
-
it("logs a warning", (
|
|
595
|
+
it("logs a warning", async () => {
|
|
663
596
|
const tests = () => {
|
|
664
597
|
expect(log_warning).toBeCalledWith(
|
|
665
598
|
typeWarningMessage(url),
|
|
666
599
|
expect.objectContaining({ url, query })
|
|
667
600
|
);
|
|
668
|
-
|
|
669
|
-
expect.assertions(1);
|
|
670
|
-
|
|
671
|
-
done();
|
|
672
601
|
};
|
|
673
602
|
|
|
674
|
-
testHook({ url, query, tests });
|
|
603
|
+
await testHook({ url, query, tests });
|
|
675
604
|
});
|
|
676
605
|
});
|
|
677
606
|
});
|
package/App/DeepLinking/URLSchemeHandler/__tests__/__snapshots__/URLSchemeHandler.test.tsx.snap
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
exports[`URLSchemeHandler renders correctly and invokes the hook 1`] = `
|
|
4
4
|
<View
|
|
5
5
|
style={
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
[
|
|
7
|
+
{
|
|
8
8
|
"alignItems": "center",
|
|
9
9
|
"flex": 1,
|
|
10
10
|
"justifyContent": "center",
|
|
11
11
|
},
|
|
12
|
-
|
|
12
|
+
{
|
|
13
13
|
"backgroundColor": "white",
|
|
14
14
|
"height": 1334,
|
|
15
15
|
"width": 750,
|
|
@@ -10,7 +10,11 @@ import * as ReactNative from "react-native";
|
|
|
10
10
|
|
|
11
11
|
import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
12
12
|
import { log_debug, log_error, log_info } from "../logger";
|
|
13
|
-
|
|
13
|
+
import { getAppUrlScheme } from "@applicaster/zapp-react-native-utils/appDataUtils";
|
|
14
|
+
import {
|
|
15
|
+
getZappPlatform,
|
|
16
|
+
ZappPlatform,
|
|
17
|
+
} from "@applicaster/zapp-react-native-utils/appUtils/platform";
|
|
14
18
|
type Props = {
|
|
15
19
|
listenerSpy?: (...any) => void;
|
|
16
20
|
children: ReactChild;
|
|
@@ -34,6 +38,15 @@ const initialState = { url: null, done: () => {} };
|
|
|
34
38
|
|
|
35
39
|
export const URLSchemeContext = createContext<State>(initialState);
|
|
36
40
|
|
|
41
|
+
const getWebDeepLink = (initialURL: string) => {
|
|
42
|
+
if (!initialURL) return null;
|
|
43
|
+
|
|
44
|
+
const index = initialURL.indexOf("?");
|
|
45
|
+
if (index === -1) return;
|
|
46
|
+
|
|
47
|
+
return getAppUrlScheme() + "://open" + initialURL.slice(index);
|
|
48
|
+
};
|
|
49
|
+
|
|
37
50
|
function URLSchemeContextProvider(props: Props) {
|
|
38
51
|
const [state, setState] = useState<string | null>(initialState.url);
|
|
39
52
|
|
|
@@ -51,10 +64,24 @@ function URLSchemeContextProvider(props: Props) {
|
|
|
51
64
|
props?.listenerSpy?.("getInitialURL");
|
|
52
65
|
|
|
53
66
|
try {
|
|
54
|
-
if (isWeb()) return;
|
|
55
|
-
|
|
56
67
|
const url = await Linking.getInitialURL();
|
|
57
68
|
|
|
69
|
+
if (isWeb()) {
|
|
70
|
+
if (getZappPlatform() === ZappPlatform.Vizio) {
|
|
71
|
+
const deepLink = getWebDeepLink(url);
|
|
72
|
+
|
|
73
|
+
if (deepLink) {
|
|
74
|
+
log_info(
|
|
75
|
+
`URLSchemeContextProvider: Retrieved initial deep link: ${deepLink}`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return setState(deepLink);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
58
85
|
log_info(
|
|
59
86
|
`URLSchemeContextProvider: Retrieved initial url: ${url || "not exist"}`
|
|
60
87
|
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, Text } from "react-native";
|
|
3
|
+
import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
|
|
4
|
+
|
|
5
|
+
import { URLSchemeListener } from "../index";
|
|
6
|
+
|
|
7
|
+
const TestComponent = (props) => (
|
|
8
|
+
<View testID="test-comp" {...props}>
|
|
9
|
+
<Text>I'm a test component</Text>
|
|
10
|
+
</View>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const navigator = {
|
|
14
|
+
push: jest.fn(),
|
|
15
|
+
replace: jest.fn(),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
jest.spyOn(console, "warn").mockImplementation(() => jest.fn());
|
|
19
|
+
|
|
20
|
+
function clearMocks() {
|
|
21
|
+
navigator.push.mockClear();
|
|
22
|
+
navigator.replace.mockClear();
|
|
23
|
+
console.warn.mockClear();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("URLSchemeHandler", () => {
|
|
27
|
+
const renderComponent = (props = {}) =>
|
|
28
|
+
renderWithProviders(
|
|
29
|
+
<URLSchemeListener {...props}>
|
|
30
|
+
<TestComponent />
|
|
31
|
+
</URLSchemeListener>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
beforeEach(clearMocks);
|
|
35
|
+
|
|
36
|
+
it("renders correctly (default case)", () => {
|
|
37
|
+
const { getByTestId } = renderComponent();
|
|
38
|
+
expect(getByTestId("test-comp")).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -5,7 +5,7 @@ import { URLSchemeContext } from "./URLSchemeContextProvider";
|
|
|
5
5
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
6
6
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
7
7
|
|
|
8
|
-
export function URLSchemeListener({ children }) {
|
|
8
|
+
export function URLSchemeListener({ children }: { children: React.ReactNode }) {
|
|
9
9
|
const { url, done } = useContext(URLSchemeContext);
|
|
10
10
|
|
|
11
11
|
const navigator = useNavigation();
|