|
@@ -1,16 +1,23 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
|
4
|
+import android.content.res.Resources;
|
|
5
|
+import android.view.ViewGroup.LayoutParams;
|
|
6
|
+import android.util.TypedValue;
|
4
|
7
|
import android.view.Gravity;
|
5
|
8
|
|
6
|
9
|
import com.reactnativenavigation.BaseTest;
|
7
|
10
|
import com.reactnativenavigation.mocks.SimpleComponentViewController;
|
8
|
11
|
import com.reactnativenavigation.parse.Options;
|
|
12
|
+import com.reactnativenavigation.parse.SideMenuOptions;
|
9
|
13
|
import com.reactnativenavigation.parse.params.Bool;
|
|
14
|
+import com.reactnativenavigation.parse.params.Number;
|
10
|
15
|
import com.reactnativenavigation.presentation.OptionsPresenter;
|
11
|
16
|
|
|
17
|
+import org.junit.Assert;
|
12
|
18
|
import org.junit.Test;
|
13
|
19
|
|
|
20
|
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
14
|
21
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
15
|
22
|
|
16
|
23
|
public class SideMenuControllerTest extends BaseTest {
|
|
@@ -55,4 +62,67 @@ public class SideMenuControllerTest extends BaseTest {
|
55
|
62
|
uut.mergeOptions(options);
|
56
|
63
|
assertThat(uut.options.sideMenuRootOptions).isNotEqualTo(initialOptions.sideMenuRootOptions);
|
57
|
64
|
}
|
|
65
|
+
|
|
66
|
+ @Test
|
|
67
|
+ public void setLeftController_matchesParentByDefault() {
|
|
68
|
+ SideMenuOptions options = new SideMenuOptions();
|
|
69
|
+ assertThat(options.width.hasValue()).isFalse();
|
|
70
|
+ assertThat(options.height.hasValue()).isFalse();
|
|
71
|
+ uut.options.sideMenuRootOptions.left = options;
|
|
72
|
+
|
|
73
|
+ SimpleComponentViewController componentViewController = new SimpleComponentViewController(activity, childRegistry, "left", new Options());
|
|
74
|
+ uut.setLeftController(componentViewController);
|
|
75
|
+
|
|
76
|
+ LayoutParams params = componentViewController.getView().getLayoutParams();
|
|
77
|
+ assertThat(params.width).isEqualTo(MATCH_PARENT);
|
|
78
|
+ assertThat(params.height).isEqualTo(MATCH_PARENT);
|
|
79
|
+ }
|
|
80
|
+ @Test
|
|
81
|
+ public void setLeftController_setHeightAndWidthWithOptions() {
|
|
82
|
+ SideMenuOptions options = new SideMenuOptions();
|
|
83
|
+ options.height = new Number(100);
|
|
84
|
+ options.width = new Number(200);
|
|
85
|
+ uut.options.sideMenuRootOptions.left = options;
|
|
86
|
+
|
|
87
|
+ SimpleComponentViewController componentViewController = new SimpleComponentViewController(activity, childRegistry, "left", new Options());
|
|
88
|
+ uut.setLeftController(componentViewController);
|
|
89
|
+
|
|
90
|
+ int heightInDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, Resources.getSystem().getDisplayMetrics());
|
|
91
|
+ int widthInDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, Resources.getSystem().getDisplayMetrics());
|
|
92
|
+
|
|
93
|
+ LayoutParams params = componentViewController.getView().getLayoutParams();
|
|
94
|
+ assertThat(params.width).isEqualTo(widthInDp);
|
|
95
|
+ assertThat(params.height).isEqualTo(heightInDp);
|
|
96
|
+ }
|
|
97
|
+ @Test
|
|
98
|
+ public void setRightController_matchesParentByDefault() {
|
|
99
|
+ SideMenuOptions options = new SideMenuOptions();
|
|
100
|
+ assertThat(options.width.hasValue()).isFalse();
|
|
101
|
+ assertThat(options.height.hasValue()).isFalse();
|
|
102
|
+ uut.options.sideMenuRootOptions.left = options;
|
|
103
|
+
|
|
104
|
+ SimpleComponentViewController componentViewController = new SimpleComponentViewController(activity, childRegistry, "right", new Options());
|
|
105
|
+ uut.setRightController(componentViewController);
|
|
106
|
+
|
|
107
|
+ LayoutParams params = componentViewController.getView().getLayoutParams();
|
|
108
|
+ assertThat(params.width).isEqualTo(MATCH_PARENT);
|
|
109
|
+ assertThat(params.height).isEqualTo(MATCH_PARENT);
|
|
110
|
+ }
|
|
111
|
+ @Test
|
|
112
|
+ public void setRightController_setHeightAndWidthWithOptions() {
|
|
113
|
+ SideMenuOptions options = new SideMenuOptions();
|
|
114
|
+ options.height = new Number(100);
|
|
115
|
+ options.width = new Number(200);
|
|
116
|
+ uut.options.sideMenuRootOptions.left = options;
|
|
117
|
+
|
|
118
|
+ SimpleComponentViewController componentViewController = new SimpleComponentViewController(activity, childRegistry, "left", new Options());
|
|
119
|
+ uut.setLeftController(componentViewController);
|
|
120
|
+
|
|
121
|
+ int heightInDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, Resources.getSystem().getDisplayMetrics());
|
|
122
|
+ int widthInDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, Resources.getSystem().getDisplayMetrics());
|
|
123
|
+
|
|
124
|
+ LayoutParams params = componentViewController.getView().getLayoutParams();
|
|
125
|
+ assertThat(params.width).isEqualTo(widthInDp);
|
|
126
|
+ assertThat(params.height).isEqualTo(heightInDp);
|
|
127
|
+ }
|
58
|
128
|
}
|