|
@@ -1,7 +1,10 @@
|
1
|
1
|
package com.reactnativenavigation.parse;
|
2
|
2
|
|
|
3
|
+import android.support.annotation.NonNull;
|
|
4
|
+
|
3
|
5
|
import com.reactnativenavigation.BaseTest;
|
4
|
6
|
|
|
7
|
+import org.json.JSONException;
|
5
|
8
|
import org.json.JSONObject;
|
6
|
9
|
import org.junit.Test;
|
7
|
10
|
|
|
@@ -10,47 +13,114 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
|
10
|
13
|
|
11
|
14
|
public class NavigationOptionsTest extends BaseTest {
|
12
|
15
|
|
13
|
|
- @Test
|
|
16
|
+ private static final String TITLE = "the title";
|
|
17
|
+ private static final int TOP_BAR_BACKGROUND_COLOR = 0xff123456;
|
|
18
|
+ private static final int TOP_BAR_TEXT_COLOR = 0xff123456;
|
|
19
|
+ private static final int TOP_BAR_FONT_SIZE = 18;
|
|
20
|
+ private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
|
|
21
|
+ private static final NavigationOptions.BooleanOptions TOP_BAR_HIDDEN = True;
|
|
22
|
+ private static final NavigationOptions.BooleanOptions BOTTOM_TABS_ANIMATE_HIDE = True;
|
|
23
|
+ private static final NavigationOptions.BooleanOptions BOTTOM_TABS_HIDDEN = True;
|
|
24
|
+ private static final int BOTTOM_TABS_BADGE = 3;
|
|
25
|
+ private static final String BOTTOM_TABS_CURRENT_TAB_ID = "ContainerId";
|
|
26
|
+ private static final int BOTTOM_TABS_CURRENT_TAB_INDEX = 1;
|
|
27
|
+
|
|
28
|
+ @Test
|
14
|
29
|
public void parsesNullAsDefaultEmptyOptions() throws Exception {
|
15
|
30
|
assertThat(NavigationOptions.parse(null)).isNotNull();
|
16
|
31
|
}
|
17
|
32
|
|
18
|
33
|
@Test
|
19
|
34
|
public void parsesJson() throws Exception {
|
20
|
|
- JSONObject json = new JSONObject();
|
21
|
|
- JSONObject topBarJson = new JSONObject();
|
|
35
|
+ JSONObject json = new JSONObject()
|
|
36
|
+ .put("topBar", createTopBar())
|
|
37
|
+ .put("tabBar", createTabBar());
|
|
38
|
+ NavigationOptions result = NavigationOptions.parse(json);
|
|
39
|
+ assertResult(result);
|
|
40
|
+ }
|
22
|
41
|
|
23
|
|
- topBarJson.put("title", "the title");
|
24
|
|
- topBarJson.put("backgroundColor", 0xff123456);
|
25
|
|
- topBarJson.put("textColor", 0xff123456);
|
26
|
|
- topBarJson.put("textFontSize", 18);
|
27
|
|
- topBarJson.put("textFontFamily", "HelveticaNeue-CondensedBold");
|
28
|
|
- topBarJson.put("hidden", true);
|
|
42
|
+ private void assertResult(NavigationOptions result) {
|
|
43
|
+ assertThat(result.topBarOptions.title).isEqualTo(TITLE);
|
|
44
|
+ assertThat(result.topBarOptions.backgroundColor).isEqualTo(TOP_BAR_BACKGROUND_COLOR);
|
|
45
|
+ assertThat(result.topBarOptions.textColor).isEqualTo(TOP_BAR_TEXT_COLOR);
|
|
46
|
+ assertThat(result.topBarOptions.textFontSize).isEqualTo(TOP_BAR_FONT_SIZE);
|
|
47
|
+ assertThat(result.topBarOptions.textFontFamily).isEqualTo(TOP_BAR_FONT_FAMILY);
|
|
48
|
+ assertThat(result.topBarOptions.hidden).isEqualTo(TOP_BAR_HIDDEN);
|
|
49
|
+ assertThat(result.bottomTabsOptions.animateHide).isEqualTo(BOTTOM_TABS_ANIMATE_HIDE);
|
|
50
|
+ assertThat(result.bottomTabsOptions.hidden).isEqualTo(BOTTOM_TABS_HIDDEN);
|
|
51
|
+ assertThat(result.bottomTabsOptions.tabBadge).isEqualTo(BOTTOM_TABS_BADGE);
|
|
52
|
+ assertThat(result.bottomTabsOptions.currentTabId).isEqualTo(BOTTOM_TABS_CURRENT_TAB_ID);
|
|
53
|
+ assertThat(result.bottomTabsOptions.currentTabIndex).isEqualTo(BOTTOM_TABS_CURRENT_TAB_INDEX);
|
|
54
|
+ }
|
29
|
55
|
|
30
|
|
- json.put("topBar", topBarJson);
|
|
56
|
+ @NonNull
|
|
57
|
+ private JSONObject createTabBar() throws JSONException {
|
|
58
|
+ return new JSONObject()
|
|
59
|
+ .put("currentTabId", BOTTOM_TABS_CURRENT_TAB_ID)
|
|
60
|
+ .put("currentTabIndex", BOTTOM_TABS_CURRENT_TAB_INDEX)
|
|
61
|
+ .put("hidden", BOTTOM_TABS_HIDDEN)
|
|
62
|
+ .put("animateHide", BOTTOM_TABS_ANIMATE_HIDE)
|
|
63
|
+ .put("tabBadge", BOTTOM_TABS_BADGE);
|
|
64
|
+ }
|
31
|
65
|
|
32
|
|
- JSONObject tabBarJson = new JSONObject();
|
33
|
|
- tabBarJson.put("currentTabId", "ContainerId");
|
34
|
|
- tabBarJson.put("currentTabIndex", 1);
|
35
|
|
- tabBarJson.put("hidden", true);
|
36
|
|
- tabBarJson.put("animateHide", true);
|
37
|
|
- tabBarJson.put("tabBadge", 3);
|
|
66
|
+ @NonNull
|
|
67
|
+ private JSONObject createTopBar() throws JSONException {
|
|
68
|
+ return new JSONObject()
|
|
69
|
+ .put("title", TITLE)
|
|
70
|
+ .put("backgroundColor", TOP_BAR_BACKGROUND_COLOR)
|
|
71
|
+ .put("textColor", TOP_BAR_TEXT_COLOR)
|
|
72
|
+ .put("textFontSize", TOP_BAR_FONT_SIZE)
|
|
73
|
+ .put("textFontFamily", TOP_BAR_FONT_FAMILY)
|
|
74
|
+ .put("hidden", TOP_BAR_HIDDEN);
|
|
75
|
+ }
|
38
|
76
|
|
39
|
|
- json.put("tabBar", tabBarJson);
|
|
77
|
+ @NonNull
|
|
78
|
+ private JSONObject createOtherTopBar() throws JSONException {
|
|
79
|
+ return new JSONObject()
|
|
80
|
+ .put("title", TITLE)
|
|
81
|
+ .put("backgroundColor", TOP_BAR_BACKGROUND_COLOR)
|
|
82
|
+ .put("textColor", TOP_BAR_TEXT_COLOR)
|
|
83
|
+ .put("textFontSize", TOP_BAR_FONT_SIZE)
|
|
84
|
+ .put("textFontFamily", TOP_BAR_FONT_FAMILY)
|
|
85
|
+ .put("hidden", TOP_BAR_HIDDEN);
|
|
86
|
+ }
|
40
|
87
|
|
41
|
|
- NavigationOptions result = NavigationOptions.parse(json);
|
42
|
|
- assertThat(result.topBarOptions.title).isEqualTo("the title");
|
43
|
|
- assertThat(result.topBarOptions.backgroundColor).isEqualTo(0xff123456);
|
44
|
|
- assertThat(result.topBarOptions.textColor).isEqualTo(0xff123456);
|
45
|
|
- assertThat(result.topBarOptions.textFontSize).isEqualTo(18);
|
46
|
|
- assertThat(result.topBarOptions.textFontFamily).isEqualTo("HelveticaNeue-CondensedBold");
|
47
|
|
- assertThat(result.topBarOptions.hidden).isEqualTo(True);
|
48
|
|
- assertThat(result.bottomTabsOptions.animateHide).isEqualTo(True);
|
49
|
|
- assertThat(result.bottomTabsOptions.hidden).isEqualTo(True);
|
50
|
|
- assertThat(result.bottomTabsOptions.tabBadge).isEqualTo(3);
|
51
|
|
- assertThat(result.bottomTabsOptions.currentTabId).isEqualTo("ContainerId");
|
52
|
|
- assertThat(result.bottomTabsOptions.currentTabIndex).isEqualTo(1);
|
53
|
|
- }
|
|
88
|
+ @NonNull
|
|
89
|
+ private JSONObject createOtherTabBar() throws JSONException {
|
|
90
|
+ return new JSONObject()
|
|
91
|
+ .put("currentTabId", BOTTOM_TABS_CURRENT_TAB_ID)
|
|
92
|
+ .put("currentTabIndex", BOTTOM_TABS_CURRENT_TAB_INDEX)
|
|
93
|
+ .put("hidden", BOTTOM_TABS_HIDDEN)
|
|
94
|
+ .put("animateHide", BOTTOM_TABS_ANIMATE_HIDE)
|
|
95
|
+ .put("tabBadge", BOTTOM_TABS_BADGE);
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Test
|
|
99
|
+ public void mergeDefaultOptions() throws Exception {
|
|
100
|
+ JSONObject json = new JSONObject();
|
|
101
|
+ json.put("topBar", createTopBar());
|
|
102
|
+ json.put("tabBar", createTabBar());
|
|
103
|
+ NavigationOptions defaultOptions = NavigationOptions.parse(json);
|
|
104
|
+ NavigationOptions options = new NavigationOptions();
|
|
105
|
+
|
|
106
|
+ options.mergeWith(defaultOptions);
|
|
107
|
+ assertResult(options);
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ @Test
|
|
111
|
+ public void mergedDefaultOptionsDontOverrideGivenOptions() throws Exception {
|
|
112
|
+ JSONObject defaultJson = new JSONObject()
|
|
113
|
+ .put("topBar", createOtherTopBar())
|
|
114
|
+ .put("tabBar", createOtherTabBar());
|
|
115
|
+ NavigationOptions defaultOptions = NavigationOptions.parse(defaultJson);
|
|
116
|
+
|
|
117
|
+ JSONObject json = new JSONObject()
|
|
118
|
+ .put("topBar", createTopBar())
|
|
119
|
+ .put("tabBar", createTabBar());
|
|
120
|
+ NavigationOptions options = NavigationOptions.parse(json);
|
|
121
|
+ options.withDefaultOptions(defaultOptions);
|
|
122
|
+ assertResult(options);
|
|
123
|
+ }
|
54
|
124
|
|
55
|
125
|
@Test
|
56
|
126
|
public void defaultEmptyOptions() throws Exception {
|