From 29c96ca303cd881321740761fdf00e7dd07736a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesv=C3=A4rd?= Date: Mon, 30 Aug 2021 15:47:39 +0200 Subject: [PATCH 1/4] poc --- jest-setup.js | 4 ++-- lib/src/Mock/index.ts | 7 +++++++ lib/src/NavigationDelegate.ts | 11 ++++++----- lib/src/index.ts | 1 - package.json | 3 ++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/jest-setup.js b/jest-setup.js index 23a79cc85d0..1cd3444f44d 100644 --- a/jest-setup.js +++ b/jest-setup.js @@ -3,11 +3,11 @@ const { mockDetox } = require('detox-testing-library-rnn-adapter'); mockDetox(() => require('./playground/index')); beforeEach(() => { - const { Navigation } = require('react-native-navigation'); + const { mockNativeComponents } = require('react-native-navigation/Mock'); setTimeout = (func) => { func(); }; - Navigation.mockNativeComponents(); + mockNativeComponents(); mockUILib(); }); diff --git a/lib/src/Mock/index.ts b/lib/src/Mock/index.ts index 853604d556e..4e828820663 100644 --- a/lib/src/Mock/index.ts +++ b/lib/src/Mock/index.ts @@ -1,3 +1,10 @@ export const ApplicationMock = require('./Application').Application; export * from './constants'; + +export function mockNativeComponents() { + const { NativeCommandsSender } = require('./mocks/NativeCommandsSender'); + const { NativeEventsReceiver } = require('./mocks/NativeEventsReceiver'); + const { Navigation } = require('react-native-navigation'); + Navigation.mockNativeComponents(new NativeCommandsSender(), new NativeEventsReceiver()); +} diff --git a/lib/src/NavigationDelegate.ts b/lib/src/NavigationDelegate.ts index 00ff027b271..02334db9586 100644 --- a/lib/src/NavigationDelegate.ts +++ b/lib/src/NavigationDelegate.ts @@ -223,12 +223,13 @@ export class NavigationDelegate { return this.concreteNavigation.TouchablePreview; } - public mockNativeComponents() { - const { NativeCommandsSender } = require('./Mock/mocks/NativeCommandsSender'); - const { NativeEventsReceiver } = require('./Mock/mocks/NativeEventsReceiver'); + public mockNativeComponents( + mockedNativeCommandsSender: NativeCommandsSender, + mockedNativeEventsReceiver: NativeEventsReceiver + ) { this.concreteNavigation = this.createConcreteNavigation( - new NativeCommandsSender(), - new NativeEventsReceiver() + mockedNativeCommandsSender, + mockedNativeEventsReceiver ); } diff --git a/lib/src/index.ts b/lib/src/index.ts index 006cee09dbb..8a44e8aa9e6 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -16,4 +16,3 @@ export * from './interfaces/NavigationFunctionComponent'; export * from './interfaces/CommandName'; export * from './interfaces/Processors'; export * from './interfaces/ProcessorSubscription'; -export * from './Mock'; diff --git a/package.json b/package.json index 0c6496c6bd9..99c5afafc7d 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,7 @@ "typedoc": "0.x.x", "typescript": "3.9.5", "detox-testing-library-rnn-adapter": "1.x.x", - "remx": "4.x.x" + "remx": "3.x.x" }, "jest": { "preset": "react-native", @@ -133,6 +133,7 @@ "./jest-setup.js" ], "moduleNameMapper": { + "react-native-navigation/Mock": "/lib/src/Mock", "react-native-navigation": "/lib/src", "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/playground/img/layouts@2x.png" }, From 652e31e7e2ea3b06b787307e9fb01a07ce2eaf84 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Thu, 2 Sep 2021 12:07:37 +0300 Subject: [PATCH 2/4] Update detox adapter --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 99c5afafc7d..d035eb5bc6c 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,7 @@ "ts-mockito": "^2.3.1", "typedoc": "0.x.x", "typescript": "3.9.5", - "detox-testing-library-rnn-adapter": "1.x.x", + "detox-testing-library-rnn-adapter": "2.x.x", "remx": "3.x.x" }, "jest": { @@ -257,4 +257,4 @@ } } } -} \ No newline at end of file +} From a9d18039eeff8e1f4be1770dde0502db0cf00306 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Thu, 2 Sep 2021 12:15:40 +0300 Subject: [PATCH 3/4] f --- lib/src/NavigationDelegate.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/src/NavigationDelegate.ts b/lib/src/NavigationDelegate.ts index d4933b8b213..90aecf18a88 100644 --- a/lib/src/NavigationDelegate.ts +++ b/lib/src/NavigationDelegate.ts @@ -226,6 +226,18 @@ export class NavigationDelegate { return this.concreteNavigation.TouchablePreview; } + public mockNativeComponents( + mockedNativeCommandsSender: NativeCommandsSender, + mockedNativeEventsReceiver: NativeEventsReceiver, + mockedAppRegistryService: AppRegistryService + ) { + this.concreteNavigation = this.createConcreteNavigation( + mockedNativeCommandsSender, + mockedNativeEventsReceiver, + mockedAppRegistryService + ); + } + public get mock() { return { store: this.concreteNavigation.store, From 666988a2f7a97fc0ad68a17e9fee13bde7d04c87 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Thu, 2 Sep 2021 14:46:17 +0300 Subject: [PATCH 4/4] Expose mocks in project root --- Mock.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 Mock.ts diff --git a/Mock.ts b/Mock.ts new file mode 100644 index 00000000000..c4cbf00d1c0 --- /dev/null +++ b/Mock.ts @@ -0,0 +1 @@ +export * from './lib/dist/Mock';