|
@@ -34,6 +34,8 @@ import com.reactnativenavigation.viewcontrollers.modal.ModalStack;
|
34
|
34
|
import com.reactnativenavigation.viewcontrollers.stack.StackController;
|
35
|
35
|
import com.reactnativenavigation.views.BottomTabs;
|
36
|
36
|
|
|
37
|
+import com.facebook.react.ReactInstanceManager;
|
|
38
|
+
|
37
|
39
|
import org.junit.Test;
|
38
|
40
|
import org.mockito.ArgumentCaptor;
|
39
|
41
|
import org.mockito.Mockito;
|
|
@@ -71,11 +73,13 @@ public class NavigatorTest extends BaseTest {
|
71
|
73
|
private EventEmitter eventEmitter;
|
72
|
74
|
private ViewController.ViewVisibilityListener parentVisibilityListener;
|
73
|
75
|
private ModalStack modalStack;
|
|
76
|
+ private ReactInstanceManager reactInstanceManager;
|
74
|
77
|
|
75
|
78
|
@Override
|
76
|
79
|
public void beforeEach() {
|
77
|
80
|
childRegistry = new ChildControllersRegistry();
|
78
|
81
|
eventEmitter = Mockito.mock(EventEmitter.class);
|
|
82
|
+ reactInstanceManager = Mockito.mock(ReactInstanceManager.class);
|
79
|
83
|
overlayManager = spy(new OverlayManager());
|
80
|
84
|
imageLoaderMock = ImageLoaderMock.mock();
|
81
|
85
|
activityController = newActivityController(TestActivity.class);
|
|
@@ -122,7 +126,7 @@ public class NavigatorTest extends BaseTest {
|
122
|
126
|
uut.setDefaultOptions(new Options());
|
123
|
127
|
|
124
|
128
|
SimpleViewController spy = spy(child1);
|
125
|
|
- uut.setRoot(spy, new CommandListenerAdapter());
|
|
129
|
+ uut.setRoot(spy, new CommandListenerAdapter(), reactInstanceManager);
|
126
|
130
|
Options defaultOptions = new Options();
|
127
|
131
|
uut.setDefaultOptions(defaultOptions);
|
128
|
132
|
|
|
@@ -133,9 +137,9 @@ public class NavigatorTest extends BaseTest {
|
133
|
137
|
@Test
|
134
|
138
|
public void setRoot_delegatesToRootPresenter() {
|
135
|
139
|
CommandListenerAdapter listener = new CommandListenerAdapter();
|
136
|
|
- uut.setRoot(child1, listener);
|
|
140
|
+ uut.setRoot(child1, listener, reactInstanceManager);
|
137
|
141
|
ArgumentCaptor<CommandListenerAdapter> captor = ArgumentCaptor.forClass(CommandListenerAdapter.class);
|
138
|
|
- verify(rootPresenter).setRoot(eq(child1), eq(uut.getDefaultOptions()), captor.capture());
|
|
142
|
+ verify(rootPresenter).setRoot(eq(child1), eq(uut.getDefaultOptions()), captor.capture(), eq(reactInstanceManager));
|
139
|
143
|
assertThat(captor.getValue().getListener()).isEqualTo(listener);
|
140
|
144
|
}
|
141
|
145
|
|
|
@@ -144,21 +148,21 @@ public class NavigatorTest extends BaseTest {
|
144
|
148
|
FrameLayout content = activity.findViewById(android.R.id.content);
|
145
|
149
|
assertThat(content.getChildCount()).isEqualTo(4); // 3 frame layouts and the default splash layout
|
146
|
150
|
|
147
|
|
- uut.setRoot(child2, new CommandListenerAdapter());
|
|
151
|
+ uut.setRoot(child2, new CommandListenerAdapter(), reactInstanceManager);
|
148
|
152
|
|
149
|
153
|
assertThat(content.getChildCount()).isEqualTo(3);
|
150
|
154
|
}
|
151
|
155
|
|
152
|
156
|
@Test
|
153
|
157
|
public void setRoot_AddsChildControllerView() {
|
154
|
|
- uut.setRoot(child1, new CommandListenerAdapter());
|
|
158
|
+ uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
|
155
|
159
|
assertIsChild(uut.getRootLayout(), child1.getView());
|
156
|
160
|
}
|
157
|
161
|
|
158
|
162
|
@Test
|
159
|
163
|
public void setRoot_ReplacesExistingChildControllerViews() {
|
160
|
|
- uut.setRoot(child1, new CommandListenerAdapter());
|
161
|
|
- uut.setRoot(child2, new CommandListenerAdapter());
|
|
164
|
+ uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
|
|
165
|
+ uut.setRoot(child2, new CommandListenerAdapter(), reactInstanceManager);
|
162
|
166
|
assertIsChild(uut.getRootLayout(), child2.getView());
|
163
|
167
|
}
|
164
|
168
|
|
|
@@ -172,7 +176,7 @@ public class NavigatorTest extends BaseTest {
|
172
|
176
|
public void push() {
|
173
|
177
|
StackController stackController = newStack();
|
174
|
178
|
stackController.push(child1, new CommandListenerAdapter());
|
175
|
|
- uut.setRoot(stackController, new CommandListenerAdapter());
|
|
179
|
+ uut.setRoot(stackController, new CommandListenerAdapter(), reactInstanceManager);
|
176
|
180
|
|
177
|
181
|
assertIsChild(uut.getView(), stackController.getView());
|
178
|
182
|
assertIsChild(stackController.getView(), child1.getView());
|
|
@@ -185,7 +189,7 @@ public class NavigatorTest extends BaseTest {
|
185
|
189
|
|
186
|
190
|
@Test
|
187
|
191
|
public void push_InvalidPushWithoutAStack_DoesNothing() {
|
188
|
|
- uut.setRoot(child1, new CommandListenerAdapter());
|
|
192
|
+ uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
|
189
|
193
|
uut.push(child1.getId(), child2, new CommandListenerAdapter());
|
190
|
194
|
assertIsChild(uut.getView(), child1.getView());
|
191
|
195
|
}
|
|
@@ -197,7 +201,7 @@ public class NavigatorTest extends BaseTest {
|
197
|
201
|
stack1.push(child1, new CommandListenerAdapter());
|
198
|
202
|
stack2.push(child2, new CommandListenerAdapter());
|
199
|
203
|
BottomTabsController bottomTabsController = newTabs(Arrays.asList(stack1, stack2));
|
200
|
|
- uut.setRoot(bottomTabsController, new CommandListenerAdapter());
|
|
204
|
+ uut.setRoot(bottomTabsController, new CommandListenerAdapter(), reactInstanceManager);
|
201
|
205
|
|
202
|
206
|
SimpleViewController newChild = new SimpleViewController(activity, childRegistry, "new child", tabOptions);
|
203
|
207
|
uut.push(child2.getId(), newChild, new CommandListenerAdapter());
|
|
@@ -216,7 +220,7 @@ public class NavigatorTest extends BaseTest {
|
216
|
220
|
@Test
|
217
|
221
|
public void pop_InvalidDoesNothing() {
|
218
|
222
|
uut.pop("123", Options.EMPTY, new CommandListenerAdapter());
|
219
|
|
- uut.setRoot(child1, new CommandListenerAdapter());
|
|
223
|
+ uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
|
220
|
224
|
uut.pop(child1.getId(), Options.EMPTY, new CommandListenerAdapter());
|
221
|
225
|
assertThat(uut.getChildControllers()).hasSize(1);
|
222
|
226
|
}
|
|
@@ -226,7 +230,7 @@ public class NavigatorTest extends BaseTest {
|
226
|
230
|
StackController stack1 = newStack();
|
227
|
231
|
StackController stack2 = newStack();
|
228
|
232
|
BottomTabsController bottomTabsController = newTabs(Arrays.asList(stack1, stack2));
|
229
|
|
- uut.setRoot(bottomTabsController, new CommandListenerAdapter());
|
|
233
|
+ uut.setRoot(bottomTabsController, new CommandListenerAdapter(), reactInstanceManager);
|
230
|
234
|
stack1.push(child1, new CommandListenerAdapter());
|
231
|
235
|
stack2.push(child2, new CommandListenerAdapter());
|
232
|
236
|
stack2.push(child3, new CommandListenerAdapter() {
|
|
@@ -249,7 +253,7 @@ public class NavigatorTest extends BaseTest {
|
249
|
253
|
disablePushAnimation(child1, child2);
|
250
|
254
|
disablePopAnimation(child2, child1);
|
251
|
255
|
StackController stack = newStack(); stack.ensureViewIsCreated();
|
252
|
|
- uut.setRoot(stack, new CommandListenerAdapter());
|
|
256
|
+ uut.setRoot(stack, new CommandListenerAdapter(), reactInstanceManager);
|
253
|
257
|
stack.push(child1, new CommandListenerAdapter());
|
254
|
258
|
stack.push(child2, new CommandListenerAdapter());
|
255
|
259
|
|
|
@@ -262,7 +266,7 @@ public class NavigatorTest extends BaseTest {
|
262
|
266
|
StackController stack1 = newStack();
|
263
|
267
|
StackController stack2 = newStack();
|
264
|
268
|
BottomTabsController bottomTabsController = newTabs(Arrays.asList(stack1, stack2));
|
265
|
|
- uut.setRoot(bottomTabsController, new CommandListenerAdapter());
|
|
269
|
+ uut.setRoot(bottomTabsController, new CommandListenerAdapter(), reactInstanceManager);
|
266
|
270
|
|
267
|
271
|
stack1.push(child1, new CommandListenerAdapter());
|
268
|
272
|
stack2.push(child2, new CommandListenerAdapter());
|
|
@@ -282,7 +286,7 @@ public class NavigatorTest extends BaseTest {
|
282
|
286
|
StackController stack1 = newStack();
|
283
|
287
|
StackController stack2 = newStack();
|
284
|
288
|
BottomTabsController bottomTabsController = newTabs(Arrays.asList(stack1, stack2));
|
285
|
|
- uut.setRoot(bottomTabsController, new CommandListenerAdapter());
|
|
289
|
+ uut.setRoot(bottomTabsController, new CommandListenerAdapter(), reactInstanceManager);
|
286
|
290
|
|
287
|
291
|
stack1.push(child1, new CommandListenerAdapter());
|
288
|
292
|
stack2.push(child2, new CommandListenerAdapter());
|
|
@@ -302,7 +306,7 @@ public class NavigatorTest extends BaseTest {
|
302
|
306
|
disablePushAnimation(child1, child2, child3);
|
303
|
307
|
|
304
|
308
|
StackController stack = newStack();
|
305
|
|
- uut.setRoot(stack, new CommandListenerAdapter());
|
|
309
|
+ uut.setRoot(stack, new CommandListenerAdapter(), reactInstanceManager);
|
306
|
310
|
|
307
|
311
|
stack.push(child1, new CommandListenerAdapter());
|
308
|
312
|
stack.push(child2, new CommandListenerAdapter());
|
|
@@ -316,7 +320,7 @@ public class NavigatorTest extends BaseTest {
|
316
|
320
|
assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
|
317
|
321
|
|
318
|
322
|
ViewController root = spy(child1);
|
319
|
|
- uut.setRoot(root, new CommandListenerAdapter());
|
|
323
|
+ uut.setRoot(root, new CommandListenerAdapter(), reactInstanceManager);
|
320
|
324
|
when(root.handleBack(any(CommandListener.class))).thenReturn(true);
|
321
|
325
|
assertThat(uut.handleBack(new CommandListenerAdapter())).isTrue();
|
322
|
326
|
verify(root, times(1)).handleBack(any());
|
|
@@ -325,7 +329,7 @@ public class NavigatorTest extends BaseTest {
|
325
|
329
|
@Test
|
326
|
330
|
public void handleBack_modalTakePrecedenceOverRoot() {
|
327
|
331
|
ViewController root = spy(child1);
|
328
|
|
- uut.setRoot(root, new CommandListenerAdapter());
|
|
332
|
+ uut.setRoot(root, new CommandListenerAdapter(), reactInstanceManager);
|
329
|
333
|
uut.showModal(child2, new CommandListenerAdapter());
|
330
|
334
|
verify(root, times(0)).handleBack(new CommandListenerAdapter());
|
331
|
335
|
}
|
|
@@ -335,7 +339,7 @@ public class NavigatorTest extends BaseTest {
|
335
|
339
|
ComponentViewController componentVc = new SimpleComponentViewController(activity, childRegistry, "theId", new Options());
|
336
|
340
|
componentVc.setParentController(parentController);
|
337
|
341
|
assertThat(componentVc.options.topBar.title.text.get("")).isEmpty();
|
338
|
|
- uut.setRoot(componentVc, new CommandListenerAdapter());
|
|
342
|
+ uut.setRoot(componentVc, new CommandListenerAdapter(), reactInstanceManager);
|
339
|
343
|
|
340
|
344
|
Options options = new Options();
|
341
|
345
|
options.topBar.title.text = new Text("new title");
|
|
@@ -368,7 +372,7 @@ public class NavigatorTest extends BaseTest {
|
368
|
372
|
|
369
|
373
|
@Test
|
370
|
374
|
public void findController_root() {
|
371
|
|
- uut.setRoot(child1, new CommandListenerAdapter());
|
|
375
|
+ uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
|
372
|
376
|
assertThat(uut.findController(child1.getId())).isEqualTo(child1);
|
373
|
377
|
}
|
374
|
378
|
|
|
@@ -399,7 +403,7 @@ public class NavigatorTest extends BaseTest {
|
399
|
403
|
public void push_promise() {
|
400
|
404
|
final StackController stackController = newStack();
|
401
|
405
|
stackController.push(child1, new CommandListenerAdapter());
|
402
|
|
- uut.setRoot(stackController, new CommandListenerAdapter());
|
|
406
|
+ uut.setRoot(stackController, new CommandListenerAdapter(), reactInstanceManager);
|
403
|
407
|
|
404
|
408
|
assertIsChild(uut.getView(), stackController.getView());
|
405
|
409
|
assertIsChild(stackController.getView(), child1.getView());
|
|
@@ -415,7 +419,7 @@ public class NavigatorTest extends BaseTest {
|
415
|
419
|
|
416
|
420
|
@Test
|
417
|
421
|
public void push_InvalidPushWithoutAStack_DoesNothing_Promise() {
|
418
|
|
- uut.setRoot(child1, new CommandListenerAdapter());
|
|
422
|
+ uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
|
419
|
423
|
uut.push(child1.getId(), child2, new CommandListenerAdapter() {
|
420
|
424
|
@Override
|
421
|
425
|
public void onError(String message) {
|
|
@@ -428,7 +432,7 @@ public class NavigatorTest extends BaseTest {
|
428
|
432
|
@Test
|
429
|
433
|
public void pop_InvalidDoesNothing_Promise() {
|
430
|
434
|
uut.pop("123", Options.EMPTY, new CommandListenerAdapter());
|
431
|
|
- uut.setRoot(child1, new CommandListenerAdapter());
|
|
435
|
+ uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
|
432
|
436
|
uut.pop(child1.getId(), Options.EMPTY, new CommandListenerAdapter() {
|
433
|
437
|
@Override
|
434
|
438
|
public void onError(String reason) {
|
|
@@ -442,7 +446,7 @@ public class NavigatorTest extends BaseTest {
|
442
|
446
|
StackController stack1 = newStack();
|
443
|
447
|
final StackController stack2 = newStack();
|
444
|
448
|
BottomTabsController bottomTabsController = newTabs(Arrays.asList(stack1, stack2));
|
445
|
|
- uut.setRoot(bottomTabsController, new CommandListenerAdapter());
|
|
449
|
+ uut.setRoot(bottomTabsController, new CommandListenerAdapter(), reactInstanceManager);
|
446
|
450
|
|
447
|
451
|
stack1.push(child1, new CommandListenerAdapter());
|
448
|
452
|
stack2.push(child2, new CommandListenerAdapter());
|
|
@@ -458,7 +462,7 @@ public class NavigatorTest extends BaseTest {
|
458
|
462
|
|
459
|
463
|
@Test
|
460
|
464
|
public void pushIntoModal() {
|
461
|
|
- uut.setRoot(parentController, new CommandListenerAdapter());
|
|
465
|
+ uut.setRoot(parentController, new CommandListenerAdapter(), reactInstanceManager);
|
462
|
466
|
StackController stackController = newStack();
|
463
|
467
|
stackController.push(child1, new CommandListenerAdapter());
|
464
|
468
|
uut.showModal(stackController, new CommandListenerAdapter());
|
|
@@ -473,7 +477,7 @@ public class NavigatorTest extends BaseTest {
|
473
|
477
|
StackController spy = spy(parentController);
|
474
|
478
|
StackController parent = newStack();
|
475
|
479
|
parent.ensureViewIsCreated();
|
476
|
|
- uut.setRoot(parent, new CommandListenerAdapter());
|
|
480
|
+ uut.setRoot(parent, new CommandListenerAdapter(), reactInstanceManager);
|
477
|
481
|
parent.push(spy, new CommandListenerAdapter());
|
478
|
482
|
|
479
|
483
|
spy.push(child1, new CommandListenerAdapter());
|
|
@@ -505,7 +509,7 @@ public class NavigatorTest extends BaseTest {
|
505
|
509
|
}
|
506
|
510
|
});
|
507
|
511
|
}
|
508
|
|
- });
|
|
512
|
+ }, reactInstanceManager);
|
509
|
513
|
}
|
510
|
514
|
|
511
|
515
|
@Test
|
|
@@ -513,7 +517,7 @@ public class NavigatorTest extends BaseTest {
|
513
|
517
|
disableShowModalAnimation(child1, child2, child3);
|
514
|
518
|
disableDismissModalAnimation(child1, child2);
|
515
|
519
|
|
516
|
|
- uut.setRoot(parentController, new CommandListenerAdapter());
|
|
520
|
+ uut.setRoot(parentController, new CommandListenerAdapter(), reactInstanceManager);
|
517
|
521
|
parentController.push(child3, new CommandListenerAdapter());
|
518
|
522
|
uut.showModal(child1, new CommandListenerAdapter());
|
519
|
523
|
uut.showModal(child2, new CommandListenerAdapter());
|
|
@@ -532,7 +536,7 @@ public class NavigatorTest extends BaseTest {
|
532
|
536
|
public void dismissModal_reattachedToRoot() {
|
533
|
537
|
disableModalAnimations(child1);
|
534
|
538
|
|
535
|
|
- uut.setRoot(parentController, new CommandListenerAdapter());
|
|
539
|
+ uut.setRoot(parentController, new CommandListenerAdapter(), reactInstanceManager);
|
536
|
540
|
assertThat(ViewUtils.isChildOf(uut.getRootLayout(), parentController.getView()));
|
537
|
541
|
uut.showModal(child1, new CommandListenerAdapter());
|
538
|
542
|
|
|
@@ -565,7 +569,7 @@ public class NavigatorTest extends BaseTest {
|
565
|
569
|
uut.dismissAllModals(Options.EMPTY, new CommandListenerAdapter());
|
566
|
570
|
verify(parentVisibilityListener, times(0)).onViewAppeared(parentController.getView());
|
567
|
571
|
|
568
|
|
- uut.setRoot(parentController, new CommandListenerAdapter());
|
|
572
|
+ uut.setRoot(parentController, new CommandListenerAdapter(), reactInstanceManager);
|
569
|
573
|
parentController.push(child2, new CommandListenerAdapter());
|
570
|
574
|
|
571
|
575
|
verify(parentVisibilityListener, times(1)).onViewAppeared(parentController.getView());
|
|
@@ -581,7 +585,7 @@ public class NavigatorTest extends BaseTest {
|
581
|
585
|
|
582
|
586
|
parentController.push(child3, new CommandListenerAdapter());
|
583
|
587
|
StackController spy = spy(parentController);
|
584
|
|
- uut.setRoot(spy, new CommandListenerAdapter());
|
|
588
|
+ uut.setRoot(spy, new CommandListenerAdapter(), reactInstanceManager);
|
585
|
589
|
uut.showModal(child1, new CommandListenerAdapter());
|
586
|
590
|
uut.showModal(child2, new CommandListenerAdapter());
|
587
|
591
|
|
|
@@ -613,7 +617,7 @@ public class NavigatorTest extends BaseTest {
|
613
|
617
|
|
614
|
618
|
StackController spy = spy(parentController);
|
615
|
619
|
spy.options.animations.setRoot.enabled = new Bool(false);
|
616
|
|
- uut.setRoot(spy, new CommandListenerAdapter());
|
|
620
|
+ uut.setRoot(spy, new CommandListenerAdapter(), reactInstanceManager);
|
617
|
621
|
spy.push(child1, new CommandListenerAdapter());
|
618
|
622
|
activityController.destroy();
|
619
|
623
|
verify(spy, times(1)).destroy();
|
|
@@ -621,14 +625,14 @@ public class NavigatorTest extends BaseTest {
|
621
|
625
|
|
622
|
626
|
@Test
|
623
|
627
|
public void destroy_destroyOverlayManager() {
|
624
|
|
- uut.setRoot(parentController, new CommandListenerAdapter());
|
|
628
|
+ uut.setRoot(parentController, new CommandListenerAdapter(), reactInstanceManager);
|
625
|
629
|
activityController.destroy();
|
626
|
630
|
verify(overlayManager).destroy();
|
627
|
631
|
}
|
628
|
632
|
|
629
|
633
|
@Test
|
630
|
634
|
public void destroyViews() {
|
631
|
|
- uut.setRoot(parentController, new CommandListenerAdapter());
|
|
635
|
+ uut.setRoot(parentController, new CommandListenerAdapter(), reactInstanceManager);
|
632
|
636
|
uut.showModal(child1, new CommandListenerAdapter());
|
633
|
637
|
uut.showOverlay(child2, new CommandListenerAdapter());
|
634
|
638
|
uut.destroy();
|