|
@@ -1,24 +1,29 @@
|
1
|
1
|
package com.reactnativenavigation.views;
|
2
|
2
|
|
|
3
|
+import android.app.Activity;
|
3
|
4
|
import android.util.Log;
|
|
5
|
+import android.view.ViewGroup;
|
4
|
6
|
|
5
|
7
|
import com.reactnativenavigation.BaseTest;
|
6
|
8
|
import com.reactnativenavigation.R;
|
7
|
9
|
import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
|
8
|
10
|
import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
|
9
|
11
|
import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
|
10
|
|
-import com.reactnativenavigation.parse.TopBarBackgroundOptions;
|
11
|
12
|
import com.reactnativenavigation.parse.params.Text;
|
12
|
|
-import com.reactnativenavigation.react.ReactView;
|
|
13
|
+import com.reactnativenavigation.utils.ViewUtils;
|
13
|
14
|
import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
|
|
15
|
+import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
|
14
|
16
|
|
15
|
17
|
import org.junit.Test;
|
16
|
18
|
|
17
|
19
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
18
|
20
|
import static org.mockito.Mockito.spy;
|
|
21
|
+import static org.mockito.Mockito.times;
|
|
22
|
+import static org.mockito.Mockito.verify;
|
19
|
23
|
|
20
|
24
|
public class TopBarBackgroundComponentTest extends BaseTest {
|
21
|
25
|
private TopBar uut;
|
|
26
|
+ private TopBarBackgroundView backgroundView;
|
22
|
27
|
|
23
|
28
|
@SuppressWarnings("Convert2Lambda")
|
24
|
29
|
@Override
|
|
@@ -29,23 +34,39 @@ public class TopBarBackgroundComponentTest extends BaseTest {
|
29
|
34
|
Log.i("TopBarTest", "onPress: " + buttonId);
|
30
|
35
|
}
|
31
|
36
|
});
|
32
|
|
- StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), onClickListener);
|
33
|
|
- uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), onClickListener, parent);
|
|
37
|
+ TopBarBackgroundViewCreatorMock backgroundViewCreator = new TopBarBackgroundViewCreatorMock() {
|
|
38
|
+ @Override
|
|
39
|
+ public TopBarBackgroundView create(Activity activity, String componentId, String componentName) {
|
|
40
|
+ backgroundView = spy(super.create(activity, componentId, componentName));
|
|
41
|
+ return backgroundView;
|
|
42
|
+ }
|
|
43
|
+ };
|
|
44
|
+ StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener);
|
|
45
|
+ uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener, parent);
|
34
|
46
|
parent.addView(uut);
|
35
|
47
|
}
|
36
|
48
|
|
37
|
49
|
@Test
|
38
|
50
|
public void setBackgroundComponent() throws Exception {
|
39
|
|
- TopBarBackgroundOptions options = new TopBarBackgroundOptions();
|
40
|
|
- options.component = new Text("someComponent");
|
41
|
|
- uut.setBackgroundComponent(options);
|
42
|
|
- assertThat(ReactView.class.isAssignableFrom(uut.findViewById(R.id.topBarBackgroundComponent).getClass())).isTrue();
|
|
51
|
+ uut.getLayoutParams().height = 100;
|
|
52
|
+ uut.setBackgroundComponent(new Text("someComponent"));
|
|
53
|
+ TopBarBackgroundView background = (TopBarBackgroundView) ViewUtils.findChildrenByClassRecursive(uut, TopBarBackgroundView.class).get(0);
|
|
54
|
+ assertThat(background).isNotNull();
|
|
55
|
+ assertThat(background.getLayoutParams().width).isEqualTo(ViewGroup.LayoutParams.MATCH_PARENT);
|
|
56
|
+ assertThat(background.getLayoutParams().height).isEqualTo(uut.getHeight());
|
43
|
57
|
}
|
44
|
58
|
|
45
|
59
|
@Test
|
46
|
60
|
public void setBackgroundComponent_doesNotSetIfNoComponentIsDefined() throws Exception {
|
47
|
|
- TopBarBackgroundOptions options = new TopBarBackgroundOptions();
|
48
|
|
- uut.setBackgroundComponent(options);
|
|
61
|
+ uut.setBackgroundComponent(new Text("someComponent"));
|
49
|
62
|
assertThat(uut.findViewById(R.id.topBarBackgroundComponent)).isNull();
|
50
|
63
|
}
|
|
64
|
+
|
|
65
|
+ @Test
|
|
66
|
+ public void clear_componentIsDestroyed() throws Exception {
|
|
67
|
+ uut.setBackgroundComponent(new Text("someComponent"));
|
|
68
|
+ uut.clear();
|
|
69
|
+ verify(backgroundView, times(1)).destroy();
|
|
70
|
+ assertThat(backgroundView.getParent()).isNull();
|
|
71
|
+ }
|
51
|
72
|
}
|