|
@@ -1,19 +1,24 @@
|
1
|
1
|
package com.reactnativenavigation.parse;
|
2
|
2
|
|
3
|
|
-import android.graphics.*;
|
4
|
|
-import android.support.annotation.*;
|
|
3
|
+import android.graphics.Typeface;
|
|
4
|
+import android.support.annotation.NonNull;
|
5
|
5
|
|
6
|
|
-import com.reactnativenavigation.*;
|
7
|
|
-import com.reactnativenavigation.mocks.*;
|
8
|
|
-import com.reactnativenavigation.parse.params.*;
|
|
6
|
+import com.reactnativenavigation.BaseTest;
|
|
7
|
+import com.reactnativenavigation.mocks.TypefaceLoaderMock;
|
|
8
|
+import com.reactnativenavigation.parse.params.Bool;
|
|
9
|
+import com.reactnativenavigation.parse.params.NullText;
|
9
|
10
|
import com.reactnativenavigation.parse.params.Number;
|
10
|
|
-import com.reactnativenavigation.utils.*;
|
|
11
|
+import com.reactnativenavigation.parse.params.Text;
|
|
12
|
+import com.reactnativenavigation.utils.TypefaceLoader;
|
11
|
13
|
|
12
|
|
-import org.json.*;
|
13
|
|
-import org.junit.*;
|
14
|
|
-import org.mockito.*;
|
|
14
|
+import org.json.JSONException;
|
|
15
|
+import org.json.JSONObject;
|
|
16
|
+import org.junit.Test;
|
|
17
|
+import org.mockito.Mockito;
|
|
18
|
+import org.mockito.stubbing.Answer;
|
15
|
19
|
|
16
|
|
-import static org.assertj.core.api.Java6Assertions.*;
|
|
20
|
+import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
21
|
+import static org.mockito.Mockito.when;
|
17
|
22
|
|
18
|
23
|
public class OptionsTest extends BaseTest {
|
19
|
24
|
|
|
@@ -30,6 +35,11 @@ public class OptionsTest extends BaseTest {
|
30
|
35
|
private static final int TOP_BAR_TEXT_COLOR = 0xff123456;
|
31
|
36
|
private static final int TOP_BAR_FONT_SIZE = 18;
|
32
|
37
|
private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
|
|
38
|
+ private static final int SUBTITLE_FONT_SIZE = 14;
|
|
39
|
+ private static final int SUBTITLE_TEXT_COLOR = 0xff123457;
|
|
40
|
+ private static final String SUBTITLE_FONT_FAMILY = "HelveticaNeue-Condensed";
|
|
41
|
+ private static final Typeface SUBTITLE_TYPEFACE = Typeface.create("HelveticaNeue-Condensed", Typeface.NORMAL);
|
|
42
|
+ private static final String SUBTITLE_ALIGNMENT = "center";
|
33
|
43
|
private static final Typeface TOP_BAR_TYPEFACE = Typeface.create("HelveticaNeue-CondensedBold", Typeface.BOLD);
|
34
|
44
|
private static final String TITLE_ALIGNMENT = "center";
|
35
|
45
|
private static final Bool TOP_BAR_VISIBLE = new Bool(true);
|
|
@@ -45,11 +55,13 @@ public class OptionsTest extends BaseTest {
|
45
|
55
|
@Override
|
46
|
56
|
public void beforeEach() {
|
47
|
57
|
mockLoader = Mockito.mock(TypefaceLoaderMock.class);
|
|
58
|
+ when(mockLoader.getTypeFace("HelveticaNeue-Condensed")).then((Answer<Typeface>) invocation -> SUBTITLE_TYPEFACE);
|
|
59
|
+ when(mockLoader.getTypeFace("HelveticaNeue-CondensedBold")).then((Answer<Typeface>) invocation -> TOP_BAR_TYPEFACE);
|
48
|
60
|
Mockito.doReturn(TOP_BAR_TYPEFACE).when(mockLoader).getTypeFace(TOP_BAR_FONT_FAMILY);
|
49
|
61
|
}
|
50
|
62
|
|
51
|
63
|
@Test
|
52
|
|
- public void parsesNullAsDefaultEmptyOptions() throws Exception {
|
|
64
|
+ public void parsesNullAsDefaultEmptyOptions() {
|
53
|
65
|
assertThat(Options.parse(mockLoader, null)).isNotNull();
|
54
|
66
|
}
|
55
|
67
|
|
|
@@ -69,6 +81,10 @@ public class OptionsTest extends BaseTest {
|
69
|
81
|
assertThat(result.topBarOptions.title.color.get()).isEqualTo(TOP_BAR_TEXT_COLOR);
|
70
|
82
|
assertThat(result.topBarOptions.title.fontSize.get()).isEqualTo(TOP_BAR_FONT_SIZE);
|
71
|
83
|
assertThat(result.topBarOptions.title.fontFamily).isEqualTo(TOP_BAR_TYPEFACE);
|
|
84
|
+ assertThat(result.topBarOptions.subtitle.color.get()).isEqualTo(SUBTITLE_TEXT_COLOR);
|
|
85
|
+ assertThat(result.topBarOptions.subtitle.fontSize.get()).isEqualTo(SUBTITLE_FONT_SIZE);
|
|
86
|
+ assertThat(result.topBarOptions.subtitle.alignment).isEqualTo(Alignment.fromString(SUBTITLE_ALIGNMENT));
|
|
87
|
+ assertThat(result.topBarOptions.subtitle.fontFamily).isEqualTo(SUBTITLE_TYPEFACE);
|
72
|
88
|
assertThat(result.topBarOptions.visible.get()).isEqualTo(TOP_BAR_VISIBLE.get());
|
73
|
89
|
assertThat(result.topBarOptions.drawBehind.get()).isEqualTo(TOP_BAR_DRAW_BEHIND.get());
|
74
|
90
|
assertThat(result.topBarOptions.hideOnScroll.get()).isEqualTo(TOP_BAR_HIDE_ON_SCROLL.get());
|
|
@@ -100,6 +116,7 @@ public class OptionsTest extends BaseTest {
|
100
|
116
|
private JSONObject createTopBar(boolean visible) throws JSONException {
|
101
|
117
|
return new JSONObject()
|
102
|
118
|
.put("title", createTitle())
|
|
119
|
+ .put("subtitle", createSubtitle())
|
103
|
120
|
.put("background", createBackground())
|
104
|
121
|
.put("visible", visible)
|
105
|
122
|
.put("drawBehind", TOP_BAR_DRAW_BEHIND.get())
|
|
@@ -120,6 +137,15 @@ public class OptionsTest extends BaseTest {
|
120
|
137
|
.put("alignment", TITLE_ALIGNMENT);
|
121
|
138
|
}
|
122
|
139
|
|
|
140
|
+ private JSONObject createSubtitle() throws JSONException {
|
|
141
|
+ return new JSONObject()
|
|
142
|
+ .put("text", "the subtitle")
|
|
143
|
+ .put("color", SUBTITLE_TEXT_COLOR)
|
|
144
|
+ .put("fontSize", SUBTITLE_FONT_SIZE)
|
|
145
|
+ .put("fontFamily", SUBTITLE_FONT_FAMILY)
|
|
146
|
+ .put("alignment", SUBTITLE_ALIGNMENT);
|
|
147
|
+ }
|
|
148
|
+
|
123
|
149
|
@NonNull
|
124
|
150
|
private JSONObject createFab() throws JSONException {
|
125
|
151
|
return new JSONObject()
|
|
@@ -150,6 +176,7 @@ public class OptionsTest extends BaseTest {
|
150
|
176
|
private JSONObject createOtherTopBar() throws JSONException {
|
151
|
177
|
return new JSONObject()
|
152
|
178
|
.put("title", createTitle())
|
|
179
|
+ .put("subtitle", createSubtitle())
|
153
|
180
|
.put("background", createBackground())
|
154
|
181
|
.put("visible", TOP_BAR_VISIBLE);
|
155
|
182
|
}
|
|
@@ -211,20 +238,20 @@ public class OptionsTest extends BaseTest {
|
211
|
238
|
}
|
212
|
239
|
|
213
|
240
|
@Test
|
214
|
|
- public void defaultEmptyOptions() throws Exception {
|
|
241
|
+ public void defaultEmptyOptions() {
|
215
|
242
|
Options uut = new Options();
|
216
|
243
|
assertThat(uut.topBarOptions.title.text.get("")).isEmpty();
|
217
|
244
|
}
|
218
|
245
|
|
219
|
246
|
@Test
|
220
|
|
- public void topBar_defaultOptions() throws Exception {
|
|
247
|
+ public void topBar_defaultOptions() {
|
221
|
248
|
Options uut = new Options();
|
222
|
249
|
assertThat(uut.topBarOptions.visible.isFalseOrUndefined()).isTrue();
|
223
|
250
|
assertThat(uut.topBarOptions.animate.isTrueOrUndefined()).isTrue();
|
224
|
251
|
}
|
225
|
252
|
|
226
|
253
|
@Test
|
227
|
|
- public void clear_topBarOptions() throws Exception {
|
|
254
|
+ public void clear_topBarOptions() {
|
228
|
255
|
Options uut = new Options();
|
229
|
256
|
uut.topBarOptions.title.text = new Text("some title");
|
230
|
257
|
uut.clearTopBarOptions();
|
|
@@ -232,7 +259,7 @@ public class OptionsTest extends BaseTest {
|
232
|
259
|
}
|
233
|
260
|
|
234
|
261
|
@Test
|
235
|
|
- public void clear_bottomTabsOptions() throws Exception {
|
|
262
|
+ public void clear_bottomTabsOptions() {
|
236
|
263
|
Options uut = new Options();
|
237
|
264
|
uut.bottomTabsOptions.tabColor = new com.reactnativenavigation.parse.params.Color(android.graphics.Color.RED);
|
238
|
265
|
uut.clearBottomTabsOptions();
|
|
@@ -240,7 +267,7 @@ public class OptionsTest extends BaseTest {
|
240
|
267
|
}
|
241
|
268
|
|
242
|
269
|
@Test
|
243
|
|
- public void clear_topTabsOptions() throws Exception {
|
|
270
|
+ public void clear_topTabsOptions() {
|
244
|
271
|
Options uut = new Options();
|
245
|
272
|
uut.topTabsOptions.fontSize = new Number(666);
|
246
|
273
|
uut.clearTopTabsOptions();
|
|
@@ -248,7 +275,7 @@ public class OptionsTest extends BaseTest {
|
248
|
275
|
}
|
249
|
276
|
|
250
|
277
|
@Test
|
251
|
|
- public void clear_topTabOptions() throws Exception {
|
|
278
|
+ public void clear_topTabOptions() {
|
252
|
279
|
Options uut = new Options();
|
253
|
280
|
uut.topTabOptions.title = new Text("some title");
|
254
|
281
|
uut.clearTopTabOptions();
|