|
@@ -2,13 +2,20 @@ package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
4
|
4
|
import android.view.View;
|
|
5
|
+import android.view.ViewParent;
|
5
|
6
|
|
6
|
7
|
import com.reactnativenavigation.BaseTest;
|
7
|
8
|
import com.reactnativenavigation.mocks.SimpleViewController;
|
8
|
9
|
|
|
10
|
+import org.assertj.android.api.Assertions;
|
9
|
11
|
import org.junit.Test;
|
|
12
|
+import org.robolectric.Shadows;
|
10
|
13
|
|
11
|
14
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
15
|
+import static org.mockito.Mockito.mock;
|
|
16
|
+import static org.mockito.Mockito.spy;
|
|
17
|
+import static org.mockito.Mockito.times;
|
|
18
|
+import static org.mockito.Mockito.verify;
|
12
|
19
|
|
13
|
20
|
public class ViewControllerTest extends BaseTest {
|
14
|
21
|
|
|
@@ -74,4 +81,21 @@ public class ViewControllerTest extends BaseTest {
|
74
|
81
|
assertThat(uut.findControllerById("456")).isNull();
|
75
|
82
|
assertThat(uut.findControllerById("uut")).isEqualTo(uut);
|
76
|
83
|
}
|
|
84
|
+
|
|
85
|
+ @Test
|
|
86
|
+ public void onAppear_WhenVisibleOnScreen() throws Exception {
|
|
87
|
+ ViewController spy = spy(uut);
|
|
88
|
+ spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
89
|
+ Assertions.assertThat(spy.getView()).isNotShown();
|
|
90
|
+ verify(spy, times(0)).onAppear();
|
|
91
|
+
|
|
92
|
+ Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
|
93
|
+ spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
94
|
+ Assertions.assertThat(spy.getView()).isShown();
|
|
95
|
+
|
|
96
|
+ verify(spy, times(1)).onAppear();
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+
|
77
|
100
|
}
|
|
101
|
+
|