react-native-navigation 8.2.1 → 8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/android/app/build.gradle +29 -0
- package/lib/android/app/src/androidTest/AndroidManifest.xml +17 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/BaseAndroidTest.kt +4 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/TestActivity.kt +4 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/TestApplication.kt +40 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/TestUtils.java +65 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/fakes/IconResolverFake.kt +8 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/mocks/BackDrawable.java +30 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/mocks/ImageLoaderMock.kt +49 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/mocks/SimpleViewController.java +110 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/mocks/TitleBarButtonCreatorMock.java +26 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/mocks/TitleBarReactViewCreatorMock.java +8 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/mocks/TopBarBackgroundViewCreatorMock.java +8 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/mocks/TypefaceLoaderMock.java +34 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/utils/ButtonPresenterTest.kt +379 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/AfterInitialTabTest.kt +42 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/AttachModeTest.kt +98 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/OnSwitchToTabTest.kt +32 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/TogetherTest.kt +19 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/viewcontrollers/child/ChildControllerTest.java +102 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/viewcontrollers/child/ChildControllersRegistryTest.java +67 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/viewcontrollers/parent/ParentControllerTest.java +349 -0
- package/lib/android/app/src/androidTest/java/com/reactnativenavigation/views/TitleSubTitleLayoutTest.kt +51 -0
- package/lib/ios/RNNAppDelegate.mm +0 -22
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
package com.reactnativenavigation.viewcontrollers.child;
|
|
2
|
+
|
|
3
|
+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
|
4
|
+
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
|
|
5
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
6
|
+
|
|
7
|
+
import com.reactnativenavigation.BaseAndroidTest;
|
|
8
|
+
import com.reactnativenavigation.TestActivity;
|
|
9
|
+
import com.reactnativenavigation.mocks.SimpleViewController;
|
|
10
|
+
import com.reactnativenavigation.options.Options;
|
|
11
|
+
|
|
12
|
+
import org.assertj.core.api.Java6Assertions;
|
|
13
|
+
import org.junit.Before;
|
|
14
|
+
import org.junit.Rule;
|
|
15
|
+
import org.junit.Test;
|
|
16
|
+
import org.junit.runner.RunWith;
|
|
17
|
+
import org.mockito.Mockito;
|
|
18
|
+
|
|
19
|
+
@RunWith(AndroidJUnit4ClassRunner.class)
|
|
20
|
+
public class ChildControllersRegistryTest extends BaseAndroidTest {
|
|
21
|
+
private ChildControllersRegistry uut;
|
|
22
|
+
private ChildController<?> child1;
|
|
23
|
+
private ChildController<?> child2;
|
|
24
|
+
|
|
25
|
+
@Rule
|
|
26
|
+
public ActivityScenarioRule<TestActivity> rule = new ActivityScenarioRule<>(TestActivity.class);
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@Before
|
|
30
|
+
public void beforeEach() {
|
|
31
|
+
rule.getScenario().onActivity(activity -> {
|
|
32
|
+
uut = new ChildControllersRegistry();
|
|
33
|
+
child1 = Mockito.spy(new SimpleViewController(activity, uut, "child1", new Options()));
|
|
34
|
+
child2 = Mockito.spy(new SimpleViewController(activity, uut, "child2", new Options()));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
public void onViewAppeared() {
|
|
40
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> child1.onViewWillAppear());
|
|
41
|
+
Mockito.verify(child1, Mockito.times(0)).onViewBroughtToFront();
|
|
42
|
+
Java6Assertions.assertThat(uut.size()).isOne();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Test
|
|
46
|
+
public void onViewDisappear() {
|
|
47
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
48
|
+
child1.onViewWillAppear();
|
|
49
|
+
child2.onViewWillAppear();
|
|
50
|
+
});
|
|
51
|
+
Java6Assertions.assertThat(uut.size()).isEqualTo(2);
|
|
52
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> child2.onViewDisappear());
|
|
53
|
+
Mockito.verify(child1, Mockito.times(1)).onViewBroughtToFront();
|
|
54
|
+
Java6Assertions.assertThat(uut.size()).isOne();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Test
|
|
58
|
+
public void onChildDestroyed() {
|
|
59
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> child1.destroy());
|
|
60
|
+
Java6Assertions.assertThat(uut.size()).isEqualTo(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test
|
|
64
|
+
public void onViewDisappear_doesNotCrashIfNoViewsHaveAppeared() {
|
|
65
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> uut.onViewDisappear(child1));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
package com.reactnativenavigation.viewcontrollers.parent;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.res.Configuration;
|
|
5
|
+
import android.view.ViewGroup;
|
|
6
|
+
import android.widget.FrameLayout;
|
|
7
|
+
|
|
8
|
+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
|
9
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
10
|
+
import androidx.test.platform.app.InstrumentationRegistry;
|
|
11
|
+
|
|
12
|
+
import com.reactnativenavigation.BaseAndroidTest;
|
|
13
|
+
import com.reactnativenavigation.TestActivity;
|
|
14
|
+
import com.reactnativenavigation.TestUtils;
|
|
15
|
+
import com.reactnativenavigation.mocks.SimpleViewController;
|
|
16
|
+
import com.reactnativenavigation.options.Options;
|
|
17
|
+
import com.reactnativenavigation.options.params.Text;
|
|
18
|
+
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter;
|
|
19
|
+
import com.reactnativenavigation.react.CommandListenerAdapter;
|
|
20
|
+
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
|
|
21
|
+
import com.reactnativenavigation.viewcontrollers.stack.StackController;
|
|
22
|
+
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController;
|
|
23
|
+
|
|
24
|
+
import org.junit.Before;
|
|
25
|
+
import org.junit.Rule;
|
|
26
|
+
import org.junit.Test;
|
|
27
|
+
import org.junit.runner.RunWith;
|
|
28
|
+
import org.mockito.ArgumentCaptor;
|
|
29
|
+
import org.mockito.Mockito;
|
|
30
|
+
|
|
31
|
+
import java.util.ArrayList;
|
|
32
|
+
import java.util.Arrays;
|
|
33
|
+
import java.util.Collection;
|
|
34
|
+
import java.util.List;
|
|
35
|
+
|
|
36
|
+
import androidx.annotation.NonNull;
|
|
37
|
+
|
|
38
|
+
import static com.reactnativenavigation.utils.CollectionUtils.*;
|
|
39
|
+
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
40
|
+
import static org.mockito.ArgumentMatchers.any;
|
|
41
|
+
import static org.mockito.ArgumentMatchers.eq;
|
|
42
|
+
import static org.mockito.Mockito.mock;
|
|
43
|
+
import static org.mockito.Mockito.never;
|
|
44
|
+
import static org.mockito.Mockito.spy;
|
|
45
|
+
import static org.mockito.Mockito.times;
|
|
46
|
+
import static org.mockito.Mockito.verify;
|
|
47
|
+
import static org.mockito.Mockito.when;
|
|
48
|
+
|
|
49
|
+
@RunWith(AndroidJUnit4.class)
|
|
50
|
+
public class ParentControllerTest extends BaseAndroidTest {
|
|
51
|
+
private static final String INITIAL_TITLE = "initial title";
|
|
52
|
+
private Activity activity;
|
|
53
|
+
private ChildControllersRegistry childRegistry;
|
|
54
|
+
private List<ViewController<?>> children;
|
|
55
|
+
private ParentController<?> uut;
|
|
56
|
+
private Presenter presenter;
|
|
57
|
+
|
|
58
|
+
@Rule
|
|
59
|
+
public ActivityScenarioRule<TestActivity> rule = new ActivityScenarioRule<>(TestActivity.class);
|
|
60
|
+
|
|
61
|
+
@Before
|
|
62
|
+
public void beforeEach() {
|
|
63
|
+
rule.getScenario().onActivity(activity -> {
|
|
64
|
+
this.activity = activity;
|
|
65
|
+
childRegistry = new ChildControllersRegistry();
|
|
66
|
+
children = new ArrayList<>();
|
|
67
|
+
Options initialOptions = new Options();
|
|
68
|
+
initialOptions.topBar.title.text = new Text(INITIAL_TITLE);
|
|
69
|
+
presenter = spy(new Presenter(activity, new Options()));
|
|
70
|
+
uut = spy(new ParentController<ViewGroup>(activity, childRegistry, "uut", presenter, initialOptions) {
|
|
71
|
+
@Override
|
|
72
|
+
public ViewController<?> getCurrentChild() {
|
|
73
|
+
return children.get(0);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@NonNull
|
|
77
|
+
@Override
|
|
78
|
+
public ViewGroup createView() {
|
|
79
|
+
FrameLayout layout = new FrameLayout(activity);
|
|
80
|
+
for (ViewController<?> child : children) {
|
|
81
|
+
child.setParentController(this);
|
|
82
|
+
layout.addView(child.getView());
|
|
83
|
+
}
|
|
84
|
+
return layout;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Override
|
|
88
|
+
public void sendOnNavigationButtonPressed(String buttonId) {
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@NonNull
|
|
92
|
+
@Override
|
|
93
|
+
public Collection<ViewController<?>> getChildControllers() {
|
|
94
|
+
return children;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@Test
|
|
101
|
+
public void onConfigurationChange_shouldCallConfigurationChangeForPresenterAndVisibleChild() {
|
|
102
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
103
|
+
SimpleViewController child1 = spy(
|
|
104
|
+
new SimpleViewController(activity, childRegistry, "child1", new Options()));
|
|
105
|
+
SimpleViewController child2 = spy(
|
|
106
|
+
new SimpleViewController(activity, childRegistry, "child2", new Options()));
|
|
107
|
+
children.add(child1);
|
|
108
|
+
children.add(child2);
|
|
109
|
+
Mockito.when(child1.isViewShown()).thenReturn(true);
|
|
110
|
+
Mockito.when(child2.isViewShown()).thenReturn(false);
|
|
111
|
+
uut.onConfigurationChanged(mock(Configuration.class));
|
|
112
|
+
verify(presenter).onConfigurationChanged(any(), any());
|
|
113
|
+
verify(child1).onConfigurationChanged(any());
|
|
114
|
+
verify(child2, never()).onConfigurationChanged(any());
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Test
|
|
119
|
+
public void onViewDidAppearShouldCallCurrentChildDidAppear() {
|
|
120
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
121
|
+
SimpleViewController child1 = spy(
|
|
122
|
+
new SimpleViewController(activity, childRegistry, "child1", new Options()));
|
|
123
|
+
SimpleViewController child2 = spy(
|
|
124
|
+
new SimpleViewController(activity, childRegistry, "child2", new Options()));
|
|
125
|
+
children.add(child1);
|
|
126
|
+
children.add(child2);
|
|
127
|
+
|
|
128
|
+
uut.onViewDidAppear();
|
|
129
|
+
|
|
130
|
+
verify(child1).onViewDidAppear();
|
|
131
|
+
verify(child2, never()).onViewDidAppear();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Test
|
|
136
|
+
public void onViewDisappearShouldCallCurrentChildDisAppear() {
|
|
137
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
138
|
+
SimpleViewController child1 = spy(
|
|
139
|
+
new SimpleViewController(activity, childRegistry, "child1", new Options()));
|
|
140
|
+
SimpleViewController child2 = spy(
|
|
141
|
+
new SimpleViewController(activity, childRegistry, "child2", new Options()));
|
|
142
|
+
children.add(child1);
|
|
143
|
+
children.add(child2);
|
|
144
|
+
|
|
145
|
+
uut.onViewDisappear();
|
|
146
|
+
|
|
147
|
+
verify(child1).onViewDisappear();
|
|
148
|
+
verify(child2, never()).onViewDisappear();
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Test
|
|
153
|
+
public void holdsViewGroup() {
|
|
154
|
+
assertThat(uut.getView()).isInstanceOf(ViewGroup.class);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@Test
|
|
158
|
+
public void mustHaveChildControllers() {
|
|
159
|
+
assertThat(uut.getChildControllers()).isNotNull();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@Test
|
|
163
|
+
public void findControllerById_ChildById() {
|
|
164
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
165
|
+
SimpleViewController child1 = new SimpleViewController(activity, childRegistry, "child1", new Options());
|
|
166
|
+
SimpleViewController child2 = new SimpleViewController(activity, childRegistry, "child2", new Options());
|
|
167
|
+
children.add(child1);
|
|
168
|
+
children.add(child2);
|
|
169
|
+
|
|
170
|
+
assertThat(uut.findController("uut")).isEqualTo(uut);
|
|
171
|
+
assertThat(uut.findController("child1")).isEqualTo(child1);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@Test
|
|
176
|
+
public void findControllerById_Recursive() {
|
|
177
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
178
|
+
StackController stackController = TestUtils.newStackController(activity).build();
|
|
179
|
+
stackController.ensureViewIsCreated();
|
|
180
|
+
SimpleViewController child1 = new SimpleViewController(activity, childRegistry, "child1", new Options());
|
|
181
|
+
SimpleViewController child2 = new SimpleViewController(activity, childRegistry, "child2", new Options());
|
|
182
|
+
stackController.push(child1, new CommandListenerAdapter());
|
|
183
|
+
stackController.push(child2, new CommandListenerAdapter());
|
|
184
|
+
children.add(stackController);
|
|
185
|
+
|
|
186
|
+
assertThat(uut.findController("child2")).isEqualTo(child2);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
@Test
|
|
191
|
+
public void destroy_DestroysChildren() {
|
|
192
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
193
|
+
ViewController<?> child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
|
|
194
|
+
children.add(child1);
|
|
195
|
+
|
|
196
|
+
verify(child1, times(0)).destroy();
|
|
197
|
+
uut.destroy();
|
|
198
|
+
verify(child1, times(1)).destroy();
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@Test
|
|
203
|
+
public void optionsAreClearedWhenChildIsAppeared() {
|
|
204
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
205
|
+
StackController stackController = spy(TestUtils.newStackController(activity).build());
|
|
206
|
+
stackController.ensureViewIsCreated();
|
|
207
|
+
SimpleViewController child1 = new SimpleViewController(activity, childRegistry, "child1", new Options());
|
|
208
|
+
stackController.push(child1, new CommandListenerAdapter());
|
|
209
|
+
|
|
210
|
+
child1.onViewWillAppear();
|
|
211
|
+
verify(stackController, times(1)).clearOptions();
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@Test
|
|
216
|
+
public void mergeOptions_optionsAreMergedWhenChildAppears() {
|
|
217
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
218
|
+
Options options = new Options();
|
|
219
|
+
options.topBar.title.text = new Text("new title");
|
|
220
|
+
ViewController<?> child1 = spy(new SimpleViewController(activity, childRegistry, "child1", options));
|
|
221
|
+
children.add(child1);
|
|
222
|
+
uut.ensureViewIsCreated();
|
|
223
|
+
|
|
224
|
+
child1.ensureViewIsCreated();
|
|
225
|
+
child1.onViewWillAppear();
|
|
226
|
+
ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);
|
|
227
|
+
verify(uut, times(1)).clearOptions();
|
|
228
|
+
verify(uut, times(1)).applyChildOptions(optionsCaptor.capture(), eq(child1));
|
|
229
|
+
assertThat(optionsCaptor.getValue().topBar.title.text.get()).isEqualTo("new title");
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@Test
|
|
234
|
+
public void mergeOptions_initialParentOptionsAreNotMutatedWhenChildAppears() {
|
|
235
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
236
|
+
Options options = new Options();
|
|
237
|
+
options.topBar.title.text = new Text("new title");
|
|
238
|
+
ViewController<?> child1 = spy(new SimpleViewController(activity, childRegistry, "child1", options));
|
|
239
|
+
children.add(child1);
|
|
240
|
+
|
|
241
|
+
uut.ensureViewIsCreated();
|
|
242
|
+
|
|
243
|
+
child1.ensureViewIsCreated();
|
|
244
|
+
child1.onViewWillAppear();
|
|
245
|
+
assertThat(uut.initialOptions.topBar.title.text.get()).isEqualTo(INITIAL_TITLE);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
@Test
|
|
250
|
+
public void resolveCurrentOptions_returnOptionsIfNoChildren() {
|
|
251
|
+
assertThat(uut.getChildControllers().size()).isZero();
|
|
252
|
+
assertThat(uut.resolveCurrentOptions()).isEqualTo(uut.initialOptions);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@Test
|
|
256
|
+
public void resolveCurrentOptions_mergesWithCurrentChild() {
|
|
257
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
258
|
+
ViewController child1 = Mockito.mock(ViewController.class);
|
|
259
|
+
when(child1.getView()).thenReturn(new FrameLayout(activity));
|
|
260
|
+
Options copiedChildOptions = spy(new Options());
|
|
261
|
+
Options childOptions = spy(new Options() {
|
|
262
|
+
@Override
|
|
263
|
+
public Options copy() {
|
|
264
|
+
return copiedChildOptions;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
when(child1.resolveCurrentOptions()).thenReturn(childOptions);
|
|
268
|
+
|
|
269
|
+
children.add(child1);
|
|
270
|
+
|
|
271
|
+
uut.ensureViewIsCreated();
|
|
272
|
+
assertThat(uut.getCurrentChild()).isEqualTo(child1);
|
|
273
|
+
uut.resolveCurrentOptions();
|
|
274
|
+
verify(child1).resolveCurrentOptions();
|
|
275
|
+
verify(copiedChildOptions).withDefaultOptions(uut.initialOptions);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
@Test
|
|
280
|
+
public void resolveCurrentOptions_withDefaultOptions() {
|
|
281
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
282
|
+
SimpleViewController child1 = new SimpleViewController(activity, childRegistry, "child1", new Options());
|
|
283
|
+
children.add(child1);
|
|
284
|
+
uut.ensureViewIsCreated();
|
|
285
|
+
|
|
286
|
+
Options defaultOptions = new Options();
|
|
287
|
+
Options currentOptions = spy(new Options());
|
|
288
|
+
ParentController<?> spy = spy(uut);
|
|
289
|
+
Mockito.when(spy.resolveCurrentOptions()).thenReturn(currentOptions);
|
|
290
|
+
spy.resolveCurrentOptions(defaultOptions);
|
|
291
|
+
verify(currentOptions).withDefaultOptions(defaultOptions);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
@Test
|
|
296
|
+
public void applyTopInset() {
|
|
297
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
298
|
+
children.addAll(createChildren());
|
|
299
|
+
uut.applyTopInset();
|
|
300
|
+
forEach(children, c -> verify(c).applyTopInset());
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@Test
|
|
305
|
+
public void getTopInset() {
|
|
306
|
+
assertThat(uut.getTopInset()).isZero();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
@Test
|
|
310
|
+
public void getTopInsetForChild() {
|
|
311
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
312
|
+
ParentController<?> parent = Mockito.mock(ParentController.class);
|
|
313
|
+
Mockito.when(parent.resolveChildOptions(uut)).thenReturn(Options.EMPTY);
|
|
314
|
+
|
|
315
|
+
when(parent.getTopInset(any())).thenReturn(123);
|
|
316
|
+
uut.setParentController(parent);
|
|
317
|
+
|
|
318
|
+
assertThat(uut.getTopInset(Mockito.mock(ViewController.class))).isEqualTo(123);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
@Test
|
|
323
|
+
public void applyBottomInset() {
|
|
324
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
325
|
+
children.addAll(createChildren());
|
|
326
|
+
uut.applyBottomInset();
|
|
327
|
+
forEach(children, c -> verify(c).applyBottomInset());
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
@Test
|
|
332
|
+
public void getBottomInsetForChild() {
|
|
333
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
|
334
|
+
ParentController<?> parent = Mockito.mock(ParentController.class);
|
|
335
|
+
Mockito.when(parent.resolveChildOptions(uut)).thenReturn(Options.EMPTY);
|
|
336
|
+
|
|
337
|
+
when(parent.getBottomInset(any())).thenReturn(123);
|
|
338
|
+
uut.setParentController(parent);
|
|
339
|
+
|
|
340
|
+
assertThat(uut.getBottomInset(Mockito.mock(ViewController.class))).isEqualTo(123);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private List<ViewController<?>> createChildren() {
|
|
345
|
+
return Arrays.asList(
|
|
346
|
+
spy(new SimpleViewController(activity, childRegistry, "child1", new Options())),
|
|
347
|
+
spy(new SimpleViewController(activity, childRegistry, "child2", new Options())));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package com.reactnativenavigation.views
|
|
2
|
+
|
|
3
|
+
import android.view.ViewGroup
|
|
4
|
+
import android.widget.FrameLayout
|
|
5
|
+
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
|
6
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
7
|
+
import com.reactnativenavigation.TestActivity
|
|
8
|
+
import com.reactnativenavigation.views.stack.topbar.titlebar.TitleSubTitleLayout
|
|
9
|
+
import org.assertj.core.api.AssertionsForInterfaceTypes.assertThat
|
|
10
|
+
import org.junit.Before
|
|
11
|
+
import org.junit.Rule
|
|
12
|
+
import org.junit.Test
|
|
13
|
+
import org.junit.runner.RunWith
|
|
14
|
+
|
|
15
|
+
private const val UUT_WIDTH = 1000
|
|
16
|
+
private const val UUT_HEIGHT = 100
|
|
17
|
+
|
|
18
|
+
@RunWith(AndroidJUnit4::class)
|
|
19
|
+
class TitleSubTitleLayoutTest {
|
|
20
|
+
private val testId = "mock-testId"
|
|
21
|
+
|
|
22
|
+
private lateinit var uut: TitleSubTitleLayout
|
|
23
|
+
|
|
24
|
+
@get:Rule
|
|
25
|
+
val rule = ActivityScenarioRule(TestActivity::class.java)
|
|
26
|
+
|
|
27
|
+
@Before
|
|
28
|
+
fun setup() {
|
|
29
|
+
rule.scenario.onActivity { activity ->
|
|
30
|
+
uut = TitleSubTitleLayout(activity)
|
|
31
|
+
activity.setContentView(FrameLayout(activity).apply {
|
|
32
|
+
addView(uut, ViewGroup.LayoutParams(UUT_WIDTH, UUT_HEIGHT))
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test
|
|
38
|
+
fun shouldSetTestIdCanonically() {
|
|
39
|
+
uut.setTestId(testId)
|
|
40
|
+
assertThat(uut.getTitleTxtView().tag).isEqualTo("$testId.title")
|
|
41
|
+
assertThat(uut.getSubTitleTxtView().tag).isEqualTo("$testId.subtitle")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
fun shouldClearTestId() {
|
|
46
|
+
uut.setTestId(testId)
|
|
47
|
+
uut.setTestId("")
|
|
48
|
+
assertThat(uut.getTitleTxtView().tag).isNull()
|
|
49
|
+
assertThat(uut.getSubTitleTxtView().tag).isNull()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -72,28 +72,6 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
|
|
|
72
72
|
return [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:self];
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
#pragma mark RCTTurboModuleManagerDelegate
|
|
76
|
-
|
|
77
|
-
- (Class)getModuleClassFromName:(const char *)name {
|
|
78
|
-
return RCTCoreModulesClassProvider(name);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
- (std::shared_ptr<facebook::react::TurboModule>)
|
|
82
|
-
getTurboModule:(const std::string &)name
|
|
83
|
-
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker {
|
|
84
|
-
return nullptr;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
- (std::shared_ptr<facebook::react::TurboModule>)
|
|
88
|
-
getTurboModule:(const std::string &)name
|
|
89
|
-
initParams:(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
90
|
-
return nullptr;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass {
|
|
94
|
-
return RCTAppSetupDefaultModuleFromClass(moduleClass, self.dependencyProvider);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
75
|
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
|
|
98
76
|
[NSException raise:@"RCTBridgeDelegate::sourceURLForBridge not implemented"
|
|
99
77
|
format:@"Subclasses must implement a valid sourceURLForBridge method"];
|