StackController extends ParentController<StackLayout> { @Override public void mergeChildOptions(Options options, ViewController childController, Component child) { super.mergeChildOptions(options, childController, child); if (childController.isViewShown() && peek() == childController) { presenter.mergeChildOptions(options, resolveCurrentOptions(), child); if (options.fabOptions.hasValue() && child instanceof ReactComponent) { fabOptionsPresenter.mergeOptions(options.fabOptions, (ReactComponent) child, getView()); } } performOnParentController(parentController -> ((ParentController) parentController).mergeChildOptions( options.copy() .clearTopBarOptions() .clearAnimationOptions() .clearFabOptions() .clearTopTabOptions() .clearTopTabsOptions(), childController, child ) ); } StackController(Activity activity, List<ViewController> children, ChildControllersRegistry childRegistry, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, NavigationAnimator animator, String id, Options initialOptions, BackButtonHelper backButtonHelper, StackPresenter stackPresenter, Presenter presenter); @Override void setDefaultOptions(Options defaultOptions); @Override void onAttachToParent(); @Override void mergeOptions(Options options); @Override void applyChildOptions(Options options, Component child); @Override void mergeChildOptions(Options options, ViewController childController, Component child); @Override void destroy(); @Override void clearOptions(); @Override void onChildDestroyed(Component child); void push(ViewController child, CommandListener listener); void setRoot(ViewController child, CommandListener listener); void pop(Options mergeOptions, CommandListener listener); void popTo(ViewController viewController, Options mergeOptions, CommandListener listener); void popToRoot(Options mergeOptions, CommandListener listener); int size(); boolean isEmpty(); @Override boolean handleBack(CommandListener listener); @Override void sendOnNavigationButtonPressed(String buttonId); @NonNull @Override Collection<ViewController> getChildControllers(); @Override void setupTopTabsWithViewPager(ViewPager viewPager); @Override void clearTopTabs(); @RestrictTo(RestrictTo.Scope.TESTS) TopBar getTopBar(); @RestrictTo(RestrictTo.Scope.TESTS) StackLayout getStackLayout();  }
@Test public void mergeChildOptions_updatesViewWithNewOptions() { StackController uut = spy(new StackControllerBuilder(activity) .setTopBarButtonCreator(new TopBarButtonCreatorMock()) .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock())) .setTopBarController(new TopBarController()) .setId("stack") .setInitialOptions(new Options()) .setStackPresenter(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarButtonCreatorMock(), new ImageLoader(), new Options())) .build()); Options optionsToMerge = new Options(); Component component = mock(Component.class); ViewController vc = mock(ViewController.class); uut.mergeChildOptions(optionsToMerge, vc, component); verify(uut, times(1)).mergeChildOptions(optionsToMerge, vc, component); }
@Test public void mergeChildOptions_updatesParentControllerWithNewOptions() { StackController uut = new StackControllerBuilder(activity) .setTopBarButtonCreator(new TopBarButtonCreatorMock()) .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock())) .setTopBarController(new TopBarController()) .setId("stack") .setInitialOptions(new Options()) .setStackPresenter(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarButtonCreatorMock(), new ImageLoader(), new Options())) .build(); ParentController parentController = Mockito.mock(ParentController.class); uut.setParentController(parentController); uut.ensureViewIsCreated(); Options optionsToMerge = new Options(); optionsToMerge.topBar.testId = new Text("topBarID"); optionsToMerge.bottomTabsOptions.testId = new Text("bottomTabsID"); Component component = mock(Component.class); ViewController vc = mock(ViewController.class); uut.mergeChildOptions(optionsToMerge, vc, component); ArgumentCaptor<Options> captor = ArgumentCaptor.forClass(Options.class); verify(parentController, times(1)).mergeChildOptions(captor.capture(), eq(vc), eq(component)); assertThat(captor.getValue().topBar.testId.hasValue()).isFalse(); assertThat(captor.getValue().bottomTabsOptions.testId.get()).isEqualTo(optionsToMerge.bottomTabsOptions.testId.get()); }
@Test public void mergeChildOptions_StackRelatedOptionsAreCleared() { uut.ensureViewIsCreated(); ParentController parentController = Mockito.mock(ParentController.class); uut.setParentController(parentController); Options options = new Options(); options.animations.push = NestedAnimationsOptions.parse(new JSONObject()); options.topBar.testId = new Text("id"); options.fabOptions.id = new Text("fabId"); Component component = mock(Component.class); ViewController vc = mock(ViewController.class); assertThat(options.fabOptions.hasValue()).isTrue(); uut.mergeChildOptions(options, vc, component); ArgumentCaptor<Options> captor = ArgumentCaptor.forClass(Options.class); verify(parentController, times(1)).mergeChildOptions(captor.capture(), eq(vc), eq(component)); assertThat(captor.getValue().animations.push.hasValue()).isFalse(); assertThat(captor.getValue().topBar.testId.hasValue()).isFalse(); assertThat(captor.getValue().fabOptions.hasValue()).isFalse(); }
@Test public void mergeChildOptions_presenterDoesNotApplyOptionsIfViewIsNotShown() { ViewController vc = mock(ViewController.class); when(vc.isViewShown()).thenReturn(false); Component child = mock(Component.class); uut.mergeChildOptions(new Options(), vc, child); verify(presenter, times(0)).mergeChildOptions(any(), any(), any()); }
@Test public void mergeChildOptions_presenterMergesOptionsOnlyForCurrentChild() { ViewController vc = mock(ViewController.class); when(vc.isViewShown()).thenReturn(true); Component child = mock(Component.class); uut.mergeChildOptions(new Options(), vc, child); verify(presenter, times(0)).mergeChildOptions(any(), any(), any()); }