|
@@ -31,7 +31,6 @@ import org.mockito.ArgumentCaptor;
|
31
|
31
|
import org.mockito.Mockito;
|
32
|
32
|
|
33
|
33
|
import java.util.Arrays;
|
34
|
|
-import java.util.Collections;
|
35
|
34
|
import java.util.List;
|
36
|
35
|
|
37
|
36
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
@@ -61,20 +60,23 @@ public class BottomTabsControllerTest extends BaseTest {
|
61
|
60
|
activity = newActivity();
|
62
|
61
|
childRegistry = new ChildControllersRegistry();
|
63
|
62
|
eventEmitter = Mockito.mock(EventEmitter.class);
|
64
|
|
- uut = spy(new BottomTabsController(activity, childRegistry, eventEmitter, imageLoaderMock, "uut", new Options()) {
|
65
|
|
- @Override
|
66
|
|
- public void ensureViewIsCreated() {
|
67
|
|
- super.ensureViewIsCreated();
|
68
|
|
- uut.getView().layout(0, 0, 1000, 1000);
|
69
|
|
- uut.getBottomTabs().layout(0, 0, 1000, 100);
|
70
|
|
- }
|
71
|
|
- });
|
|
63
|
+
|
72
|
64
|
child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
|
73
|
65
|
child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
|
74
|
66
|
child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
|
75
|
67
|
child4 = spy(new SimpleViewController(activity, childRegistry, "child4", tabOptions));
|
76
|
68
|
child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
|
|
69
|
+ when(child5.handleBack(any())).thenReturn(true);
|
77
|
70
|
tabs = createTabs();
|
|
71
|
+
|
|
72
|
+ uut = new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "uut", new Options()) {
|
|
73
|
+ @Override
|
|
74
|
+ public void ensureViewIsCreated() {
|
|
75
|
+ super.ensureViewIsCreated();
|
|
76
|
+ uut.getView().layout(0, 0, 1000, 1000);
|
|
77
|
+ uut.getBottomTabs().layout(0, 0, 1000, 100);
|
|
78
|
+ }
|
|
79
|
+ };
|
78
|
80
|
}
|
79
|
81
|
|
80
|
82
|
@Test
|
|
@@ -85,15 +87,19 @@ public class BottomTabsControllerTest extends BaseTest {
|
85
|
87
|
|
86
|
88
|
@Test(expected = RuntimeException.class)
|
87
|
89
|
public void setTabs_ThrowWhenMoreThan5() {
|
88
|
|
- List<ViewController> tabs = createTabs();
|
89
|
90
|
tabs.add(new SimpleViewController(activity, childRegistry, "6", tabOptions));
|
90
|
|
- uut.setTabs(tabs);
|
|
91
|
+ new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "uut", new Options()) {
|
|
92
|
+ @Override
|
|
93
|
+ public void ensureViewIsCreated() {
|
|
94
|
+ super.ensureViewIsCreated();
|
|
95
|
+ uut.getView().layout(0, 0, 1000, 1000);
|
|
96
|
+ uut.getBottomTabs().layout(0, 0, 1000, 100);
|
|
97
|
+ }
|
|
98
|
+ };
|
91
|
99
|
}
|
92
|
100
|
|
93
|
101
|
@Test
|
94
|
102
|
public void setTab_controllerIsSetAsParent() {
|
95
|
|
- List<ViewController> tabs = createTabs();
|
96
|
|
- uut.setTabs(tabs);
|
97
|
103
|
for (ViewController tab : tabs) {
|
98
|
104
|
assertThat(tab.getParentController()).isEqualTo(uut);
|
99
|
105
|
}
|
|
@@ -101,8 +107,6 @@ public class BottomTabsControllerTest extends BaseTest {
|
101
|
107
|
|
102
|
108
|
@Test
|
103
|
109
|
public void setTabs_AddAllViews() {
|
104
|
|
- List<ViewController> tabs = createTabs();
|
105
|
|
- uut.setTabs(tabs);
|
106
|
110
|
uut.onViewAppeared();
|
107
|
111
|
assertThat(uut.getView().getChildCount()).isEqualTo(2);
|
108
|
112
|
assertThat(((ViewController) ((List) uut.getChildControllers()).get(0)).getView().getParent()).isNotNull();
|
|
@@ -110,7 +114,6 @@ public class BottomTabsControllerTest extends BaseTest {
|
110
|
114
|
|
111
|
115
|
@Test
|
112
|
116
|
public void onTabSelected() {
|
113
|
|
- uut.setTabs(createTabs());
|
114
|
117
|
assertThat(uut.getSelectedIndex()).isZero();
|
115
|
118
|
|
116
|
119
|
uut.onTabSelected(3, false);
|
|
@@ -122,7 +125,6 @@ public class BottomTabsControllerTest extends BaseTest {
|
122
|
125
|
|
123
|
126
|
@Test
|
124
|
127
|
public void onTabReSelected() {
|
125
|
|
- uut.setTabs(createTabs());
|
126
|
128
|
assertThat(uut.getSelectedIndex()).isZero();
|
127
|
129
|
|
128
|
130
|
uut.onTabSelected(0, false);
|
|
@@ -132,39 +134,19 @@ public class BottomTabsControllerTest extends BaseTest {
|
132
|
134
|
verify(eventEmitter, times(1)).emitBottomTabSelected(0, 0);
|
133
|
135
|
}
|
134
|
136
|
|
135
|
|
- @Test
|
136
|
|
- public void findControllerById_ReturnsSelfOrChildren() {
|
137
|
|
- assertThat(uut.findControllerById("123")).isNull();
|
138
|
|
- assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
|
139
|
|
- StackController inner = createStack("inner");
|
140
|
|
- inner.push(child1, new CommandListenerAdapter());
|
141
|
|
- assertThat(uut.findControllerById(child1.getId())).isNull();
|
142
|
|
- uut.setTabs(Collections.singletonList(inner));
|
143
|
|
- assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
|
144
|
|
- }
|
145
|
|
-
|
146
|
137
|
@Test
|
147
|
138
|
public void handleBack_DelegatesToSelectedChild() {
|
148
|
139
|
assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
|
149
|
|
-
|
150
|
|
- List<ViewController> tabs = createTabs();
|
151
|
|
- ViewController spy = spy(tabs.get(2));
|
152
|
|
- tabs.set(2, spy);
|
153
|
|
- when(spy.handleBack(any())).thenReturn(true);
|
154
|
|
- uut.setTabs(tabs);
|
155
|
|
-
|
156
|
|
- assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
|
157
|
|
- uut.selectTab(2);
|
|
140
|
+ uut.selectTab(4);
|
158
|
141
|
assertThat(uut.handleBack(new CommandListenerAdapter())).isTrue();
|
159
|
|
-
|
160
|
|
- verify(spy, times(1)).handleBack(any());
|
|
142
|
+ verify(child5, times(1)).handleBack(any());
|
161
|
143
|
}
|
162
|
144
|
|
163
|
145
|
@Test
|
164
|
146
|
public void applyOptions_bottomTabsOptionsAreClearedAfterApply() {
|
165
|
|
- List<ViewController> tabs = createTabs();
|
166
|
|
- child1.options.bottomTabsOptions.tabColor = new Color(android.graphics.Color.RED);
|
167
|
|
- uut.setTabs(tabs);
|
|
147
|
+ Options options = new Options();
|
|
148
|
+ options.bottomTabsOptions.tabColor = new Color(android.graphics.Color.RED);
|
|
149
|
+ child1.mergeOptions(options);
|
168
|
150
|
uut.ensureViewIsCreated();
|
169
|
151
|
|
170
|
152
|
StackController stack = spy(createStack("stack"));
|
|
@@ -181,20 +163,18 @@ public class BottomTabsControllerTest extends BaseTest {
|
181
|
163
|
|
182
|
164
|
@Test
|
183
|
165
|
public void mergeOptions_currentTabIndex() {
|
184
|
|
- uut.setTabs(tabs);
|
185
|
166
|
uut.ensureViewIsCreated();
|
|
167
|
+ assertThat(uut.getSelectedIndex()).isZero();
|
186
|
168
|
|
187
|
169
|
Options options = new Options();
|
188
|
170
|
options.bottomTabsOptions.currentTabIndex = new Number(1);
|
189
|
171
|
uut.mergeOptions(options);
|
190
|
|
- verify(uut, times(1)).selectTab(1);
|
|
172
|
+ assertThat(uut.getSelectedIndex()).isOne();
|
191
|
173
|
verify(eventEmitter, times(0)).emitBottomTabSelected(any(Integer.class), any(Integer.class));
|
192
|
174
|
}
|
193
|
175
|
|
194
|
176
|
@Test
|
195
|
177
|
public void mergeOptions_drawBehind() {
|
196
|
|
- List<ViewController> tabs = createTabs();
|
197
|
|
- uut.setTabs(tabs);
|
198
|
178
|
uut.ensureViewIsCreated();
|
199
|
179
|
child1.onViewAppeared();
|
200
|
180
|
uut.selectTab(0);
|
|
@@ -214,8 +194,6 @@ public class BottomTabsControllerTest extends BaseTest {
|
214
|
194
|
|
215
|
195
|
@Test
|
216
|
196
|
public void child_mergeOptions_currentTabIndex() {
|
217
|
|
- List<ViewController> tabs = createTabs();
|
218
|
|
- uut.setTabs(tabs);
|
219
|
197
|
uut.ensureViewIsCreated();
|
220
|
198
|
|
221
|
199
|
assertThat(uut.getSelectedIndex()).isZero();
|
|
@@ -229,12 +207,11 @@ public class BottomTabsControllerTest extends BaseTest {
|
229
|
207
|
|
230
|
208
|
@Test
|
231
|
209
|
public void buttonPressInvokedOnCurrentTab() {
|
232
|
|
- uut.setTabs(createTabs());
|
233
|
210
|
uut.ensureViewIsCreated();
|
234
|
|
- uut.selectTab(1);
|
|
211
|
+ uut.selectTab(4);
|
235
|
212
|
|
236
|
213
|
uut.sendOnNavigationButtonPressed("btn1");
|
237
|
|
- verify(child2, times(1)).sendOnNavigationButtonPressed("btn1");
|
|
214
|
+ verify(child5, times(1)).sendOnNavigationButtonPressed("btn1");
|
238
|
215
|
}
|
239
|
216
|
|
240
|
217
|
@NonNull
|