|
@@ -1,23 +1,32 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
|
-import android.app.*;
|
4
|
|
-import android.support.annotation.*;
|
5
|
|
-import android.view.*;
|
6
|
|
-import android.widget.*;
|
7
|
|
-
|
8
|
|
-import com.reactnativenavigation.*;
|
9
|
|
-import com.reactnativenavigation.mocks.*;
|
|
3
|
+import android.app.Activity;
|
|
4
|
+import android.support.annotation.NonNull;
|
|
5
|
+import android.view.ViewGroup;
|
|
6
|
+import android.widget.FrameLayout;
|
|
7
|
+
|
|
8
|
+import com.reactnativenavigation.BaseTest;
|
|
9
|
+import com.reactnativenavigation.mocks.MockPromise;
|
|
10
|
+import com.reactnativenavigation.mocks.SimpleViewController;
|
10
|
11
|
import com.reactnativenavigation.parse.Options;
|
|
12
|
+import com.reactnativenavigation.parse.Text;
|
|
13
|
+import com.reactnativenavigation.views.ReactComponent;
|
11
|
14
|
|
12
|
|
-import org.junit.*;
|
|
15
|
+import org.junit.Test;
|
|
16
|
+import org.mockito.ArgumentCaptor;
|
13
|
17
|
|
14
|
|
-import java.util.*;
|
|
18
|
+import java.util.ArrayList;
|
|
19
|
+import java.util.Collection;
|
|
20
|
+import java.util.List;
|
15
|
21
|
|
16
|
|
-import static org.assertj.core.api.Java6Assertions.*;
|
17
|
|
-import static org.mockito.Mockito.*;
|
|
22
|
+import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
23
|
+import static org.mockito.Mockito.spy;
|
|
24
|
+import static org.mockito.Mockito.times;
|
|
25
|
+import static org.mockito.Mockito.verify;
|
18
|
26
|
|
19
|
27
|
public class ParentControllerTest extends BaseTest {
|
20
|
28
|
|
|
29
|
+ public static final String INITIAL_TITLE = "initial title";
|
21
|
30
|
private Activity activity;
|
22
|
31
|
private List<ViewController> children;
|
23
|
32
|
private ParentController uut;
|
|
@@ -27,12 +36,19 @@ public class ParentControllerTest extends BaseTest {
|
27
|
36
|
super.beforeEach();
|
28
|
37
|
activity = newActivity();
|
29
|
38
|
children = new ArrayList<>();
|
30
|
|
- uut = new ParentController(activity, "uut", new Options()) {
|
|
39
|
+ Options initialOptions = new Options();
|
|
40
|
+ initialOptions.topBarOptions.title = new Text(INITIAL_TITLE);
|
|
41
|
+ uut = spy(new ParentController(activity, "uut", initialOptions) {
|
31
|
42
|
|
32
|
43
|
@NonNull
|
33
|
44
|
@Override
|
34
|
45
|
protected ViewGroup createView() {
|
35
|
|
- return new FrameLayout(activity);
|
|
46
|
+ FrameLayout layout = new FrameLayout(activity);
|
|
47
|
+ for (ViewController child : children) {
|
|
48
|
+ child.setParentController(this);
|
|
49
|
+ layout.addView(child.getView());
|
|
50
|
+ }
|
|
51
|
+ return layout;
|
36
|
52
|
}
|
37
|
53
|
|
38
|
54
|
@NonNull
|
|
@@ -40,7 +56,7 @@ public class ParentControllerTest extends BaseTest {
|
40
|
56
|
public Collection<ViewController> getChildControllers() {
|
41
|
57
|
return children;
|
42
|
58
|
}
|
43
|
|
- };
|
|
59
|
+ });
|
44
|
60
|
}
|
45
|
61
|
|
46
|
62
|
@Test
|
|
@@ -95,4 +111,35 @@ public class ParentControllerTest extends BaseTest {
|
95
|
111
|
child1.onViewAppeared();
|
96
|
112
|
verify(stackController, times(1)).clearOptions();
|
97
|
113
|
}
|
|
114
|
+
|
|
115
|
+ @Test
|
|
116
|
+ public void mergeOptions_optionsAreMergedWhenChildAppears() throws Exception {
|
|
117
|
+ Options options = new Options();
|
|
118
|
+ options.topBarOptions.title = new Text("new title");
|
|
119
|
+ ViewController child1 = spy(new SimpleViewController(activity, "child1", options));
|
|
120
|
+ children.add(child1);
|
|
121
|
+ uut.ensureViewIsCreated();
|
|
122
|
+
|
|
123
|
+ child1.ensureViewIsCreated();
|
|
124
|
+ child1.onViewAppeared();
|
|
125
|
+ ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);
|
|
126
|
+ ArgumentCaptor<ReactComponent> viewCaptor = ArgumentCaptor.forClass(ReactComponent.class);
|
|
127
|
+ verify(uut, times(1)).applyOptions(optionsCaptor.capture(), viewCaptor.capture());
|
|
128
|
+ assertThat(optionsCaptor.getValue().topBarOptions.title.get()).isEqualTo("new title");
|
|
129
|
+ assertThat(viewCaptor.getValue()).isEqualTo(child1.getView());
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ @Test
|
|
133
|
+ public void mergeOptions_initialParentOptionsAreNotMutatedWhenChildAppears() throws Exception {
|
|
134
|
+ Options options = new Options();
|
|
135
|
+ options.topBarOptions.title = new Text("new title");
|
|
136
|
+ ViewController child1 = spy(new SimpleViewController(activity, "child1", options));
|
|
137
|
+ children.add(child1);
|
|
138
|
+
|
|
139
|
+ uut.ensureViewIsCreated();
|
|
140
|
+
|
|
141
|
+ child1.ensureViewIsCreated();
|
|
142
|
+ child1.onViewAppeared();
|
|
143
|
+ assertThat(uut.initialOptions.topBarOptions.title.get()).isEqualTo(INITIAL_TITLE);
|
|
144
|
+ }
|
98
|
145
|
}
|