|
@@ -5,13 +5,13 @@ import android.support.annotation.*;
|
5
|
5
|
|
6
|
6
|
import com.reactnativenavigation.*;
|
7
|
7
|
import com.reactnativenavigation.mocks.*;
|
|
8
|
+import com.reactnativenavigation.parse.params.Bool;
|
8
|
9
|
import com.reactnativenavigation.utils.*;
|
9
|
10
|
|
10
|
11
|
import org.json.*;
|
11
|
12
|
import org.junit.*;
|
12
|
13
|
import org.mockito.*;
|
13
|
14
|
|
14
|
|
-import static com.reactnativenavigation.parse.Options.BooleanOptions.*;
|
15
|
15
|
import static org.assertj.core.api.Java6Assertions.*;
|
16
|
16
|
|
17
|
17
|
public class OptionsTest extends BaseTest {
|
|
@@ -22,11 +22,11 @@ public class OptionsTest extends BaseTest {
|
22
|
22
|
private static final int TOP_BAR_FONT_SIZE = 18;
|
23
|
23
|
private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
|
24
|
24
|
private static final Typeface TOP_BAR_TYPEFACE = Typeface.create("HelveticaNeue-CondensedBold", Typeface.BOLD);
|
25
|
|
- private static final Options.BooleanOptions TOP_BAR_HIDDEN = True;
|
26
|
|
- private static final Options.BooleanOptions TOP_BAR_DRAW_BEHIND = True;
|
27
|
|
- private static final Options.BooleanOptions TOP_BAR_HIDE_ON_SCROLL = True;
|
28
|
|
- private static final Options.BooleanOptions BOTTOM_TABS_ANIMATE_HIDE = True;
|
29
|
|
- private static final Options.BooleanOptions BOTTOM_TABS_HIDDEN = True;
|
|
25
|
+ private static final Bool TOP_BAR_HIDDEN = new Bool(true);
|
|
26
|
+ private static final Bool TOP_BAR_DRAW_BEHIND = new Bool(true);
|
|
27
|
+ private static final Bool TOP_BAR_HIDE_ON_SCROLL = new Bool(true);
|
|
28
|
+ private static final Bool BOTTOM_TABS_ANIMATE_HIDE = new Bool(true);
|
|
29
|
+ private static final Bool BOTTOM_TABS_HIDDEN = new Bool(true);
|
30
|
30
|
private static final String BOTTOM_TABS_BADGE = "3";
|
31
|
31
|
private static final String BOTTOM_TABS_CURRENT_TAB_ID = "ComponentId";
|
32
|
32
|
private static final int BOTTOM_TABS_CURRENT_TAB_INDEX = 1;
|
|
@@ -46,7 +46,7 @@ public class OptionsTest extends BaseTest {
|
46
|
46
|
@Test
|
47
|
47
|
public void parsesJson() throws Exception {
|
48
|
48
|
JSONObject json = new JSONObject()
|
49
|
|
- .put("topBar", createTopBar(TOP_BAR_HIDDEN))
|
|
49
|
+ .put("topBar", createTopBar(TOP_BAR_HIDDEN.get()))
|
50
|
50
|
.put("bottomTabs", createBottomTabs());
|
51
|
51
|
Options result = Options.parse(mockLoader, json);
|
52
|
52
|
assertResult(result);
|
|
@@ -58,11 +58,11 @@ public class OptionsTest extends BaseTest {
|
58
|
58
|
assertThat(result.topBarOptions.textColor.get()).isEqualTo(TOP_BAR_TEXT_COLOR);
|
59
|
59
|
assertThat(result.topBarOptions.textFontSize.get()).isEqualTo(TOP_BAR_FONT_SIZE);
|
60
|
60
|
assertThat(result.topBarOptions.textFontFamily).isEqualTo(TOP_BAR_TYPEFACE);
|
61
|
|
- assertThat(result.topBarOptions.hidden).isEqualTo(TOP_BAR_HIDDEN);
|
62
|
|
- assertThat(result.topBarOptions.drawBehind).isEqualTo(TOP_BAR_DRAW_BEHIND);
|
63
|
|
- assertThat(result.topBarOptions.hideOnScroll).isEqualTo(TOP_BAR_HIDE_ON_SCROLL);
|
64
|
|
- assertThat(result.bottomTabsOptions.animateHide).isEqualTo(BOTTOM_TABS_ANIMATE_HIDE);
|
65
|
|
- assertThat(result.bottomTabsOptions.visible).isEqualTo(BOTTOM_TABS_HIDDEN);
|
|
61
|
+ assertThat(result.topBarOptions.hidden.get()).isEqualTo(TOP_BAR_HIDDEN.get());
|
|
62
|
+ assertThat(result.topBarOptions.drawBehind.get()).isEqualTo(TOP_BAR_DRAW_BEHIND.get());
|
|
63
|
+ assertThat(result.topBarOptions.hideOnScroll.get()).isEqualTo(TOP_BAR_HIDE_ON_SCROLL.get());
|
|
64
|
+ assertThat(result.bottomTabsOptions.animateHide.get()).isEqualTo(BOTTOM_TABS_ANIMATE_HIDE.get());
|
|
65
|
+ assertThat(result.bottomTabsOptions.visible.get()).isEqualTo(BOTTOM_TABS_HIDDEN.get());
|
66
|
66
|
assertThat(result.bottomTabsOptions.currentTabId.get()).isEqualTo(BOTTOM_TABS_CURRENT_TAB_ID);
|
67
|
67
|
assertThat(result.bottomTabsOptions.currentTabIndex).isEqualTo(BOTTOM_TABS_CURRENT_TAB_INDEX);
|
68
|
68
|
}
|
|
@@ -72,12 +72,12 @@ public class OptionsTest extends BaseTest {
|
72
|
72
|
return new JSONObject()
|
73
|
73
|
.put("currentTabId", BOTTOM_TABS_CURRENT_TAB_ID)
|
74
|
74
|
.put("currentTabIndex", BOTTOM_TABS_CURRENT_TAB_INDEX)
|
75
|
|
- .put("visible", BOTTOM_TABS_HIDDEN)
|
76
|
|
- .put("animateHide", BOTTOM_TABS_ANIMATE_HIDE);
|
|
75
|
+ .put("visible", BOTTOM_TABS_HIDDEN.get())
|
|
76
|
+ .put("animateHide", BOTTOM_TABS_ANIMATE_HIDE.get());
|
77
|
77
|
}
|
78
|
78
|
|
79
|
79
|
@NonNull
|
80
|
|
- private JSONObject createTopBar(Options.BooleanOptions hidden) throws JSONException {
|
|
80
|
+ private JSONObject createTopBar(boolean hidden) throws JSONException {
|
81
|
81
|
return new JSONObject()
|
82
|
82
|
.put("title", "the title")
|
83
|
83
|
.put("backgroundColor", TOP_BAR_BACKGROUND_COLOR)
|
|
@@ -85,8 +85,8 @@ public class OptionsTest extends BaseTest {
|
85
|
85
|
.put("textFontSize", TOP_BAR_FONT_SIZE)
|
86
|
86
|
.put("textFontFamily", TOP_BAR_FONT_FAMILY)
|
87
|
87
|
.put("hidden", hidden)
|
88
|
|
- .put("drawBehind", TOP_BAR_DRAW_BEHIND)
|
89
|
|
- .put("hideOnScroll", TOP_BAR_HIDE_ON_SCROLL);
|
|
88
|
+ .put("drawBehind", TOP_BAR_DRAW_BEHIND.get())
|
|
89
|
+ .put("hideOnScroll", TOP_BAR_HIDE_ON_SCROLL.get());
|
90
|
90
|
}
|
91
|
91
|
|
92
|
92
|
@NonNull
|
|
@@ -113,23 +113,26 @@ public class OptionsTest extends BaseTest {
|
113
|
113
|
@Test
|
114
|
114
|
public void mergeDoesNotMutate() throws Exception {
|
115
|
115
|
JSONObject json1 = new JSONObject();
|
116
|
|
- json1.put("topBar", createTopBar(Options.BooleanOptions.True));
|
|
116
|
+ json1.put("topBar", createTopBar(true));
|
117
|
117
|
Options options1 = Options.parse(mockLoader, json1);
|
|
118
|
+ options1.topBarOptions.title = new Text("some title");
|
118
|
119
|
|
119
|
120
|
|
120
|
121
|
JSONObject json2 = new JSONObject();
|
121
|
|
- json2.put("topBar", createTopBar(Options.BooleanOptions.False));
|
|
122
|
+ json2.put("topBar", createTopBar(false));
|
122
|
123
|
Options options2 = Options.parse(mockLoader, json2);
|
|
124
|
+ options2.topBarOptions.title = new NullText();
|
123
|
125
|
|
124
|
126
|
Options merged = options1.mergeWith(options2);
|
125
|
|
- assertThat(options1.topBarOptions.hidden).isEqualTo(Options.BooleanOptions.True);
|
126
|
|
- assertThat(merged.topBarOptions.hidden).isEqualTo(False);
|
|
127
|
+ assertThat(options1.topBarOptions.hidden.get()).isTrue();
|
|
128
|
+ assertThat(merged.topBarOptions.hidden.get()).isFalse();
|
|
129
|
+ assertThat(merged.topBarOptions.title.get()).isEqualTo("some title");
|
127
|
130
|
}
|
128
|
131
|
|
129
|
132
|
@Test
|
130
|
133
|
public void mergeDefaultOptions() throws Exception {
|
131
|
134
|
JSONObject json = new JSONObject();
|
132
|
|
- json.put("topBar", createTopBar(TOP_BAR_HIDDEN));
|
|
135
|
+ json.put("topBar", createTopBar(TOP_BAR_HIDDEN.get()));
|
133
|
136
|
json.put("bottomTabs", createBottomTabs());
|
134
|
137
|
Options defaultOptions = Options.parse(mockLoader, json);
|
135
|
138
|
Options options = new Options();
|
|
@@ -145,7 +148,7 @@ public class OptionsTest extends BaseTest {
|
145
|
148
|
Options defaultOptions = Options.parse(mockLoader, defaultJson);
|
146
|
149
|
|
147
|
150
|
JSONObject json = new JSONObject()
|
148
|
|
- .put("topBar", createTopBar(TOP_BAR_HIDDEN))
|
|
151
|
+ .put("topBar", createTopBar(TOP_BAR_HIDDEN.get()))
|
149
|
152
|
.put("bottomTabs", createBottomTabs());
|
150
|
153
|
Options options = Options.parse(mockLoader, json);
|
151
|
154
|
options.withDefaultOptions(defaultOptions);
|
|
@@ -161,7 +164,7 @@ public class OptionsTest extends BaseTest {
|
161
|
164
|
@Test
|
162
|
165
|
public void topBar_defaultOptions() throws Exception {
|
163
|
166
|
Options uut = new Options();
|
164
|
|
- assertThat(uut.topBarOptions.hidden).isEqualTo(Options.BooleanOptions.False);
|
165
|
|
- assertThat(uut.topBarOptions.animateHide).isEqualTo(Options.BooleanOptions.True);
|
|
167
|
+ assertThat(uut.topBarOptions.hidden.isFalseOrUndefined()).isTrue();
|
|
168
|
+ assertThat(uut.topBarOptions.animateHide.isTrueOrUndefined()).isTrue();
|
166
|
169
|
}
|
167
|
170
|
}
|