|
@@ -1,7 +1,6 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers.modal;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
4
|
|
-import android.view.ViewGroup;
|
5
|
4
|
import android.widget.FrameLayout;
|
6
|
5
|
|
7
|
6
|
import com.reactnativenavigation.BaseTest;
|
|
@@ -13,11 +12,9 @@ import com.reactnativenavigation.utils.CommandListener;
|
13
|
12
|
import com.reactnativenavigation.utils.CommandListenerAdapter;
|
14
|
13
|
import com.reactnativenavigation.viewcontrollers.ChildController;
|
15
|
14
|
import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
|
16
|
|
-import com.reactnativenavigation.viewcontrollers.ParentController;
|
17
|
15
|
import com.reactnativenavigation.viewcontrollers.ViewController;
|
18
|
16
|
|
19
|
17
|
import org.junit.Test;
|
20
|
|
-import org.mockito.Mockito;
|
21
|
18
|
|
22
|
19
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
23
|
20
|
import static org.mockito.ArgumentMatchers.any;
|
|
@@ -25,7 +22,6 @@ import static org.mockito.ArgumentMatchers.eq;
|
25
|
22
|
import static org.mockito.Mockito.spy;
|
26
|
23
|
import static org.mockito.Mockito.times;
|
27
|
24
|
import static org.mockito.Mockito.verify;
|
28
|
|
-import static org.mockito.Mockito.when;
|
29
|
25
|
|
30
|
26
|
public class ModalPresenterTest extends BaseTest {
|
31
|
27
|
private static final String MODAL_ID_1 = "modalId1";
|
|
@@ -37,18 +33,15 @@ public class ModalPresenterTest extends BaseTest {
|
37
|
33
|
private FrameLayout contentLayout;
|
38
|
34
|
private ModalAnimator animator;
|
39
|
35
|
private ViewController rootController;
|
40
|
|
- private ChildControllersRegistry childRegistry;
|
41
|
36
|
|
42
|
37
|
@Override
|
43
|
38
|
public void beforeEach() {
|
44
|
39
|
Activity activity = newActivity();
|
45
|
|
- childRegistry = new ChildControllersRegistry();
|
|
40
|
+ ChildControllersRegistry childRegistry = new ChildControllersRegistry();
|
46
|
41
|
|
47
|
|
- ViewGroup root = new FrameLayout(activity);
|
48
|
|
- rootController = Mockito.mock(ParentController.class);
|
49
|
|
- when(this.rootController.getView()).then(invocation -> root);
|
|
42
|
+ rootController = spy(new SimpleViewController(activity, childRegistry, "root", new Options()));
|
50
|
43
|
contentLayout = new FrameLayout(activity);
|
51
|
|
- contentLayout.addView(root);
|
|
44
|
+ contentLayout.addView(rootController.getView());
|
52
|
45
|
activity.setContentView(contentLayout);
|
53
|
46
|
|
54
|
47
|
animator = spy(new ModalAnimator(activity));
|
|
@@ -114,7 +107,7 @@ public class ModalPresenterTest extends BaseTest {
|
114
|
107
|
disableShowModalAnimation(modal1);
|
115
|
108
|
|
116
|
109
|
uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
117
|
|
- uut.dismissModal(modal1, rootController, new CommandListenerAdapter() {
|
|
110
|
+ uut.dismissTopModal(modal1, rootController, new CommandListenerAdapter() {
|
118
|
111
|
@Override
|
119
|
112
|
public void onSuccess(String childId) {
|
120
|
113
|
verify(modal1, times(1)).onViewDisappear();
|
|
@@ -130,28 +123,17 @@ public class ModalPresenterTest extends BaseTest {
|
130
|
123
|
modal2.ensureViewIsCreated();
|
131
|
124
|
FrameLayout spy = spy(new FrameLayout(newActivity()));
|
132
|
125
|
uut.setContentLayout(spy);
|
133
|
|
- uut.dismissModal(modal1, modal2, new CommandListenerAdapter());
|
|
126
|
+ uut.dismissTopModal(modal1, modal2, new CommandListenerAdapter());
|
134
|
127
|
verify(spy, times(1)).addView(modal2.getView(), 0);
|
135
|
128
|
}
|
136
|
129
|
|
137
|
|
- @Test
|
138
|
|
- public void dismissModal_onViewBroughtToFront_invokedOnPreviousView() {
|
139
|
|
- disableShowModalAnimation(modal1, modal2);
|
140
|
|
- disableDismissModalAnimation(modal1, modal2);
|
141
|
|
-
|
142
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
143
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
144
|
|
- uut.dismissModal(modal2, modal1, new CommandListenerAdapter());
|
145
|
|
- verify(modal1, times(1)).onViewBroughtToFront();
|
146
|
|
- }
|
147
|
|
-
|
148
|
130
|
@Test
|
149
|
131
|
public void dismissModal_noAnimation() {
|
150
|
132
|
disableShowModalAnimation(modal1);
|
151
|
133
|
disableDismissModalAnimation(modal1);
|
152
|
134
|
|
153
|
135
|
uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
154
|
|
- uut.dismissModal(modal1, rootController, new CommandListenerAdapter());
|
|
136
|
+ uut.dismissTopModal(modal1, rootController, new CommandListenerAdapter());
|
155
|
137
|
verify(modal1, times(1)).onViewDisappear();
|
156
|
138
|
verify(modal1, times(1)).destroy();
|
157
|
139
|
verify(animator, times(0)).dismiss(any(), any());
|
|
@@ -164,10 +146,27 @@ public class ModalPresenterTest extends BaseTest {
|
164
|
146
|
uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
165
|
147
|
uut.showModal(modal2, modal1, new CommandListenerAdapter());
|
166
|
148
|
assertThat(modal1.getView().getParent()).isNull();
|
167
|
|
- uut.dismissModal(modal2, modal1, new CommandListenerAdapter());
|
|
149
|
+ uut.dismissTopModal(modal2, modal1, new CommandListenerAdapter());
|
168
|
150
|
verify(modal1, times(2)).onViewAppeared();
|
169
|
151
|
}
|
170
|
152
|
|
|
153
|
+ @Test
|
|
154
|
+ public void dismissModal_previousControllerIsNotAddedIfDismissedModalIsNotTop() {
|
|
155
|
+ disableShowModalAnimation(modal1, modal2);
|
|
156
|
+ disableDismissModalAnimation(modal1, modal2);
|
|
157
|
+
|
|
158
|
+ uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
159
|
+ uut.showModal(modal2, modal1, new CommandListenerAdapter());
|
|
160
|
+ assertThat(modal1.getView().getParent()).isNull();
|
|
161
|
+ assertThat(rootController.getView().getParent()).isNull();
|
|
162
|
+
|
|
163
|
+ uut.dismissModal(modal1, new CommandListenerAdapter());
|
|
164
|
+ assertThat(rootController.getView().getParent()).isNull();
|
|
165
|
+
|
|
166
|
+ uut.dismissTopModal(modal2, rootController, new CommandListenerAdapter());
|
|
167
|
+ assertThat(rootController.getView().getParent()).isNotNull();
|
|
168
|
+ }
|
|
169
|
+
|
171
|
170
|
@Test
|
172
|
171
|
public void dismissModal_previousViewIsNotDetachedIfOverCurrentContext() {
|
173
|
172
|
modal1.options.modal.presentationStyle = ModalPresentationStyle.OverCurrentContext;
|