|
@@ -12,6 +12,7 @@ import com.reactnativenavigation.parse.OrientationOptions;
|
12
|
12
|
import com.reactnativenavigation.parse.SubtitleOptions;
|
13
|
13
|
import com.reactnativenavigation.parse.TitleOptions;
|
14
|
14
|
import com.reactnativenavigation.parse.params.Bool;
|
|
15
|
+import com.reactnativenavigation.parse.params.Button;
|
15
|
16
|
import com.reactnativenavigation.parse.params.Color;
|
16
|
17
|
import com.reactnativenavigation.parse.params.Fraction;
|
17
|
18
|
import com.reactnativenavigation.parse.params.Number;
|
|
@@ -22,10 +23,13 @@ import com.reactnativenavigation.views.topbar.TopBar;
|
22
|
23
|
|
23
|
24
|
import org.json.JSONObject;
|
24
|
25
|
import org.junit.Test;
|
|
26
|
+import org.mockito.ArgumentCaptor;
|
25
|
27
|
import org.mockito.Mockito;
|
26
|
28
|
|
27
|
29
|
import java.util.ArrayList;
|
|
30
|
+import java.util.List;
|
28
|
31
|
|
|
32
|
+import static org.assertj.core.api.Java6Assertions.assertThat;
|
29
|
33
|
import static org.mockito.ArgumentMatchers.any;
|
30
|
34
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
31
|
35
|
import static org.mockito.ArgumentMatchers.anyDouble;
|
|
@@ -38,6 +42,7 @@ import static org.mockito.Mockito.when;
|
38
|
42
|
|
39
|
43
|
public class StackOptionsPresenterTest extends BaseTest {
|
40
|
44
|
|
|
45
|
+ private static final Options EMPTY_OPTIONS = new Options();
|
41
|
46
|
private StackOptionsPresenter uut;
|
42
|
47
|
private TestComponentLayout child;
|
43
|
48
|
private Activity activity;
|
|
@@ -55,35 +60,35 @@ public class StackOptionsPresenterTest extends BaseTest {
|
55
|
60
|
@Test
|
56
|
61
|
public void mergeOrientation() throws Exception {
|
57
|
62
|
Options options = new Options();
|
58
|
|
- uut.mergeChildOptions(options, child);
|
|
63
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
59
|
64
|
verify(uut, times(0)).applyOrientation(any());
|
60
|
65
|
|
61
|
66
|
JSONObject orientation = new JSONObject().put("orientation", "landscape");
|
62
|
67
|
options.layout.orientation = OrientationOptions.parse(orientation);
|
63
|
|
- uut.mergeChildOptions(options, child);
|
|
68
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
64
|
69
|
verify(uut, times(1)).applyOrientation(options.layout.orientation);
|
65
|
70
|
}
|
66
|
71
|
|
67
|
72
|
@Test
|
68
|
73
|
public void mergeButtons() {
|
69
|
74
|
Options options = new Options();
|
70
|
|
- uut.mergeChildOptions(options, child);
|
|
75
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
71
|
76
|
verify(topBar, times(0)).setRightButtons(any());
|
72
|
77
|
verify(topBar, times(0)).setLeftButtons(any());
|
73
|
78
|
|
74
|
79
|
options.topBar.buttons.right = new ArrayList<>();
|
75
|
|
- uut.mergeChildOptions(options, child);
|
|
80
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
76
|
81
|
verify(topBar, times(1)).setRightButtons(any());
|
77
|
82
|
|
78
|
83
|
options.topBar.buttons.left = new ArrayList<>();
|
79
|
|
- uut.mergeChildOptions(options, child);
|
|
84
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
80
|
85
|
verify(topBar, times(1)).setLeftButtons(any());
|
81
|
86
|
}
|
82
|
87
|
|
83
|
88
|
@Test
|
84
|
89
|
public void mergeTopBarOptions() {
|
85
|
90
|
Options options = new Options();
|
86
|
|
- uut.mergeChildOptions(options, child);
|
|
91
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
87
|
92
|
assertTopBarOptions(options, 0);
|
88
|
93
|
|
89
|
94
|
TitleOptions title = new TitleOptions();
|
|
@@ -105,19 +110,20 @@ public class StackOptionsPresenterTest extends BaseTest {
|
105
|
110
|
options.topBar.drawBehind = new Bool(false);
|
106
|
111
|
options.topBar.hideOnScroll = new Bool(false);
|
107
|
112
|
options.topBar.validate();
|
108
|
|
- uut.mergeChildOptions(options, child);
|
|
113
|
+
|
|
114
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
109
|
115
|
|
110
|
116
|
assertTopBarOptions(options, 1);
|
111
|
117
|
|
112
|
118
|
options.topBar.drawBehind = new Bool(true);
|
113
|
|
- uut.mergeChildOptions(options, child);
|
|
119
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
114
|
120
|
verify(child, times(1)).drawBehindTopBar();
|
115
|
121
|
}
|
116
|
122
|
|
117
|
123
|
@Test
|
118
|
124
|
public void mergeTopTabsOptions() {
|
119
|
125
|
Options options = new Options();
|
120
|
|
- uut.mergeChildOptions(options, child);
|
|
126
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
121
|
127
|
verify(topBar, times(0)).applyTopTabsColors(any(), any());
|
122
|
128
|
verify(topBar, times(0)).applyTopTabsFontSize(any());
|
123
|
129
|
verify(topBar, times(0)).setTopTabsVisible(anyBoolean());
|
|
@@ -126,7 +132,7 @@ public class StackOptionsPresenterTest extends BaseTest {
|
126
|
132
|
options.topTabs.unselectedTabColor = new Color(1);
|
127
|
133
|
options.topTabs.fontSize = new Number(1);
|
128
|
134
|
options.topTabs.visible = new Bool(true);
|
129
|
|
- uut.mergeChildOptions(options, child);
|
|
135
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
130
|
136
|
verify(topBar, times(1)).applyTopTabsColors(options.topTabs.selectedTabColor, options.topTabs.unselectedTabColor);
|
131
|
137
|
verify(topBar, times(1)).applyTopTabsFontSize(options.topTabs.fontSize);
|
132
|
138
|
verify(topBar, times(1)).setTopTabsVisible(anyBoolean());
|
|
@@ -135,13 +141,13 @@ public class StackOptionsPresenterTest extends BaseTest {
|
135
|
141
|
@Test
|
136
|
142
|
public void mergeTopTabOptions() {
|
137
|
143
|
Options options = new Options();
|
138
|
|
- uut.mergeChildOptions(options, child);
|
|
144
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
139
|
145
|
|
140
|
146
|
verify(topBar, times(0)).setTopTabFontFamily(anyInt(), any());
|
141
|
147
|
|
142
|
148
|
options.topTabOptions.tabIndex = 1;
|
143
|
149
|
options.topTabOptions.fontFamily = Typeface.DEFAULT_BOLD;
|
144
|
|
- uut.mergeChildOptions(options, child);
|
|
150
|
+ uut.mergeChildOptions(options, EMPTY_OPTIONS, child);
|
145
|
151
|
|
146
|
152
|
verify(topBar, times(1)).setTopTabFontFamily(1, Typeface.DEFAULT_BOLD);
|
147
|
153
|
}
|
|
@@ -165,11 +171,105 @@ public class StackOptionsPresenterTest extends BaseTest {
|
165
|
171
|
|
166
|
172
|
Options childOptions = new Options();
|
167
|
173
|
childOptions.topBar.title.text = new Text("someText");
|
168
|
|
- uut.mergeChildOptions(childOptions, child);
|
|
174
|
+ uut.mergeChildOptions(childOptions, EMPTY_OPTIONS, child);
|
169
|
175
|
|
170
|
176
|
verify(topBar, times(0)).setBackgroundColor(anyInt());
|
171
|
177
|
}
|
172
|
178
|
|
|
179
|
+ public void applyButtons_buttonColorIsMergedToButtons() {
|
|
180
|
+ Options options = new Options();
|
|
181
|
+ Button rightButton1 = new Button();
|
|
182
|
+ Button rightButton2 = new Button();
|
|
183
|
+ Button leftButton = new Button();
|
|
184
|
+
|
|
185
|
+ options.topBar.rightButtonColor = new Color(10);
|
|
186
|
+ options.topBar.leftButtonColor = new Color(100);
|
|
187
|
+
|
|
188
|
+ options.topBar.buttons.right = new ArrayList<>();
|
|
189
|
+ options.topBar.buttons.right.add(rightButton1);
|
|
190
|
+ options.topBar.buttons.right.add(rightButton2);
|
|
191
|
+
|
|
192
|
+ options.topBar.buttons.left = new ArrayList<>();
|
|
193
|
+ options.topBar.buttons.left.add(leftButton);
|
|
194
|
+
|
|
195
|
+ uut.applyChildOptions(options, child);
|
|
196
|
+ ArgumentCaptor<List<Button>> rightCaptor = ArgumentCaptor.forClass(List.class);
|
|
197
|
+ verify(topBar).setRightButtons(rightCaptor.capture());
|
|
198
|
+ assertThat(rightCaptor.getValue().get(0).color.get()).isEqualTo(options.topBar.rightButtonColor.get());
|
|
199
|
+ assertThat(rightCaptor.getValue().get(1).color.get()).isEqualTo(options.topBar.rightButtonColor.get());
|
|
200
|
+ assertThat(rightCaptor.getValue().get(0)).isNotEqualTo(rightButton1);
|
|
201
|
+ assertThat(rightCaptor.getValue().get(1)).isNotEqualTo(rightButton2);
|
|
202
|
+
|
|
203
|
+ ArgumentCaptor<List<Button>> leftCaptor = ArgumentCaptor.forClass(List.class);
|
|
204
|
+ verify(topBar).setLeftButtons(leftCaptor.capture());
|
|
205
|
+ assertThat(leftCaptor.getValue().get(0).color).isEqualTo(options.topBar.leftButtonColor);
|
|
206
|
+ assertThat(leftCaptor.getValue().get(0)).isNotEqualTo(leftButton);
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ @Test
|
|
210
|
+ public void mergeChildOptions_buttonColorIsResolvedFromAppliedOptions() {
|
|
211
|
+ Options appliedOptions = new Options();
|
|
212
|
+ appliedOptions.topBar.rightButtonColor = new Color(10);
|
|
213
|
+ appliedOptions.topBar.leftButtonColor = new Color(100);
|
|
214
|
+
|
|
215
|
+ Options options2 = new Options();
|
|
216
|
+ Button rightButton1 = new Button();
|
|
217
|
+ Button rightButton2 = new Button();
|
|
218
|
+ Button leftButton = new Button();
|
|
219
|
+
|
|
220
|
+ options2.topBar.buttons.right = new ArrayList<>();
|
|
221
|
+ options2.topBar.buttons.right.add(rightButton1);
|
|
222
|
+ options2.topBar.buttons.right.add(rightButton2);
|
|
223
|
+
|
|
224
|
+ options2.topBar.buttons.left = new ArrayList<>();
|
|
225
|
+ options2.topBar.buttons.left.add(leftButton);
|
|
226
|
+
|
|
227
|
+ uut.mergeChildOptions(options2, appliedOptions, child);
|
|
228
|
+ ArgumentCaptor<List<Button>> rightCaptor = ArgumentCaptor.forClass(List.class);
|
|
229
|
+ verify(topBar, times(1)).setRightButtons(rightCaptor.capture());
|
|
230
|
+ assertThat(rightCaptor.getValue().get(0).color.get()).isEqualTo(appliedOptions.topBar.rightButtonColor.get());
|
|
231
|
+ assertThat(rightCaptor.getValue().get(1).color.get()).isEqualTo(appliedOptions.topBar.rightButtonColor.get());
|
|
232
|
+ assertThat(rightCaptor.getValue().get(0)).isNotEqualTo(rightButton1);
|
|
233
|
+ assertThat(rightCaptor.getValue().get(1)).isNotEqualTo(rightButton2);
|
|
234
|
+
|
|
235
|
+ ArgumentCaptor<List<Button>> leftCaptor = ArgumentCaptor.forClass(List.class);
|
|
236
|
+ verify(topBar, times(1)).setLeftButtons(leftCaptor.capture());
|
|
237
|
+ assertThat(leftCaptor.getValue().get(0).color.get()).isEqualTo(appliedOptions.topBar.leftButtonColor.get());
|
|
238
|
+ assertThat(leftCaptor.getValue().get(0)).isNotEqualTo(leftButton);
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ @Test
|
|
242
|
+ public void mergeChildOptions_buttonColorIsResolvedFromMergedOptions() {
|
|
243
|
+ Options resolvedOptions = new Options();
|
|
244
|
+ resolvedOptions.topBar.rightButtonColor = new Color(10);
|
|
245
|
+ resolvedOptions.topBar.leftButtonColor = new Color(100);
|
|
246
|
+
|
|
247
|
+ Options options2 = new Options();
|
|
248
|
+ Button rightButton1 = new Button();
|
|
249
|
+ Button rightButton2 = new Button();
|
|
250
|
+ Button leftButton = new Button();
|
|
251
|
+
|
|
252
|
+ options2.topBar.buttons.right = new ArrayList<>();
|
|
253
|
+ options2.topBar.buttons.right.add(rightButton1);
|
|
254
|
+ options2.topBar.buttons.right.add(rightButton2);
|
|
255
|
+
|
|
256
|
+ options2.topBar.buttons.left = new ArrayList<>();
|
|
257
|
+ options2.topBar.buttons.left.add(leftButton);
|
|
258
|
+
|
|
259
|
+ uut.mergeChildOptions(options2, resolvedOptions, child);
|
|
260
|
+ ArgumentCaptor<List<Button>> rightCaptor = ArgumentCaptor.forClass(List.class);
|
|
261
|
+ verify(topBar).setRightButtons(rightCaptor.capture());
|
|
262
|
+ assertThat(rightCaptor.getValue().get(0).color.get()).isEqualTo(resolvedOptions.topBar.rightButtonColor.get());
|
|
263
|
+ assertThat(rightCaptor.getValue().get(1).color.get()).isEqualTo(resolvedOptions.topBar.rightButtonColor.get());
|
|
264
|
+ assertThat(rightCaptor.getValue().get(0)).isNotEqualTo(rightButton1);
|
|
265
|
+ assertThat(rightCaptor.getValue().get(1)).isNotEqualTo(rightButton2);
|
|
266
|
+
|
|
267
|
+ ArgumentCaptor<List<Button>> leftCaptor = ArgumentCaptor.forClass(List.class);
|
|
268
|
+ verify(topBar).setLeftButtons(leftCaptor.capture());
|
|
269
|
+ assertThat(leftCaptor.getValue().get(0).color.get()).isEqualTo(resolvedOptions.topBar.leftButtonColor.get());
|
|
270
|
+ assertThat(leftCaptor.getValue().get(0)).isNotEqualTo(leftButton);
|
|
271
|
+ }
|
|
272
|
+
|
173
|
273
|
private void assertTopBarOptions(Options options, int t) {
|
174
|
274
|
if (options.topBar.title.component.hasValue()) {
|
175
|
275
|
verify(topBar, times(0)).setTitle(any());
|