|
@@ -1,6 +1,8 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
|
4
|
+import android.graphics.Color;
|
|
5
|
+import android.graphics.drawable.ColorDrawable;
|
4
|
6
|
|
5
|
7
|
import com.reactnativenavigation.BaseTest;
|
6
|
8
|
import com.reactnativenavigation.mocks.TestContainerView;
|
|
@@ -12,42 +14,116 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
|
12
|
14
|
import static org.mockito.Mockito.spy;
|
13
|
15
|
import static org.mockito.Mockito.times;
|
14
|
16
|
import static org.mockito.Mockito.verify;
|
|
17
|
+import static org.mockito.Mockito.when;
|
15
|
18
|
|
16
|
19
|
public class ContainerViewControllerTest extends BaseTest {
|
17
|
|
- private ContainerViewController uut;
|
18
|
20
|
private Activity activity;
|
|
21
|
+ private ContainerViewController uut;
|
|
22
|
+ private ContainerViewController.ContainerView view;
|
|
23
|
+ private NavigationOptions initialNavigationOptions;
|
19
|
24
|
|
20
|
25
|
@Override
|
21
|
26
|
public void beforeEach() {
|
22
|
27
|
super.beforeEach();
|
23
|
28
|
activity = newActivity();
|
24
|
|
- }
|
25
|
|
-
|
26
|
|
- @Test
|
27
|
|
- public void createsViewFromContainerViewCreator() throws Exception {
|
28
|
|
- final ContainerViewController.ContainerView view = new TestContainerView(activity);
|
29
|
|
- uut = new ContainerViewController(newActivity(), "id1", "containerName", new ContainerViewController.ContainerViewCreator() {
|
|
29
|
+ initialNavigationOptions = new NavigationOptions();
|
|
30
|
+ view = spy(new TestContainerView(activity));
|
|
31
|
+ uut = new ContainerViewController(activity, "containerId1", "containerName", new ContainerViewController.ContainerViewCreator() {
|
30
|
32
|
@Override
|
31
|
33
|
public ContainerViewController.ContainerView create(final Activity activity1, final String containerId, final String containerName) {
|
32
|
34
|
return view;
|
33
|
35
|
}
|
34
|
|
- }, new NavigationOptions());
|
|
36
|
+ }, initialNavigationOptions);
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ @Test
|
|
40
|
+ public void createsViewFromContainerViewCreator() throws Exception {
|
35
|
41
|
assertThat(uut.getView()).isSameAs(view);
|
36
|
42
|
}
|
37
|
43
|
|
38
|
44
|
@Test
|
39
|
|
- public void containerViewDestroyedOnDestory() throws Exception {
|
40
|
|
- final ContainerViewController.ContainerView view = spy(new TestContainerView(activity));
|
41
|
|
- uut = new ContainerViewController(newActivity(), "id1", "containerName", new ContainerViewController.ContainerViewCreator() {
|
42
|
|
- @Override
|
43
|
|
- public ContainerViewController.ContainerView create(final Activity activity1, final String containerId, final String containerName) {
|
44
|
|
- return view;
|
45
|
|
- }
|
46
|
|
- }, new NavigationOptions());
|
|
45
|
+ public void containerViewDestroyedOnDestroy() throws Exception {
|
47
|
46
|
uut.ensureViewIsCreated();
|
48
|
|
-
|
49
|
47
|
verify(view, times(0)).destroy();
|
50
|
48
|
uut.destroy();
|
51
|
49
|
verify(view, times(1)).destroy();
|
52
|
50
|
}
|
|
51
|
+
|
|
52
|
+ @Test
|
|
53
|
+ public void lifecycleMethodsSentToContainerView() throws Exception {
|
|
54
|
+ uut.ensureViewIsCreated();
|
|
55
|
+ verify(view, times(0)).sendContainerStart();
|
|
56
|
+ verify(view, times(0)).sendContainerStop();
|
|
57
|
+ uut.onViewAppeared();
|
|
58
|
+ verify(view, times(1)).sendContainerStart();
|
|
59
|
+ verify(view, times(0)).sendContainerStop();
|
|
60
|
+ uut.onViewDisappear();
|
|
61
|
+ verify(view, times(1)).sendContainerStart();
|
|
62
|
+ verify(view, times(1)).sendContainerStop();
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ @Test
|
|
66
|
+ public void isViewShownOnlyIfContainerViewIsReady() throws Exception {
|
|
67
|
+ assertThat(uut.isViewShown()).isFalse();
|
|
68
|
+ uut.ensureViewIsCreated();
|
|
69
|
+ when(view.asView().isShown()).thenReturn(true);
|
|
70
|
+ assertThat(uut.isViewShown()).isFalse();
|
|
71
|
+ when(view.isReady()).thenReturn(true);
|
|
72
|
+ assertThat(uut.isViewShown()).isTrue();
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Test
|
|
76
|
+ public void applyNavigationOptionsHandlesNoParentStack() throws Exception {
|
|
77
|
+ assertThat(uut.getParentStackController()).isNull();
|
|
78
|
+ uut.onViewAppeared();
|
|
79
|
+ assertThat(uut.getParentStackController()).isNull();
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ @Test
|
|
83
|
+ public void initialOptionsAppliedOnAppear() throws Exception {
|
|
84
|
+ assertThat(uut.getNavigationOptions()).isSameAs(initialNavigationOptions);
|
|
85
|
+ initialNavigationOptions.title = "the title";
|
|
86
|
+ StackController stackController = new StackController(activity, "stackId");
|
|
87
|
+ stackController.push(uut);
|
|
88
|
+ assertThat(stackController.getTopBar().getTitle()).isEmpty();
|
|
89
|
+
|
|
90
|
+ uut.onViewAppeared();
|
|
91
|
+ assertThat(stackController.getTopBar().getTitle()).isEqualTo("the title");
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ @Test
|
|
95
|
+ public void mergeNavigationOptionsUpdatesCurrentOptions() throws Exception {
|
|
96
|
+ assertThat(uut.getNavigationOptions().title).isEmpty();
|
|
97
|
+ NavigationOptions options = new NavigationOptions();
|
|
98
|
+ options.title = "new title";
|
|
99
|
+ uut.mergeNavigationOptions(options);
|
|
100
|
+ assertThat(uut.getNavigationOptions().title).isEqualTo("new title");
|
|
101
|
+ assertThat(uut.getNavigationOptions()).isSameAs(initialNavigationOptions);
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ @Test
|
|
105
|
+ public void reappliesOptionsOnMerge() throws Exception {
|
|
106
|
+ StackController stackController = new StackController(activity, "stackId");
|
|
107
|
+ stackController.push(uut);
|
|
108
|
+ assertThat(stackController.getTopBar().getTitle()).isEmpty();
|
|
109
|
+
|
|
110
|
+ NavigationOptions opts = new NavigationOptions();
|
|
111
|
+ opts.title = "the new title";
|
|
112
|
+ uut.mergeNavigationOptions(opts);
|
|
113
|
+
|
|
114
|
+ assertThat(stackController.getTopBar().getTitle()).isEqualTo("the new title");
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ @Test
|
|
118
|
+ public void appliesTopBackBackgroundColor() throws Exception {
|
|
119
|
+ StackController stackController = new StackController(activity, "stackId");
|
|
120
|
+ stackController.push(uut);
|
|
121
|
+ assertThat(((ColorDrawable) stackController.getTopBar().getBackground()).getColor()).isNotEqualTo(0xffff0000);
|
|
122
|
+
|
|
123
|
+ NavigationOptions opts = new NavigationOptions();
|
|
124
|
+ opts.topBarBackgroundColor = Color.RED;
|
|
125
|
+ uut.mergeNavigationOptions(opts);
|
|
126
|
+
|
|
127
|
+ assertThat(((ColorDrawable) stackController.getTopBar().getBackground()).getColor()).isEqualTo(0xffff0000);
|
|
128
|
+ }
|
53
|
129
|
}
|