|
@@ -10,9 +10,11 @@ import com.reactnativenavigation.mocks.SimpleViewController;
|
10
|
10
|
import com.reactnativenavigation.parse.Options;
|
11
|
11
|
import com.reactnativenavigation.utils.CommandListenerAdapter;
|
12
|
12
|
import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
|
|
13
|
+import com.reactnativenavigation.viewcontrollers.ParentController;
|
13
|
14
|
import com.reactnativenavigation.viewcontrollers.ViewController;
|
14
|
15
|
|
15
|
16
|
import org.junit.Test;
|
|
17
|
+import org.mockito.Mockito;
|
16
|
18
|
|
17
|
19
|
import java.util.EmptyStackException;
|
18
|
20
|
|
|
@@ -25,6 +27,7 @@ import static org.mockito.Mockito.spy;
|
25
|
27
|
import static org.mockito.Mockito.times;
|
26
|
28
|
import static org.mockito.Mockito.verify;
|
27
|
29
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
|
30
|
+import static org.mockito.Mockito.when;
|
28
|
31
|
|
29
|
32
|
public class ModalStackTest extends BaseTest {
|
30
|
33
|
private static final String MODAL_ID_1 = "modalId1";
|
|
@@ -38,16 +41,23 @@ public class ModalStackTest extends BaseTest {
|
38
|
41
|
private Activity activity;
|
39
|
42
|
private ModalPresenter presenter;
|
40
|
43
|
private ModalAnimator animator;
|
|
44
|
+ private ViewController rootController;
|
41
|
45
|
|
42
|
46
|
@Override
|
43
|
47
|
public void beforeEach() {
|
44
|
48
|
activity = newActivity();
|
|
49
|
+
|
45
|
50
|
ViewGroup root = new FrameLayout(activity);
|
46
|
|
- activity.setContentView(root);
|
|
51
|
+ rootController = Mockito.mock(ParentController.class);
|
|
52
|
+ when(this.rootController.getView()).then(invocation -> root);
|
|
53
|
+ FrameLayout activityContentView = new FrameLayout(activity);
|
|
54
|
+ activityContentView.addView(root);
|
|
55
|
+ activity.setContentView(activityContentView);
|
|
56
|
+
|
47
|
57
|
animator = spy(new ModalAnimatorMock(activity));
|
48
|
58
|
presenter = spy(new ModalPresenter(animator));
|
49
|
59
|
uut = new ModalStack(presenter);
|
50
|
|
- uut.setContentLayout(root);
|
|
60
|
+ uut.setContentLayout(activityContentView);
|
51
|
61
|
modal1 = spy(new SimpleViewController(activity, MODAL_ID_1, new Options()));
|
52
|
62
|
modal2 = spy(new SimpleViewController(activity, MODAL_ID_2, new Options()));
|
53
|
63
|
modal3 = spy(new SimpleViewController(activity, MODAL_ID_3, new Options()));
|
|
@@ -57,7 +67,7 @@ public class ModalStackTest extends BaseTest {
|
57
|
67
|
public void modalRefIsSaved() {
|
58
|
68
|
disableShowModalAnimation(modal1);
|
59
|
69
|
CommandListener listener = spy(new CommandListenerAdapter());
|
60
|
|
- uut.showModal(modal1, listener);
|
|
70
|
+ uut.showModal(modal1, rootController, listener);
|
61
|
71
|
verify(listener, times(1)).onSuccess(modal1.getId());
|
62
|
72
|
assertThat(findModal(MODAL_ID_1)).isNotNull();
|
63
|
73
|
}
|
|
@@ -65,17 +75,17 @@ public class ModalStackTest extends BaseTest {
|
65
|
75
|
@Test
|
66
|
76
|
public void showModal() {
|
67
|
77
|
CommandListener listener = spy(new CommandListenerAdapter());
|
68
|
|
- uut.showModal(modal1, listener);
|
|
78
|
+ uut.showModal(modal1, rootController, listener);
|
69
|
79
|
verify(listener, times(1)).onSuccess(modal1.getId());
|
70
|
80
|
assertThat(uut.size()).isOne();
|
71
|
|
- verify(presenter, times(1)).showModal(modal1, null, listener);
|
|
81
|
+ verify(presenter, times(1)).showModal(modal1, rootController, listener);
|
72
|
82
|
assertThat(findModal(MODAL_ID_1)).isNotNull();
|
73
|
83
|
}
|
74
|
84
|
|
75
|
85
|
@SuppressWarnings("Convert2Lambda")
|
76
|
86
|
@Test
|
77
|
87
|
public void dismissModal() {
|
78
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
|
88
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
79
|
89
|
CommandListener listener = new CommandListenerAdapter();
|
80
|
90
|
Runnable onModalWillDismiss = spy(new Runnable() {
|
81
|
91
|
@Override
|
|
@@ -107,8 +117,8 @@ public class ModalStackTest extends BaseTest {
|
107
|
117
|
|
108
|
118
|
@Test
|
109
|
119
|
public void dismissAllModals() {
|
110
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
111
|
|
- uut.showModal(modal2, new CommandListenerAdapter());
|
|
120
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
121
|
+ uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
112
|
122
|
CommandListener listener = spy(new CommandListenerAdapter() {
|
113
|
123
|
@Override
|
114
|
124
|
public void onSuccess(String childId) {
|
|
@@ -132,8 +142,8 @@ public class ModalStackTest extends BaseTest {
|
132
|
142
|
@SuppressWarnings("Convert2Lambda")
|
133
|
143
|
@Test
|
134
|
144
|
public void dismissAllModals_onlyTopModalIsAnimated() {
|
135
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
136
|
|
- uut.showModal(modal2, new CommandListenerAdapter());
|
|
145
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
146
|
+ uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
137
|
147
|
|
138
|
148
|
ViewGroup view1 = modal1.getView();
|
139
|
149
|
ViewGroup view2 = modal2.getView();
|
|
@@ -154,8 +164,8 @@ public class ModalStackTest extends BaseTest {
|
154
|
164
|
|
155
|
165
|
@Test
|
156
|
166
|
public void dismissAllModals_bottomModalsAreDestroyed() {
|
157
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
158
|
|
- uut.showModal(modal2, new CommandListenerAdapter());
|
|
167
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
168
|
+ uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
159
|
169
|
|
160
|
170
|
uut.dismissAllModals(new CommandListenerAdapter(), () -> {});
|
161
|
171
|
|
|
@@ -167,7 +177,7 @@ public class ModalStackTest extends BaseTest {
|
167
|
177
|
@Test
|
168
|
178
|
public void isEmpty() {
|
169
|
179
|
assertThat(uut.isEmpty()).isTrue();
|
170
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
|
180
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
171
|
181
|
assertThat(uut.isEmpty()).isFalse();
|
172
|
182
|
uut.dismissAllModals(new CommandListenerAdapter(), () -> {});
|
173
|
183
|
assertThat(uut.isEmpty()).isTrue();
|
|
@@ -177,7 +187,7 @@ public class ModalStackTest extends BaseTest {
|
177
|
187
|
public void peek() {
|
178
|
188
|
assertThat(uut.isEmpty()).isTrue();
|
179
|
189
|
assertThatThrownBy(() -> uut.peek()).isInstanceOf(EmptyStackException.class);
|
180
|
|
- uut.showModal(modal1, new CommandListenerAdapter() {
|
|
190
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter() {
|
181
|
191
|
@Override
|
182
|
192
|
public void onSuccess(String childId) {
|
183
|
193
|
assertThat(uut.peek()).isEqualTo(modal1);
|
|
@@ -189,8 +199,8 @@ public class ModalStackTest extends BaseTest {
|
189
|
199
|
public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
|
190
|
200
|
disableShowModalAnimation(modal1, modal2);
|
191
|
201
|
|
192
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
193
|
|
- uut.showModal(modal2, new CommandListenerAdapter());
|
|
202
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
203
|
+ uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
194
|
204
|
uut.dismissModal(modal2.getId(), () -> {}, new CommandListenerAdapter());
|
195
|
205
|
verify(modal1, times(2)).onViewAppeared();
|
196
|
206
|
}
|
|
@@ -200,9 +210,9 @@ public class ModalStackTest extends BaseTest {
|
200
|
210
|
disableShowModalAnimation(modal1, modal2, modal3);
|
201
|
211
|
disableDismissModalAnimation(modal1, modal2, modal3);
|
202
|
212
|
|
203
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
204
|
|
- uut.showModal(modal2, new CommandListenerAdapter());
|
205
|
|
- uut.showModal(modal3, new CommandListenerAdapter());
|
|
213
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
214
|
+ uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
|
215
|
+ uut.showModal(modal3, rootController, new CommandListenerAdapter());
|
206
|
216
|
|
207
|
217
|
uut.dismissModal(modal2.getId(), () -> {}, new CommandListenerAdapter());
|
208
|
218
|
assertThat(uut.size()).isEqualTo(2);
|
|
@@ -220,7 +230,7 @@ public class ModalStackTest extends BaseTest {
|
220
|
230
|
@Test
|
221
|
231
|
public void handleBack_dismissModal() {
|
222
|
232
|
disableDismissModalAnimation(modal1);
|
223
|
|
- uut.showModal(modal1, new CommandListenerAdapter());
|
|
233
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
224
|
234
|
assertThat(uut.handleBack(new CommandListenerAdapter(), () -> {})).isTrue();
|
225
|
235
|
verify(modal1, times(1)).onViewDisappear();
|
226
|
236
|
|
|
@@ -234,7 +244,10 @@ public class ModalStackTest extends BaseTest {
|
234
|
244
|
return true;
|
235
|
245
|
}
|
236
|
246
|
});
|
237
|
|
- uut.showModal(backHandlingModal, new CommandListenerAdapter());
|
|
247
|
+ uut.showModal(backHandlingModal, rootController, new CommandListenerAdapter());
|
|
248
|
+
|
|
249
|
+ rootController.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
250
|
+
|
238
|
251
|
assertThat(uut.handleBack(new CommandListenerAdapter(), any())).isTrue();
|
239
|
252
|
verify(backHandlingModal, times(1)).handleBack(any());
|
240
|
253
|
verify(backHandlingModal, times(0)).onViewDisappear();
|