|
@@ -1,6 +1,7 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
|
4
|
+import android.content.Context;
|
4
|
5
|
import android.support.annotation.NonNull;
|
5
|
6
|
import android.view.View;
|
6
|
7
|
|
|
@@ -21,6 +22,8 @@ import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
|
21
|
22
|
import com.reactnativenavigation.views.Component;
|
22
|
23
|
import com.reactnativenavigation.views.ReactComponent;
|
23
|
24
|
import com.reactnativenavigation.views.StackLayout;
|
|
25
|
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
|
|
26
|
+import com.reactnativenavigation.views.topbar.TopBar;
|
24
|
27
|
|
25
|
28
|
import org.assertj.core.api.iterable.Extractor;
|
26
|
29
|
import org.json.JSONObject;
|
|
@@ -170,17 +173,6 @@ public class StackControllerTest extends BaseTest {
|
170
|
173
|
assertThat(uut.isEmpty()).isFalse();
|
171
|
174
|
}
|
172
|
175
|
|
173
|
|
- @Test
|
174
|
|
- public void pushAssignsRefToSelfOnPushedController() {
|
175
|
|
- assertThat(child1.getParentController()).isNull();
|
176
|
|
- uut.push(child1, new CommandListenerAdapter());
|
177
|
|
- assertThat(child1.getParentController()).isEqualTo(uut);
|
178
|
|
-
|
179
|
|
- StackController anotherNavController = createStackController("another");
|
180
|
|
- anotherNavController.push(child2, new CommandListenerAdapter());
|
181
|
|
- assertThat(child2.getParentController()).isEqualTo(anotherNavController);
|
182
|
|
- }
|
183
|
|
-
|
184
|
176
|
@Test
|
185
|
177
|
public void handleBack_PopsUnlessSingleChild() {
|
186
|
178
|
assertThat(uut.isEmpty()).isTrue();
|
|
@@ -226,14 +218,14 @@ public class StackControllerTest extends BaseTest {
|
226
|
218
|
}
|
227
|
219
|
|
228
|
220
|
@Test
|
229
|
|
- public void pushAddsToViewTree() {
|
|
221
|
+ public void push_addsToViewTree() {
|
230
|
222
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
|
231
|
223
|
uut.push(child1, new CommandListenerAdapter());
|
232
|
224
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
|
233
|
225
|
}
|
234
|
226
|
|
235
|
227
|
@Test
|
236
|
|
- public void pushRemovesPreviousFromTree() {
|
|
228
|
+ public void push_removesPreviousFromTree() {
|
237
|
229
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
|
238
|
230
|
uut.push(child1, new CommandListenerAdapter());
|
239
|
231
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
|
|
@@ -247,7 +239,60 @@ public class StackControllerTest extends BaseTest {
|
247
|
239
|
}
|
248
|
240
|
|
249
|
241
|
@Test
|
250
|
|
- public void popReplacesViewWithPrevious() {
|
|
242
|
+ public void push_assignsRefToSelfOnPushedController() {
|
|
243
|
+ assertThat(child1.getParentController()).isNull();
|
|
244
|
+ uut.push(child1, new CommandListenerAdapter());
|
|
245
|
+ assertThat(child1.getParentController()).isEqualTo(uut);
|
|
246
|
+
|
|
247
|
+ StackController anotherNavController = createStackController("another");
|
|
248
|
+ anotherNavController.push(child2, new CommandListenerAdapter());
|
|
249
|
+ assertThat(child2.getParentController()).isEqualTo(anotherNavController);
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ @Test
|
|
253
|
+ public void push_doesNotAnimateTopBarIfScreenIsPushedWithoutAnimation() {
|
|
254
|
+ uut.ensureViewIsCreated();
|
|
255
|
+ child1.ensureViewIsCreated();
|
|
256
|
+
|
|
257
|
+ child1.options.topBarOptions.visible = new Bool(false);
|
|
258
|
+ child1.options.topBarOptions.animate = new Bool(false);
|
|
259
|
+ child1.options.animated = new Bool(false);
|
|
260
|
+ child2.options.animated = new Bool(false);
|
|
261
|
+
|
|
262
|
+ uut.push(child1, new CommandListenerAdapter() {
|
|
263
|
+ @Override
|
|
264
|
+ public void onSuccess(String childId) {
|
|
265
|
+ child1.onViewAppeared();
|
|
266
|
+ assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
|
|
267
|
+
|
|
268
|
+ uut.push(child2, new CommandListenerAdapter());
|
|
269
|
+ child2.onViewAppeared();
|
|
270
|
+ verify(uut.getTopBar(), times(0)).showAnimate(child2.options.animationsOptions.push.topBar);
|
|
271
|
+ assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.VISIBLE);
|
|
272
|
+ verify(uut.getTopBar(), times(1)).resetAnimationOptions();
|
|
273
|
+ }
|
|
274
|
+ });
|
|
275
|
+ }
|
|
276
|
+
|
|
277
|
+ @Test
|
|
278
|
+ public void push_animatesAndClearsPreviousAnimationValues() {
|
|
279
|
+ uut.ensureViewIsCreated();
|
|
280
|
+
|
|
281
|
+ child1.options.topBarOptions.visible = new Bool(false);
|
|
282
|
+ child1.options.topBarOptions.animate = new Bool(false);
|
|
283
|
+ child1.options.animated = new Bool(false);
|
|
284
|
+
|
|
285
|
+ uut.push(child1, new CommandListenerAdapter());
|
|
286
|
+ uut.push(child2, new CommandListenerAdapter() {
|
|
287
|
+ @Override
|
|
288
|
+ public void onSuccess(String childId) {
|
|
289
|
+ verify(uut.getTopBar(), times(1)).resetAnimationOptions();
|
|
290
|
+ }
|
|
291
|
+ });
|
|
292
|
+ }
|
|
293
|
+
|
|
294
|
+ @Test
|
|
295
|
+ public void pop_replacesViewWithPrevious() {
|
251
|
296
|
final View child2View = child2.getView();
|
252
|
297
|
final View child1View = child1.getView();
|
253
|
298
|
|
|
@@ -265,7 +310,7 @@ public class StackControllerTest extends BaseTest {
|
265
|
310
|
}
|
266
|
311
|
|
267
|
312
|
@Test
|
268
|
|
- public void popSpecificWhenTopIsRegularPop() {
|
|
313
|
+ public void pop_specificWhenTopIsRegularPop() {
|
269
|
314
|
uut.push(child1, new CommandListenerAdapter());
|
270
|
315
|
uut.push(child2, new CommandListenerAdapter() {
|
271
|
316
|
@Override
|
|
@@ -282,7 +327,7 @@ public class StackControllerTest extends BaseTest {
|
282
|
327
|
}
|
283
|
328
|
|
284
|
329
|
@Test
|
285
|
|
- public void popSpecificDeepInStack() {
|
|
330
|
+ public void popSpecific_deepInStack() {
|
286
|
331
|
uut.push(child1, new CommandListenerAdapter());
|
287
|
332
|
uut.push(child2, new CommandListenerAdapter());
|
288
|
333
|
assertIsChildById(uut.getView(), child2.getView());
|
|
@@ -460,29 +505,52 @@ public class StackControllerTest extends BaseTest {
|
460
|
505
|
}
|
461
|
506
|
|
462
|
507
|
@Test
|
463
|
|
- public void pop_animatesTopBarIfNeeded() {
|
|
508
|
+ public void pop_animatesTopBar() {
|
464
|
509
|
uut.ensureViewIsCreated();
|
465
|
510
|
|
466
|
511
|
child1.options.topBarOptions.visible = new Bool(false);
|
467
|
|
- child1.options.topBarOptions.animate = new Bool(false);
|
468
|
|
- child2.options.topBarOptions.visible = new Bool(true);
|
469
|
|
- uut.push(child1, new CommandListenerAdapter());
|
470
|
|
- child1.onViewAppeared();
|
471
|
|
-
|
472
|
|
- assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
|
473
|
|
- uut.push(child2, new CommandListenerAdapter() {
|
|
512
|
+ child1.options.animated = new Bool(false);
|
|
513
|
+ child2.options.animated = new Bool(true);
|
|
514
|
+ uut.push(child1, new CommandListenerAdapter() {
|
474
|
515
|
@Override
|
475
|
516
|
public void onSuccess(String childId) {
|
476
|
|
- uut.pop(new CommandListenerAdapter() {
|
|
517
|
+ child1.onViewAppeared();
|
|
518
|
+ assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
|
|
519
|
+ uut.push(child2, new CommandListenerAdapter() {
|
477
|
520
|
@Override
|
478
|
521
|
public void onSuccess(String childId) {
|
479
|
|
- verify(uut.getTopBar(), times(1)).hide();
|
|
522
|
+ uut.pop(new CommandListenerAdapter() {
|
|
523
|
+ @Override
|
|
524
|
+ public void onSuccess(String childId) {
|
|
525
|
+ verify(uut.getTopBar(), times(1)).hideAnimate(child2.options.animationsOptions.pop.topBar);
|
|
526
|
+ }
|
|
527
|
+ });
|
480
|
528
|
}
|
481
|
529
|
});
|
482
|
530
|
}
|
483
|
531
|
});
|
484
|
532
|
}
|
485
|
533
|
|
|
534
|
+ @Test
|
|
535
|
+ public void pop_doesNotAnimateTopBarIfScreenIsPushedWithoutAnimation() {
|
|
536
|
+ uut.ensureViewIsCreated();
|
|
537
|
+
|
|
538
|
+ child1.options.topBarOptions.visible = new Bool(false);
|
|
539
|
+ child2.options.animated = new Bool(false);
|
|
540
|
+ child1.ensureViewIsCreated();
|
|
541
|
+ uut.push(child1, new CommandListenerAdapter() {
|
|
542
|
+ @Override
|
|
543
|
+ public void onSuccess(String childId) {
|
|
544
|
+ uut.push(child2, new CommandListenerAdapter());
|
|
545
|
+ assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.VISIBLE);
|
|
546
|
+
|
|
547
|
+ uut.pop(new CommandListenerAdapter());
|
|
548
|
+ verify(uut.getTopBar(), times(0)).hideAnimate(child2.options.animationsOptions.pop.topBar);
|
|
549
|
+ assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
|
|
550
|
+ }
|
|
551
|
+ });
|
|
552
|
+ }
|
|
553
|
+
|
486
|
554
|
@Test
|
487
|
555
|
public void popSpecific_CallsDestroyOnPoppedChild() {
|
488
|
556
|
child1 = spy(child1);
|
|
@@ -656,10 +724,20 @@ public class StackControllerTest extends BaseTest {
|
656
|
724
|
}
|
657
|
725
|
|
658
|
726
|
private StackController createStackController(String id) {
|
659
|
|
- topBarController = spy(new TopBarController());
|
|
727
|
+ topBarController = spy(new TopBarController() {
|
|
728
|
+ @Override
|
|
729
|
+ protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout) {
|
|
730
|
+ TopBar topBar = spy(super.createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout));
|
|
731
|
+ return topBar;
|
|
732
|
+ }
|
|
733
|
+ });
|
660
|
734
|
return new StackController(activity,
|
661
|
|
- new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()),
|
662
|
|
- topBarController, id, new Options()) {
|
|
735
|
+ new TopBarButtonCreatorMock(),
|
|
736
|
+ new TitleBarReactViewCreatorMock(),
|
|
737
|
+ new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()),
|
|
738
|
+ topBarController,
|
|
739
|
+ id,
|
|
740
|
+ new Options()) {
|
663
|
741
|
@Override
|
664
|
742
|
NavigationAnimator createAnimator() {
|
665
|
743
|
animator = Mockito.mock(NavigationAnimator.class);
|