|
@@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
|
5
|
5
|
import android.view.ViewGroup;
|
6
|
6
|
|
7
|
7
|
import com.reactnativenavigation.BaseTest;
|
|
8
|
+import com.reactnativenavigation.mocks.MockPromise;
|
8
|
9
|
import com.reactnativenavigation.mocks.TestComponentViewCreator;
|
9
|
10
|
import com.reactnativenavigation.mocks.TestReactView;
|
10
|
11
|
import com.reactnativenavigation.parse.Options;
|
|
@@ -15,13 +16,14 @@ import com.reactnativenavigation.views.ReactComponent;
|
15
|
16
|
import com.reactnativenavigation.views.TopTabsLayoutCreator;
|
16
|
17
|
import com.reactnativenavigation.views.TopTabsViewPager;
|
17
|
18
|
|
18
|
|
-import org.assertj.core.api.Assertions;
|
19
|
19
|
import org.junit.Test;
|
|
20
|
+import org.mockito.ArgumentCaptor;
|
20
|
21
|
import org.mockito.Mockito;
|
21
|
22
|
|
22
|
23
|
import java.util.ArrayList;
|
23
|
24
|
import java.util.List;
|
24
|
25
|
|
|
26
|
+import static org.assertj.core.api.Assertions.assertThat;
|
25
|
27
|
import static org.mockito.ArgumentMatchers.any;
|
26
|
28
|
import static org.mockito.ArgumentMatchers.eq;
|
27
|
29
|
import static org.mockito.Mockito.spy;
|
|
@@ -38,14 +40,15 @@ public class TopTabsViewControllerTest extends BaseTest {
|
38
|
40
|
private List<Options> tabOptions = new ArrayList<>(SIZE);
|
39
|
41
|
private final Options options = new Options();
|
40
|
42
|
private TopTabsViewPager topTabsLayout;
|
|
43
|
+ private Activity activity;
|
41
|
44
|
|
42
|
45
|
@Override
|
43
|
46
|
public void beforeEach() {
|
44
|
47
|
super.beforeEach();
|
45
|
48
|
|
46
|
|
- final Activity activity = newActivity();
|
|
49
|
+ activity = newActivity();
|
47
|
50
|
tabOptions = createOptions();
|
48
|
|
- tabControllers = createTabsControllers(activity);
|
|
51
|
+ tabControllers = createTabsControllers(activity, tabOptions);
|
49
|
52
|
|
50
|
53
|
topTabsLayout = spy(new TopTabsViewPager(activity, tabControllers, new TopTabsAdapter(tabControllers)));
|
51
|
54
|
TopTabsLayoutCreator layoutCreator = Mockito.mock(TopTabsLayoutCreator.class);
|
|
@@ -54,6 +57,7 @@ public class TopTabsViewControllerTest extends BaseTest {
|
54
|
57
|
tabControllers.forEach(viewController -> viewController.setParentController(uut));
|
55
|
58
|
|
56
|
59
|
parentController = spy(new StackController(activity, "stackId", new Options()));
|
|
60
|
+ parentController.push(uut, new MockPromise());
|
57
|
61
|
uut.setParentController(parentController);
|
58
|
62
|
}
|
59
|
63
|
|
|
@@ -69,7 +73,7 @@ public class TopTabsViewControllerTest extends BaseTest {
|
69
|
73
|
return result;
|
70
|
74
|
}
|
71
|
75
|
|
72
|
|
- private List<ViewController> createTabsControllers(Activity activity) {
|
|
76
|
+ private List<ViewController> createTabsControllers(Activity activity, List<Options> tabOptions) {
|
73
|
77
|
List<ViewController> tabControllers = new ArrayList<>(SIZE);
|
74
|
78
|
for (int i = 0; i < SIZE; i++) {
|
75
|
79
|
ComponentViewController viewController = new ComponentViewController(
|
|
@@ -165,17 +169,17 @@ public class TopTabsViewControllerTest extends BaseTest {
|
165
|
169
|
uut.onViewAppeared();
|
166
|
170
|
ReactComponent currentTab = tabView(0);
|
167
|
171
|
verify(uut, times(1)).applyOptions(any(Options.class), eq(currentTab));
|
168
|
|
- Assertions.assertThat(uut.options.topBarOptions.title.get()).isEqualTo(createTabTopBarTitle(0));
|
|
172
|
+ assertThat(uut.options.topBarOptions.title.get()).isEqualTo(createTabTopBarTitle(0));
|
169
|
173
|
|
170
|
174
|
uut.switchToTab(1);
|
171
|
175
|
currentTab = tabView(1);
|
172
|
176
|
verify(uut, times(1)).applyOptions(any(Options.class), eq(currentTab));
|
173
|
|
- Assertions.assertThat(uut.options.topBarOptions.title.get()).isEqualTo(createTabTopBarTitle(1));
|
|
177
|
+ assertThat(uut.options.topBarOptions.title.get()).isEqualTo(createTabTopBarTitle(1));
|
174
|
178
|
|
175
|
179
|
uut.switchToTab(0);
|
176
|
180
|
currentTab = tabView(0);
|
177
|
181
|
verify(uut, times(2)).applyOptions(any(Options.class), eq(currentTab));
|
178
|
|
- Assertions.assertThat(uut.options.topBarOptions.title.get()).isEqualTo(createTabTopBarTitle(0));
|
|
182
|
+ assertThat(uut.options.topBarOptions.title.get()).isEqualTo(createTabTopBarTitle(0));
|
179
|
183
|
}
|
180
|
184
|
|
181
|
185
|
private TestReactView getActualTabView(int index) {
|
|
@@ -193,6 +197,16 @@ public class TopTabsViewControllerTest extends BaseTest {
|
193
|
197
|
verify(topTabsLayout, times(1)).applyOptions(any(Options.class));
|
194
|
198
|
}
|
195
|
199
|
|
|
200
|
+ @Test
|
|
201
|
+ public void applyOptions_applyOnlyOnFirstTopTabs() throws Exception {
|
|
202
|
+ tabOptions.get(0).topTabOptions.title = new Text("tab title");
|
|
203
|
+ tabControllers.get(0).onViewAppeared();
|
|
204
|
+ ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);
|
|
205
|
+ ArgumentCaptor<ReactComponent> viewCaptor = ArgumentCaptor.forClass(ReactComponent.class);
|
|
206
|
+ verify(parentController, times(1)).applyOptions(optionsCaptor.capture(), viewCaptor.capture());
|
|
207
|
+ assertThat(optionsCaptor.getValue().topTabOptions.title.hasValue()).isFalse();
|
|
208
|
+ }
|
|
209
|
+
|
196
|
210
|
private IReactView tab(TopTabsViewPager topTabs, final int index) {
|
197
|
211
|
return (IReactView) ((ViewGroup) topTabs.getChildAt(index)).getChildAt(0);
|
198
|
212
|
}
|