react-native-navigation 7.24.3 → 7.25.1
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/lib/android/app/build.gradle +12 -9
- package/lib/android/app/src/main/java/com/reactnativenavigation/options/Options.java +2 -0
- package/lib/android/app/src/main/java/com/reactnativenavigation/options/layout/LayoutInsets.kt +44 -0
- package/lib/android/app/src/main/java/com/reactnativenavigation/options/layout/LayoutOptions.kt +71 -0
- package/lib/android/app/src/main/java/com/reactnativenavigation/utils/PrimitiveExt.kt +9 -0
- package/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/component/ComponentViewController.java +4 -3
- package/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/navigator/Navigator.java +5 -0
- package/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/viewcontroller/Presenter.java +23 -7
- package/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/viewcontroller/ViewController.java +12 -3
- package/lib/dist/src/interfaces/Options.d.ts +10 -0
- package/lib/ios/RNNBasePresenter.m +17 -0
- package/lib/ios/RNNBottomTabsController.m +1 -0
- package/lib/ios/RNNBridgeManager.mm +5 -3
- package/lib/ios/RNNComponentViewController.m +5 -0
- package/lib/ios/RNNLayoutOptions.h +2 -1
- package/lib/ios/RNNLayoutOptions.m +4 -0
- package/lib/ios/RNNModalHostViewManagerHandler.h +11 -0
- package/lib/ios/RNNModalHostViewManagerHandler.m +40 -0
- package/lib/ios/RNNModalManager.h +2 -2
- package/lib/ios/RNNModalManager.m +0 -26
- package/lib/ios/RNNStackPresenter.m +1 -0
- package/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj +8 -0
- package/lib/src/interfaces/Options.ts +12 -0
- package/package.json +3 -1
- package/.buildkite/pipeline.yml +0 -59
- package/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutOptions.java +0 -48
- package/lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java +0 -178
- package/lib/android/app/src/test/java/com/reactnativenavigation/EnvironmentTest.java +0 -43
- package/lib/android/app/src/test/java/com/reactnativenavigation/TestActivity.java +0 -23
- package/lib/android/app/src/test/java/com/reactnativenavigation/TestApplication.java +0 -35
- package/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java +0 -62
- package/lib/android/app/src/test/java/com/reactnativenavigation/fakes/IconResolverFake.kt +0 -8
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/BackDrawable.java +0 -30
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/ImageLoaderMock.kt +0 -49
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/Mocks.kt +0 -18
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleComponentViewController.java +0 -15
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleOverlay.java +0 -54
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleViewController.java +0 -113
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TestComponentLayout.java +0 -79
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TestComponentViewCreator.java +0 -18
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TestReactView.java +0 -71
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TitleBarButtonCreatorMock.java +0 -34
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TitleBarReactViewCreatorMock.java +0 -20
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TopBarBackgroundViewCreatorMock.java +0 -20
- package/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TypefaceLoaderMock.kt +0 -21
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/LayoutNodeParserTest.java +0 -51
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java +0 -315
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/OrientationOptionsTest.java +0 -81
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/TopBarButtonsTest.kt +0 -95
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/TransitionAnimationOptionsTest.kt +0 -122
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/BoolParserTest.java +0 -28
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java +0 -50
- package/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/JSONParserTest.java +0 -64
- package/lib/android/app/src/test/java/com/reactnativenavigation/presentation/PresenterTest.java +0 -56
- package/lib/android/app/src/test/java/com/reactnativenavigation/presentation/RenderCheckerTest.java +0 -59
- package/lib/android/app/src/test/java/com/reactnativenavigation/presentation/SideMenuPresenterTest.java +0 -35
- package/lib/android/app/src/test/java/com/reactnativenavigation/react/NavigationModuleTest.java +0 -102
- package/lib/android/app/src/test/java/com/reactnativenavigation/react/ReloadListenerTest.java +0 -24
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/AnimationHelper.kt +0 -33
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonPresenterTest.java +0 -241
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonSpanTest.java +0 -57
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/CompatUtilsTest.java +0 -17
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/LayoutFactoryTest.java +0 -78
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/MotionEventTest.kt +0 -47
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java +0 -60
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/OptionHelper.java +0 -16
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/ReflectionUtilsTest.java +0 -26
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/StringUtilsTest.java +0 -19
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/SystemUiUtilsTest.kt +0 -27
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/TitleAndButtonsMeasurerTest.kt +0 -357
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/TitleBarHelper.java +0 -54
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/UiThreadTest.java +0 -29
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/UiUtilsTest.java +0 -22
- package/lib/android/app/src/test/java/com/reactnativenavigation/utils/ViewHelper.java +0 -9
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java +0 -149
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenterTest.java +0 -206
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsAttacherTest.java +0 -62
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.kt +0 -589
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsPresenterTest.kt +0 -173
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/AfterInitialTabTest.java +0 -38
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/AttachModeTest.java +0 -86
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/OnSwitchToTabTest.java +0 -31
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/TogetherTest.java +0 -20
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolverTest.java +0 -78
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllerTest.java +0 -80
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllersRegistryTest.java +0 -56
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/component/ComponentViewControllerTest.java +0 -216
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/externalcomponent/ExternalComponentViewControllerTest.java +0 -97
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/externalcomponent/FragmentCreatorMock.java +0 -34
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/externalcomponent/SomeFragment.java +0 -8
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/fakes/FakeParentController.kt +0 -33
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalAnimatorMock.java +0 -40
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalAnimatorTest.kt +0 -213
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenterTest.java +0 -319
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java +0 -367
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java +0 -898
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/RootPresenterTest.kt +0 -254
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/overlay/OverlayManagerTest.java +0 -108
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/parent/ParentControllerTest.java +0 -299
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/sidemenu/SideMenuControllerTest.java +0 -446
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/BackButtonHelperTest.java +0 -77
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/FloatingActionButtonTest.java +0 -154
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/IdStackTest.java +0 -114
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackAnimatorTest.kt +0 -241
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.kt +0 -1165
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenterTest.kt +0 -1081
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/TitleBarButtonControllerTest.java +0 -61
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/TitleBarReactViewControllerTest.java +0 -43
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/TopBarButtonControllerTest.java +0 -120
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/TopBarControllerTest.kt +0 -432
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/toptabs/TopTabsViewControllerTest.java +0 -249
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/viewcontroller/ViewControllerTest.java +0 -337
- package/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/viewcontroller/YellowBoxDelegateTest.java +0 -68
- package/lib/android/app/src/test/java/com/reactnativenavigation/views/OverlayTouchDelegateTest.java +0 -60
- package/lib/android/app/src/test/java/com/reactnativenavigation/views/TitleAndButtonsContainerTest.kt +0 -477
- package/lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java +0 -82
- package/lib/android/app/src/test/java/com/reactnativenavigation/views/animations/BaseViewAnimatorTest.kt +0 -109
- package/lib/android/app/src/test/java/com/reactnativenavigation/views/animations/DefaultViewAnimatorCreatorFake.kt +0 -36
- package/lib/android/app/src/test/java/com/reactnativenavigation/views/bottomtabs/BottomTabsContainerTest.kt +0 -101
- package/lib/android/app/src/test/java/com/reactnativenavigation/views/bottomtabs/BottomTabsTest.kt +0 -40
- package/lib/android/app/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +0 -1
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
package com.reactnativenavigation.viewcontrollers.toptabs;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.view.ViewGroup;
|
|
5
|
-
|
|
6
|
-
import com.reactnativenavigation.BaseTest;
|
|
7
|
-
import com.reactnativenavigation.TestUtils;
|
|
8
|
-
import com.reactnativenavigation.mocks.SimpleViewController;
|
|
9
|
-
import com.reactnativenavigation.mocks.TestComponentViewCreator;
|
|
10
|
-
import com.reactnativenavigation.mocks.TestReactView;
|
|
11
|
-
import com.reactnativenavigation.options.Options;
|
|
12
|
-
import com.reactnativenavigation.options.params.Bool;
|
|
13
|
-
import com.reactnativenavigation.options.params.Text;
|
|
14
|
-
import com.reactnativenavigation.viewcontrollers.component.ComponentPresenter;
|
|
15
|
-
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter;
|
|
16
|
-
import com.reactnativenavigation.react.events.ComponentType;
|
|
17
|
-
import com.reactnativenavigation.react.CommandListenerAdapter;
|
|
18
|
-
import com.reactnativenavigation.utils.ViewHelper;
|
|
19
|
-
import com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView;
|
|
20
|
-
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
|
|
21
|
-
import com.reactnativenavigation.viewcontrollers.component.ComponentViewController;
|
|
22
|
-
import com.reactnativenavigation.viewcontrollers.stack.StackController;
|
|
23
|
-
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController;
|
|
24
|
-
import com.reactnativenavigation.views.toptabs.TopTabsLayoutCreator;
|
|
25
|
-
import com.reactnativenavigation.views.toptabs.TopTabsViewPager;
|
|
26
|
-
|
|
27
|
-
import org.junit.Ignore;
|
|
28
|
-
import org.junit.Test;
|
|
29
|
-
import org.mockito.Mockito;
|
|
30
|
-
|
|
31
|
-
import java.util.ArrayList;
|
|
32
|
-
import java.util.List;
|
|
33
|
-
|
|
34
|
-
import androidx.annotation.NonNull;
|
|
35
|
-
|
|
36
|
-
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
37
|
-
import static org.mockito.ArgumentMatchers.any;
|
|
38
|
-
import static org.mockito.ArgumentMatchers.eq;
|
|
39
|
-
import static org.mockito.Mockito.spy;
|
|
40
|
-
import static org.mockito.Mockito.times;
|
|
41
|
-
import static org.mockito.Mockito.verify;
|
|
42
|
-
|
|
43
|
-
public class TopTabsViewControllerTest extends BaseTest {
|
|
44
|
-
private static final int SIZE = 2;
|
|
45
|
-
|
|
46
|
-
private StackController stack;
|
|
47
|
-
private TopTabsController uut;
|
|
48
|
-
private List<ViewController<?>> tabControllers = new ArrayList<>(SIZE);
|
|
49
|
-
private final Options options = new Options();
|
|
50
|
-
private TopTabsViewPager topTabsLayout;
|
|
51
|
-
private Activity activity;
|
|
52
|
-
private ChildControllersRegistry childRegistry;
|
|
53
|
-
|
|
54
|
-
@Override
|
|
55
|
-
public void beforeEach() {
|
|
56
|
-
super.beforeEach();
|
|
57
|
-
|
|
58
|
-
activity = newActivity();
|
|
59
|
-
childRegistry = new ChildControllersRegistry();
|
|
60
|
-
List<Options> tabOptions = createOptions();
|
|
61
|
-
tabControllers = createTabsControllers(activity, tabOptions);
|
|
62
|
-
|
|
63
|
-
topTabsLayout = spy(new TopTabsViewPager(activity, tabControllers, new TopTabsAdapter(tabControllers)));
|
|
64
|
-
TopTabsLayoutCreator layoutCreator = Mockito.mock(TopTabsLayoutCreator.class);
|
|
65
|
-
Mockito.when(layoutCreator.create()).thenReturn(topTabsLayout);
|
|
66
|
-
Presenter presenter = new Presenter(activity, new Options());
|
|
67
|
-
options.topBar.buttons.back.visible = new Bool(false);
|
|
68
|
-
uut = spy(new TopTabsController(activity, childRegistry, "componentId", tabControllers, layoutCreator, options, presenter));
|
|
69
|
-
tabControllers.forEach(viewController -> viewController.setParentController(uut));
|
|
70
|
-
|
|
71
|
-
stack = spy(TestUtils.newStackController(activity).build());
|
|
72
|
-
stack.ensureViewIsCreated();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@NonNull
|
|
76
|
-
private ArrayList<Options> createOptions() {
|
|
77
|
-
ArrayList<Options> result = new ArrayList<>();
|
|
78
|
-
for (int i = 0; i < SIZE; i++) {
|
|
79
|
-
final Options options = new Options();
|
|
80
|
-
options.topTabOptions.title = new Text("Tab " + i);
|
|
81
|
-
options.topBar.title.text = new Text(createTabTopBarTitle(i));
|
|
82
|
-
result.add(options);
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private List<ViewController<?>> createTabsControllers(Activity activity, List<Options> tabOptions) {
|
|
88
|
-
List<ViewController<?>> tabControllers = new ArrayList<>(SIZE);
|
|
89
|
-
for (int i = 0; i < SIZE; i++) {
|
|
90
|
-
ComponentViewController viewController = new ComponentViewController(
|
|
91
|
-
activity,
|
|
92
|
-
childRegistry,
|
|
93
|
-
"idTab" + i,
|
|
94
|
-
"theComponentName",
|
|
95
|
-
new TestComponentViewCreator(),
|
|
96
|
-
tabOptions.get(i),
|
|
97
|
-
new Presenter(activity, new Options()),
|
|
98
|
-
new ComponentPresenter(Options.EMPTY)
|
|
99
|
-
);
|
|
100
|
-
tabControllers.add(spy(viewController));
|
|
101
|
-
}
|
|
102
|
-
return tabControllers;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
@Test
|
|
106
|
-
public void createsViewFromComponentViewCreator() {
|
|
107
|
-
uut.ensureViewIsCreated();
|
|
108
|
-
for (int i = 0; i < SIZE; i++) {
|
|
109
|
-
verify(tabControllers.get(i), times(1)).createView();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
@Test
|
|
114
|
-
public void componentViewDestroyedOnDestroy() {
|
|
115
|
-
uut.ensureViewIsCreated();
|
|
116
|
-
TopTabsViewPager topTabs = uut.getView();
|
|
117
|
-
for (int i = 0; i < SIZE; i++) {
|
|
118
|
-
verify(tab(topTabs, i), times(0)).destroy();
|
|
119
|
-
}
|
|
120
|
-
uut.destroy();
|
|
121
|
-
for (ViewController<?> tabController : tabControllers) {
|
|
122
|
-
verify(tabController, times(1)).destroy();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
@Test
|
|
127
|
-
@Ignore("TopTabs not yet well supported")
|
|
128
|
-
public void lifecycleMethodsSentWhenSelectedTabChanges() {
|
|
129
|
-
stack.ensureViewIsCreated();
|
|
130
|
-
uut.ensureViewIsCreated();
|
|
131
|
-
tabControllers.get(0).ensureViewIsCreated();
|
|
132
|
-
tabControllers.get(1).ensureViewIsCreated();
|
|
133
|
-
|
|
134
|
-
TestReactView initialTab = getActualTabView(0);
|
|
135
|
-
TestReactView selectedTab = getActualTabView(1);
|
|
136
|
-
|
|
137
|
-
uut.switchToTab(1);
|
|
138
|
-
verify(initialTab, times(1)).sendComponentStop(ComponentType.Component);
|
|
139
|
-
verify(selectedTab, times(1)).sendComponentWillStart(ComponentType.Component);
|
|
140
|
-
verify(selectedTab, times(1)).sendComponentStart(ComponentType.Component);
|
|
141
|
-
verify(selectedTab, times(0)).sendComponentStop(ComponentType.Component);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@Test
|
|
145
|
-
public void lifecycleMethodsSentWhenSelectedPreviouslySelectedTab() {
|
|
146
|
-
stack.ensureViewIsCreated();
|
|
147
|
-
uut.ensureViewIsCreated();
|
|
148
|
-
uut.onViewDidAppear();
|
|
149
|
-
uut.switchToTab(1);
|
|
150
|
-
uut.switchToTab(0);
|
|
151
|
-
|
|
152
|
-
verify(getActualTabView(0), times(1)).sendComponentStop(ComponentType.Component);
|
|
153
|
-
verify(getActualTabView(0), times(2)).sendComponentWillStart(ComponentType.Component);
|
|
154
|
-
verify(getActualTabView(0), times(2)).sendComponentStart(ComponentType.Component);
|
|
155
|
-
verify(getActualTabView(1), times(1)).sendComponentStart(ComponentType.Component);
|
|
156
|
-
verify(getActualTabView(1), times(1)).sendComponentStop(ComponentType.Component);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@Test
|
|
160
|
-
public void setOptionsOfInitialTab() {
|
|
161
|
-
stack.ensureViewIsCreated();
|
|
162
|
-
uut.ensureViewIsCreated();
|
|
163
|
-
uut.onViewWillAppear();
|
|
164
|
-
verify(tabControllers.get(0), times(1)).onViewWillAppear();
|
|
165
|
-
verify(tabControllers.get(1), times(0)).onViewWillAppear();
|
|
166
|
-
|
|
167
|
-
ViewController<?> comp = tabControllers.get(0);
|
|
168
|
-
verify(uut, times(1)).applyChildOptions(any(Options.class), eq(comp));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
@Test
|
|
172
|
-
public void setOptionsWhenTabChanges() {
|
|
173
|
-
stack.ensureViewIsCreated();
|
|
174
|
-
uut.ensureViewIsCreated();
|
|
175
|
-
tabControllers.get(0).ensureViewIsCreated();
|
|
176
|
-
tabControllers.get(1).ensureViewIsCreated();
|
|
177
|
-
|
|
178
|
-
uut.onViewWillAppear();
|
|
179
|
-
ViewController<?> currentTab = tab(0);
|
|
180
|
-
verify(uut, times(1)).applyChildOptions(any(Options.class), eq(currentTab));
|
|
181
|
-
assertThat(uut.options.topBar.title.text.get()).isEqualTo(createTabTopBarTitle(0));
|
|
182
|
-
|
|
183
|
-
uut.switchToTab(1);
|
|
184
|
-
currentTab = tab(1);
|
|
185
|
-
verify(uut, times(1)).applyChildOptions(any(Options.class), eq(currentTab));
|
|
186
|
-
assertThat(uut.options.topBar.title.text.get()).isEqualTo(createTabTopBarTitle(1));
|
|
187
|
-
|
|
188
|
-
uut.switchToTab(0);
|
|
189
|
-
currentTab = tab(0);
|
|
190
|
-
verify(uut, times(2)).applyChildOptions(any(Options.class), eq(currentTab));
|
|
191
|
-
assertThat(uut.options.topBar.title.text.get()).isEqualTo(createTabTopBarTitle(0));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private TestReactView getActualTabView(int index) {
|
|
195
|
-
return (TestReactView) tabControllers.get(index).getView().getChildAt(0);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@Test
|
|
199
|
-
public void appliesOptionsOnLayoutWhenVisible() {
|
|
200
|
-
tabControllers.get(0).ensureViewIsCreated();
|
|
201
|
-
stack.ensureViewIsCreated();
|
|
202
|
-
uut.ensureViewIsCreated();
|
|
203
|
-
|
|
204
|
-
uut.onViewWillAppear();
|
|
205
|
-
|
|
206
|
-
verify(topTabsLayout, times(1)).applyOptions(any(Options.class));
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
@Test
|
|
210
|
-
public void applyOptions_tabsAreRemovedAfterViewDisappears() {
|
|
211
|
-
StackController stackController = TestUtils.newStackController(activity).build();
|
|
212
|
-
stackController.ensureViewIsCreated();
|
|
213
|
-
ViewController<?> first = new SimpleViewController(activity, childRegistry, "first", Options.EMPTY);
|
|
214
|
-
disablePushAnimation(first, uut);
|
|
215
|
-
stackController.push(first, new CommandListenerAdapter());
|
|
216
|
-
stackController.push(uut, new CommandListenerAdapter());
|
|
217
|
-
|
|
218
|
-
uut.onViewWillAppear();
|
|
219
|
-
|
|
220
|
-
assertThat(ViewHelper.isVisible(stackController.getTopBar().getTopTabs())).isTrue();
|
|
221
|
-
disablePopAnimation(uut);
|
|
222
|
-
stackController.pop(Options.EMPTY, new CommandListenerAdapter());
|
|
223
|
-
|
|
224
|
-
first.onViewWillAppear();
|
|
225
|
-
|
|
226
|
-
assertThat(ViewHelper.isVisible(stackController.getTopBar().getTopTabs())).isFalse();
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
@Test
|
|
230
|
-
public void onNavigationButtonPressInvokedOnCurrentTab() {
|
|
231
|
-
uut.ensureViewIsCreated();
|
|
232
|
-
uut.onViewWillAppear();
|
|
233
|
-
uut.switchToTab(1);
|
|
234
|
-
uut.sendOnNavigationButtonPressed("btn1");
|
|
235
|
-
verify(tabControllers.get(1), times(1)).sendOnNavigationButtonPressed("btn1");
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private IReactView tab(TopTabsViewPager topTabs, final int index) {
|
|
239
|
-
return (IReactView) ((ViewGroup) topTabs.getChildAt(index)).getChildAt(0);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private String createTabTopBarTitle(int i) {
|
|
243
|
-
return "Title " + i;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
private ViewController<?> tab(int index) {
|
|
247
|
-
return tabControllers.get(index);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
package com.reactnativenavigation.viewcontrollers.viewcontroller;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.view.View;
|
|
5
|
-
import android.view.ViewGroup;
|
|
6
|
-
import android.view.ViewParent;
|
|
7
|
-
import android.widget.FrameLayout;
|
|
8
|
-
import android.widget.LinearLayout;
|
|
9
|
-
|
|
10
|
-
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
|
11
|
-
|
|
12
|
-
import com.reactnativenavigation.BaseTest;
|
|
13
|
-
import com.reactnativenavigation.TestUtils;
|
|
14
|
-
import com.reactnativenavigation.mocks.SimpleViewController;
|
|
15
|
-
import com.reactnativenavigation.options.Options;
|
|
16
|
-
import com.reactnativenavigation.options.params.Bool;
|
|
17
|
-
import com.reactnativenavigation.options.params.NullBool;
|
|
18
|
-
import com.reactnativenavigation.react.CommandListenerAdapter;
|
|
19
|
-
import com.reactnativenavigation.utils.Functions;
|
|
20
|
-
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
|
|
21
|
-
import com.reactnativenavigation.viewcontrollers.parent.ParentController;
|
|
22
|
-
import com.reactnativenavigation.viewcontrollers.stack.StackController;
|
|
23
|
-
import com.reactnativenavigation.viewcontrollers.viewcontroller.overlay.ViewControllerOverlay;
|
|
24
|
-
import com.reactnativenavigation.views.component.Component;
|
|
25
|
-
|
|
26
|
-
import org.assertj.android.api.Assertions;
|
|
27
|
-
import org.junit.Test;
|
|
28
|
-
import org.mockito.Mockito;
|
|
29
|
-
import org.robolectric.Shadows;
|
|
30
|
-
|
|
31
|
-
import java.lang.reflect.Field;
|
|
32
|
-
|
|
33
|
-
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
34
|
-
import static org.mockito.ArgumentMatchers.any;
|
|
35
|
-
import static org.mockito.Mockito.mock;
|
|
36
|
-
import static org.mockito.Mockito.spy;
|
|
37
|
-
import static org.mockito.Mockito.times;
|
|
38
|
-
import static org.mockito.Mockito.verify;
|
|
39
|
-
import static org.mockito.Mockito.withSettings;
|
|
40
|
-
|
|
41
|
-
public class ViewControllerTest extends BaseTest {
|
|
42
|
-
|
|
43
|
-
private ViewController uut;
|
|
44
|
-
private Activity activity;
|
|
45
|
-
private ChildControllersRegistry childRegistry;
|
|
46
|
-
private YellowBoxDelegate yellowBoxDelegate;
|
|
47
|
-
|
|
48
|
-
@Override
|
|
49
|
-
public void beforeEach() {
|
|
50
|
-
super.beforeEach();
|
|
51
|
-
yellowBoxDelegate = Mockito.mock(YellowBoxDelegate.class);
|
|
52
|
-
activity = newActivity();
|
|
53
|
-
childRegistry = new ChildControllersRegistry();
|
|
54
|
-
uut = new SimpleViewController(activity, childRegistry, "uut", new Options());
|
|
55
|
-
final ParentController<?> parent = mock(ParentController.class);
|
|
56
|
-
uut.setParentController(parent);
|
|
57
|
-
Mockito.when(parent.resolveChildOptions(any())).thenReturn(Options.EMPTY);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@Test
|
|
61
|
-
public void holdsAView() {
|
|
62
|
-
assertThat(uut.getView()).isNotNull().isInstanceOf(View.class);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@Test
|
|
66
|
-
public void holdsARefToActivity() {
|
|
67
|
-
assertThat(uut.getActivity()).isNotNull().isEqualTo(activity);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@Test
|
|
71
|
-
public void canOverrideViewCreation() {
|
|
72
|
-
final FrameLayout otherView = new FrameLayout(activity);
|
|
73
|
-
yellowBoxDelegate = spy(new YellowBoxDelegate(activity));
|
|
74
|
-
ViewController myController = new ViewController(activity, "vc", yellowBoxDelegate, new Options(), new ViewControllerOverlay(activity)) {
|
|
75
|
-
@Override
|
|
76
|
-
public FrameLayout createView() {
|
|
77
|
-
return otherView;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@Override
|
|
81
|
-
public void sendOnNavigationButtonPressed(String buttonId) {
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
@Override
|
|
86
|
-
public String getCurrentComponentName() { return null; }
|
|
87
|
-
};
|
|
88
|
-
assertThat(myController.getView()).isEqualTo(otherView);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@SuppressWarnings("ConstantConditions")
|
|
92
|
-
@Test
|
|
93
|
-
public void holdsAReferenceToStackControllerOrNull() {
|
|
94
|
-
uut.setParentController(null);
|
|
95
|
-
|
|
96
|
-
assertThat(uut.getParentController()).isNull();
|
|
97
|
-
StackController nav = TestUtils.newStackController(activity).build();
|
|
98
|
-
nav.ensureViewIsCreated();
|
|
99
|
-
nav.push(uut, new CommandListenerAdapter());
|
|
100
|
-
assertThat(uut.getParentController()).isEqualTo(nav);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@Test
|
|
104
|
-
public void handleBackDefaultFalse() {
|
|
105
|
-
assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@Test
|
|
109
|
-
public void holdsId() {
|
|
110
|
-
assertThat(uut.getId()).isEqualTo("uut");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
@Test
|
|
114
|
-
public void isSameId() {
|
|
115
|
-
assertThat(uut.isSameId("")).isFalse();
|
|
116
|
-
assertThat(uut.isSameId(null)).isFalse();
|
|
117
|
-
assertThat(uut.isSameId("uut")).isTrue();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@Test
|
|
121
|
-
public void findControllerById_SelfOrNull() {
|
|
122
|
-
assertThat(uut.findController("456")).isNull();
|
|
123
|
-
assertThat(uut.findController("uut")).isEqualTo(uut);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
@Test
|
|
127
|
-
public void runOnPreDraw() {
|
|
128
|
-
Functions.Func1<View> task = Mockito.mock(Functions.Func1.class);
|
|
129
|
-
uut.runOnPreDraw(task);
|
|
130
|
-
dispatchPreDraw(uut.getView());
|
|
131
|
-
verify(task).run(uut.getView());
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
@Test
|
|
135
|
-
public void runOnPreDraw_doesNotInvokeTaskIfControllerIsDestroyed() {
|
|
136
|
-
Functions.Func1<View> task = Mockito.mock(Functions.Func1.class);
|
|
137
|
-
uut.runOnPreDraw(task);
|
|
138
|
-
View view = uut.getView();
|
|
139
|
-
uut.destroy();
|
|
140
|
-
dispatchPreDraw(view);
|
|
141
|
-
verify(task, times(1)).run(view);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@Test
|
|
145
|
-
public void onChildViewAdded_delegatesToYellowBoxDelegate() {
|
|
146
|
-
View child = new View(activity);
|
|
147
|
-
ViewGroup view = new FrameLayout(activity);
|
|
148
|
-
ViewController vc = new ViewController(activity, "", yellowBoxDelegate, new Options(), new ViewControllerOverlay(activity)) {
|
|
149
|
-
@Override
|
|
150
|
-
public ViewGroup createView() {
|
|
151
|
-
return view;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
@Override
|
|
155
|
-
public void sendOnNavigationButtonPressed(String buttonId) {
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@Override
|
|
160
|
-
public String getCurrentComponentName() { return null; }
|
|
161
|
-
};
|
|
162
|
-
vc.onChildViewAdded(view, child);
|
|
163
|
-
verify(yellowBoxDelegate).onChildViewAdded(view, child);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
@Test
|
|
167
|
-
public void onAppear_WhenShown() {
|
|
168
|
-
ViewController spy = spy(uut);
|
|
169
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
170
|
-
Assertions.assertThat(spy.getView()).isNotShown();
|
|
171
|
-
verify(spy, times(0)).onViewWillAppear();
|
|
172
|
-
|
|
173
|
-
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
|
174
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
175
|
-
Assertions.assertThat(spy.getView()).isShown();
|
|
176
|
-
|
|
177
|
-
verify(spy, times(1)).onViewWillAppear();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
@Test
|
|
181
|
-
public void onAppear_CalledAtMostOnce() {
|
|
182
|
-
ViewController spy = spy(uut);
|
|
183
|
-
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
|
184
|
-
Assertions.assertThat(spy.getView()).isShown();
|
|
185
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
186
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
187
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
188
|
-
|
|
189
|
-
verify(spy, times(1)).onViewWillAppear();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
@Test
|
|
193
|
-
public void isViewShown_doesNotCreateView() {
|
|
194
|
-
assertThat(uut.isViewShown()).isFalse();
|
|
195
|
-
assertThat(uut.view).isNull();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@Test
|
|
199
|
-
public void onDisappear_WhenNotShown_AfterOnAppearWasCalled() {
|
|
200
|
-
ViewController spy = spy(uut);
|
|
201
|
-
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
|
202
|
-
Assertions.assertThat(spy.getView()).isShown();
|
|
203
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
204
|
-
verify(spy, times(1)).onViewWillAppear();
|
|
205
|
-
verify(spy, times(0)).onViewDisappear();
|
|
206
|
-
|
|
207
|
-
spy.getView().setVisibility(View.GONE);
|
|
208
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
209
|
-
Assertions.assertThat(spy.getView()).isNotShown();
|
|
210
|
-
verify(spy, times(1)).onViewDisappear();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
@Test
|
|
214
|
-
public void onDisappear_CalledAtMostOnce() {
|
|
215
|
-
ViewController spy = spy(uut);
|
|
216
|
-
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
|
217
|
-
Assertions.assertThat(spy.getView()).isShown();
|
|
218
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
219
|
-
spy.getView().setVisibility(View.GONE);
|
|
220
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
221
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
222
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
223
|
-
verify(spy, times(1)).onViewDisappear();
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
@Test
|
|
227
|
-
public void onDestroy_RemovesGlobalLayoutListener() throws Exception {
|
|
228
|
-
new SimpleViewController(activity, childRegistry, "ensureNotNull", new Options()).destroy();
|
|
229
|
-
|
|
230
|
-
ViewController spy = spy(uut);
|
|
231
|
-
View view = spy.getView();
|
|
232
|
-
Shadows.shadowOf(view).setMyParent(mock(ViewParent.class));
|
|
233
|
-
|
|
234
|
-
spy.destroy();
|
|
235
|
-
|
|
236
|
-
Assertions.assertThat(view).isShown();
|
|
237
|
-
view.getViewTreeObserver().dispatchOnGlobalLayout();
|
|
238
|
-
verify(spy, times(0)).onViewWillAppear();
|
|
239
|
-
verify(spy, times(0)).onViewDisappear();
|
|
240
|
-
|
|
241
|
-
Field field = ViewController.class.getDeclaredField("view");
|
|
242
|
-
field.setAccessible(true);
|
|
243
|
-
assertThat(field.get(spy)).isNull();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
@Test
|
|
247
|
-
public void onDestroy_CallsOnDisappearIfNeeded() {
|
|
248
|
-
ViewController spy = spy(uut);
|
|
249
|
-
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
|
250
|
-
Assertions.assertThat(spy.getView()).isShown();
|
|
251
|
-
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
252
|
-
verify(spy, times(1)).onViewWillAppear();
|
|
253
|
-
|
|
254
|
-
spy.destroy();
|
|
255
|
-
|
|
256
|
-
verify(spy, times(1)).onViewDisappear();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
@Test
|
|
260
|
-
public void onDestroy_destroysViewEvenIfHidden() {
|
|
261
|
-
final SimpleViewController.SimpleView[] spy = new SimpleViewController.SimpleView[1];
|
|
262
|
-
ViewController uut = new SimpleViewController(activity, childRegistry, "uut", new Options()) {
|
|
263
|
-
@Override
|
|
264
|
-
public SimpleView createView() {
|
|
265
|
-
SimpleView view = spy(super.createView());
|
|
266
|
-
spy[0] = view;
|
|
267
|
-
return view;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
assertThat(uut.isViewShown()).isFalse();
|
|
271
|
-
uut.destroy();
|
|
272
|
-
verify(spy[0], times(1)).destroy();
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
@Test
|
|
276
|
-
public void onDestroy_RemovesSelfFromParentIfExists() {
|
|
277
|
-
LinearLayout parent = new LinearLayout(activity);
|
|
278
|
-
parent.addView(uut.getView());
|
|
279
|
-
|
|
280
|
-
uut.destroy();
|
|
281
|
-
assertThat(parent.getChildCount()).withFailMessage("expected not to have children").isZero();
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
@Test
|
|
285
|
-
public void onDestroy_shouldKeepViewIdsStable() {
|
|
286
|
-
LinearLayout parent = new LinearLayout(activity);
|
|
287
|
-
ViewGroup view = uut.getView();
|
|
288
|
-
view.setId(10);
|
|
289
|
-
parent.addView(view);
|
|
290
|
-
|
|
291
|
-
uut.destroy();
|
|
292
|
-
assertThat(view.getId()).isEqualTo(10);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
@Test
|
|
296
|
-
public void ensureViewIsCreated() {
|
|
297
|
-
ViewController spy = spy(uut);
|
|
298
|
-
verify(spy, times(0)).getView();
|
|
299
|
-
spy.ensureViewIsCreated();
|
|
300
|
-
verify(spy, times(1)).getView();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
@Test
|
|
304
|
-
public void isRendered_falseIfViewIsNotCreated() {
|
|
305
|
-
uut.setWaitForRender(new Bool(true));
|
|
306
|
-
assertThat(uut.isRendered()).isFalse();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
@Test
|
|
310
|
-
public void isRendered_delegatesToView() {
|
|
311
|
-
uut.setWaitForRender(new Bool(true));
|
|
312
|
-
uut.view = mock(ViewGroup.class, withSettings().extraInterfaces(Component.class));
|
|
313
|
-
uut.isRendered();
|
|
314
|
-
verify((Component) uut.view).isRendered();
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
@Test
|
|
318
|
-
public void isRendered_returnsTrueForEveryViewByDefault() {
|
|
319
|
-
uut.setWaitForRender(new NullBool());
|
|
320
|
-
uut.view = mock(ViewGroup.class);
|
|
321
|
-
assertThat(uut.isRendered()).isTrue();
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
@Test
|
|
325
|
-
public void getTopInset_noParent() {
|
|
326
|
-
uut.setParentController(null);
|
|
327
|
-
assertThat(uut.getTopInset()).isEqualTo(63);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
@Test
|
|
331
|
-
public void onMeasureChild() {
|
|
332
|
-
ViewController spy = spy(uut);
|
|
333
|
-
spy.onMeasureChild(mock(CoordinatorLayout.class), spy.getView(), -1, -1, -1, -1);
|
|
334
|
-
verify(spy).applyTopInset();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
package com.reactnativenavigation.viewcontrollers.viewcontroller;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.view.View;
|
|
5
|
-
import android.view.ViewGroup;
|
|
6
|
-
import android.widget.FrameLayout;
|
|
7
|
-
|
|
8
|
-
import com.reactnativenavigation.BaseTest;
|
|
9
|
-
|
|
10
|
-
import org.junit.Test;
|
|
11
|
-
import org.mockito.Mockito;
|
|
12
|
-
|
|
13
|
-
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
14
|
-
import static org.mockito.Mockito.verify;
|
|
15
|
-
|
|
16
|
-
public class YellowBoxDelegateTest extends BaseTest {
|
|
17
|
-
private YellowBoxDelegate uut;
|
|
18
|
-
private YellowBoxHelper yellowBoxHelper;
|
|
19
|
-
private View yellowBox;
|
|
20
|
-
private ViewGroup parent;
|
|
21
|
-
|
|
22
|
-
@Override
|
|
23
|
-
public void beforeEach() {
|
|
24
|
-
Activity context = newActivity();
|
|
25
|
-
yellowBox = new View(context);
|
|
26
|
-
parent = new FrameLayout(context);
|
|
27
|
-
yellowBoxHelper = Mockito.mock(YellowBoxHelper.class);
|
|
28
|
-
uut = new YellowBoxDelegate(context, yellowBoxHelper);
|
|
29
|
-
parent.addView(new View(context)); // We assume view at index 0 is not a yellow box
|
|
30
|
-
parent.addView(yellowBox);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@Test
|
|
34
|
-
public void onYellowBoxAdded_removedFromParent() {
|
|
35
|
-
uut.onYellowBoxAdded(parent);
|
|
36
|
-
assertThat(yellowBox.getParent()).isNull();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@Test
|
|
40
|
-
public void onYellowBoxAdded_storesRefToYellowBoxAndParent() {
|
|
41
|
-
uut.onYellowBoxAdded(parent);
|
|
42
|
-
assertThat(uut.getYellowBoxes()).contains(yellowBox);
|
|
43
|
-
assertThat(uut.getParent()).isEqualTo(parent);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@Test
|
|
47
|
-
public void onReactViewDestroy_yellowBoxIsAddedBackToParent() {
|
|
48
|
-
uut.onYellowBoxAdded(parent);
|
|
49
|
-
uut.destroy();
|
|
50
|
-
assertThat(yellowBox.getParent()).isEqualTo(parent);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@Test
|
|
54
|
-
public void onChildViewAdded() {
|
|
55
|
-
uut.onChildViewAdded(parent, yellowBox);
|
|
56
|
-
dispatchPreDraw(yellowBox);
|
|
57
|
-
verify(yellowBoxHelper).isYellowBox(parent, yellowBox);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@Test
|
|
61
|
-
public void onYellowBoxAdded_notHandledIfDelegateIsDestroyed() {
|
|
62
|
-
uut.onYellowBoxAdded(parent);
|
|
63
|
-
uut.destroy();
|
|
64
|
-
|
|
65
|
-
uut.onYellowBoxAdded(parent);
|
|
66
|
-
assertThat(yellowBox.getParent()).isEqualTo(parent);
|
|
67
|
-
}
|
|
68
|
-
}
|