|
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.spy;
|
28
|
28
|
import static org.mockito.Mockito.times;
|
29
|
29
|
import static org.mockito.Mockito.verify;
|
30
|
30
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
|
31
|
+import static org.mockito.Mockito.when;
|
31
|
32
|
|
32
|
33
|
public class ModalStackTest extends BaseTest {
|
33
|
34
|
private static final String MODAL_ID_1 = "modalId1";
|
|
@@ -42,22 +43,26 @@ public class ModalStackTest extends BaseTest {
|
42
|
43
|
private ChildControllersRegistry childRegistry;
|
43
|
44
|
private ModalPresenter presenter;
|
44
|
45
|
private ModalAnimator animator;
|
45
|
|
- private ViewController rootController;
|
|
46
|
+ private ViewController root;
|
46
|
47
|
|
47
|
48
|
@Override
|
48
|
49
|
public void beforeEach() {
|
49
|
50
|
activity = newActivity();
|
50
|
51
|
childRegistry = new ChildControllersRegistry();
|
|
52
|
+ root = new SimpleViewController(activity, childRegistry, "root", new Options());
|
51
|
53
|
|
52
|
|
- this.rootController = new SimpleViewController(activity, childRegistry, "root", new Options());
|
53
|
|
- FrameLayout activityContentView = new FrameLayout(activity);
|
54
|
|
- activityContentView.addView(rootController.getView());
|
55
|
|
- activity.setContentView(activityContentView);
|
|
54
|
+ FrameLayout rootLayout = new FrameLayout(activity);
|
|
55
|
+ FrameLayout modalsLayout = new FrameLayout(activity);
|
|
56
|
+ FrameLayout contentLayout = new FrameLayout(activity);
|
|
57
|
+ contentLayout.addView(rootLayout);
|
|
58
|
+ contentLayout.addView(modalsLayout);
|
|
59
|
+ activity.setContentView(contentLayout);
|
56
|
60
|
|
57
|
61
|
animator = spy(new ModalAnimatorMock(activity));
|
58
|
62
|
presenter = spy(new ModalPresenter(animator));
|
59
|
63
|
uut = new ModalStack(presenter);
|
60
|
|
- uut.setModalsContainer(activityContentView);
|
|
64
|
+ uut.setModalsLayout(modalsLayout);
|
|
65
|
+ uut.setRootLayout(rootLayout);
|
61
|
66
|
uut.setEventEmitter(Mockito.mock(EventEmitter.class));
|
62
|
67
|
modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
|
63
|
68
|
modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
|
|
@@ -68,7 +73,7 @@ public class ModalStackTest extends BaseTest {
|
68
|
73
|
public void modalRefIsSaved() {
|
69
|
74
|
disableShowModalAnimation(modal1);
|
70
|
75
|
CommandListener listener = spy(new CommandListenerAdapter());
|
71
|
|
- uut.showModal(modal1, rootController, listener);
|
|
76
|
+ uut.showModal(modal1, root, listener);
|
72
|
77
|
verify(listener, times(1)).onSuccess(modal1.getId());
|
73
|
78
|
assertThat(findModal(MODAL_ID_1)).isNotNull();
|
74
|
79
|
}
|
|
@@ -76,21 +81,21 @@ public class ModalStackTest extends BaseTest {
|
76
|
81
|
@Test
|
77
|
82
|
public void showModal() {
|
78
|
83
|
CommandListener listener = spy(new CommandListenerAdapter());
|
79
|
|
- uut.showModal(modal1, rootController, listener);
|
|
84
|
+ uut.showModal(modal1, root, listener);
|
80
|
85
|
verify(listener, times(1)).onSuccess(modal1.getId());
|
81
|
86
|
assertThat(uut.size()).isOne();
|
82
|
|
- verify(presenter, times(1)).showModal(modal1, rootController, listener);
|
|
87
|
+ verify(presenter, times(1)).showModal(modal1, root, listener);
|
83
|
88
|
assertThat(findModal(MODAL_ID_1)).isNotNull();
|
84
|
89
|
}
|
85
|
90
|
|
86
|
91
|
@SuppressWarnings("Convert2Lambda")
|
87
|
92
|
@Test
|
88
|
93
|
public void dismissModal() {
|
89
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
94
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
90
|
95
|
CommandListener listener = spy(new CommandListenerAdapter());
|
91
|
|
- uut.dismissModal(modal1.getId(), rootController, listener);
|
|
96
|
+ uut.dismissModal(modal1.getId(), root, listener);
|
92
|
97
|
assertThat(findModal(modal1.getId())).isNull();
|
93
|
|
- verify(presenter, times(1)).dismissTopModal(eq(modal1), eq(rootController), any());
|
|
98
|
+ verify(presenter, times(1)).dismissModal(eq(modal1), eq(root), eq(root), any());
|
94
|
99
|
verify(listener).onSuccess(modal1.getId());
|
95
|
100
|
}
|
96
|
101
|
|
|
@@ -104,7 +109,7 @@ public class ModalStackTest extends BaseTest {
|
104
|
109
|
|
105
|
110
|
}
|
106
|
111
|
});
|
107
|
|
- uut.dismissModal(MODAL_ID_1, rootController, listener);
|
|
112
|
+ uut.dismissModal(MODAL_ID_1, root, listener);
|
108
|
113
|
verify(onModalWillDismiss, times(0)).run();
|
109
|
114
|
verify(listener, times(1)).onError(anyString());
|
110
|
115
|
verifyZeroInteractions(listener);
|
|
@@ -115,24 +120,24 @@ public class ModalStackTest extends BaseTest {
|
115
|
120
|
disableShowModalAnimation(modal1, modal2, modal3);
|
116
|
121
|
disableDismissModalAnimation(modal1, modal2, modal3);
|
117
|
122
|
|
118
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
119
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
120
|
|
- uut.showModal(modal3, rootController, new CommandListenerAdapter());
|
|
123
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
124
|
+ uut.showModal(modal2, root, new CommandListenerAdapter());
|
|
125
|
+ uut.showModal(modal3, root, new CommandListenerAdapter());
|
121
|
126
|
|
122
|
|
- assertThat(rootController.getView().getParent()).isNull();
|
123
|
|
- uut.dismissModal(modal1.getId(), rootController, new CommandListenerAdapter());
|
124
|
|
- assertThat(rootController.getView().getParent()).isNull();
|
|
127
|
+ assertThat(root.getView().getParent()).isNull();
|
|
128
|
+ uut.dismissModal(modal1.getId(), root, new CommandListenerAdapter());
|
|
129
|
+ assertThat(root.getView().getParent()).isNull();
|
125
|
130
|
|
126
|
|
- uut.dismissModal(modal3.getId(), rootController, new CommandListenerAdapter());
|
127
|
|
- uut.dismissModal(modal2.getId(), rootController, new CommandListenerAdapter());
|
128
|
|
- assertThat(rootController.getView().getParent()).isNotNull();
|
129
|
|
- assertThat(rootController.getView().isShown()).isTrue();
|
|
131
|
+ uut.dismissModal(modal3.getId(), root, new CommandListenerAdapter());
|
|
132
|
+ uut.dismissModal(modal2.getId(), root, new CommandListenerAdapter());
|
|
133
|
+ assertThat(root.getView().getParent()).isNotNull();
|
|
134
|
+ assertThat(root.getView().isShown()).isTrue();
|
130
|
135
|
}
|
131
|
136
|
|
132
|
137
|
@Test
|
133
|
138
|
public void dismissAllModals() {
|
134
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
135
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
|
139
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
140
|
+ uut.showModal(modal2, root, new CommandListenerAdapter());
|
136
|
141
|
CommandListener listener = spy(new CommandListenerAdapter() {
|
137
|
142
|
@Override
|
138
|
143
|
public void onSuccess(String childId) {
|
|
@@ -141,7 +146,7 @@ public class ModalStackTest extends BaseTest {
|
141
|
146
|
assertThat(uut.isEmpty()).isTrue();
|
142
|
147
|
}
|
143
|
148
|
});
|
144
|
|
- uut.dismissAllModals(rootController, Options.EMPTY, listener);
|
|
149
|
+ uut.dismissAllModals(root, Options.EMPTY, listener);
|
145
|
150
|
verify(listener, times(1)).onSuccess(anyString());
|
146
|
151
|
verifyZeroInteractions(listener);
|
147
|
152
|
}
|
|
@@ -149,18 +154,18 @@ public class ModalStackTest extends BaseTest {
|
149
|
154
|
@Test
|
150
|
155
|
public void dismissAllModals_rejectIfEmpty() {
|
151
|
156
|
CommandListener spy = spy(new CommandListenerAdapter());
|
152
|
|
- uut.dismissAllModals(rootController, Options.EMPTY, spy);
|
|
157
|
+ uut.dismissAllModals(root, Options.EMPTY, spy);
|
153
|
158
|
verify(spy, times(1)).onError(any());
|
154
|
159
|
}
|
155
|
160
|
|
156
|
161
|
@Test
|
157
|
162
|
public void dismissAllModals_optionsAreMergedOnTopModal() {
|
158
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
159
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
160
|
|
- uut.showModal(modal3, rootController, new CommandListenerAdapter());
|
|
163
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
164
|
+ uut.showModal(modal2, root, new CommandListenerAdapter());
|
|
165
|
+ uut.showModal(modal3, root, new CommandListenerAdapter());
|
161
|
166
|
|
162
|
167
|
Options mergeOptions = new Options();
|
163
|
|
- uut.dismissAllModals(rootController, mergeOptions, new CommandListenerAdapter());
|
|
168
|
+ uut.dismissAllModals(root, mergeOptions, new CommandListenerAdapter());
|
164
|
169
|
verify(modal3).mergeOptions(mergeOptions);
|
165
|
170
|
verify(modal1, times(0)).mergeOptions(mergeOptions);
|
166
|
171
|
verify(modal2, times(0)).mergeOptions(mergeOptions);
|
|
@@ -169,26 +174,31 @@ public class ModalStackTest extends BaseTest {
|
169
|
174
|
@SuppressWarnings("Convert2Lambda")
|
170
|
175
|
@Test
|
171
|
176
|
public void dismissAllModals_onlyTopModalIsAnimated() {
|
172
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
173
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
|
177
|
+ modal2 = spy(modal2);
|
|
178
|
+ Options defaultOptions = new Options();
|
|
179
|
+ uut.setDefaultOptions(defaultOptions);
|
|
180
|
+ Options resolvedOptions = new Options();
|
|
181
|
+ when(modal2.resolveCurrentOptions(defaultOptions)).then(invocation -> resolvedOptions);
|
|
182
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
183
|
+ uut.showModal(modal2, root, new CommandListenerAdapter());
|
174
|
184
|
|
175
|
185
|
ViewGroup view1 = modal1.getView();
|
176
|
186
|
ViewGroup view2 = modal2.getView();
|
177
|
187
|
CommandListener listener = spy(new CommandListenerAdapter());
|
178
|
|
- uut.dismissAllModals(rootController, Options.EMPTY, listener);
|
179
|
|
- verify(presenter, times(1)).dismissTopModal(eq(modal2), eq(rootController), any());
|
|
188
|
+ uut.dismissAllModals(root, Options.EMPTY, listener);
|
|
189
|
+ verify(presenter).dismissModal(eq(modal2), eq(root), eq(root), any());
|
180
|
190
|
verify(listener).onSuccess(modal2.getId());
|
181
|
191
|
verify(animator, times(0)).dismiss(eq(view1), eq(modal1.options.animations.dismissModal), any());
|
182
|
|
- verify(animator, times(1)).dismiss(eq(view2), eq(modal2.options.animations.dismissModal), any());
|
|
192
|
+ verify(animator).dismiss(eq(view2), eq(resolvedOptions.animations.dismissModal), any());
|
183
|
193
|
assertThat(uut.size()).isEqualTo(0);
|
184
|
194
|
}
|
185
|
195
|
|
186
|
196
|
@Test
|
187
|
197
|
public void dismissAllModals_bottomModalsAreDestroyed() {
|
188
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
189
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
|
198
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
199
|
+ uut.showModal(modal2, root, new CommandListenerAdapter());
|
190
|
200
|
|
191
|
|
- uut.dismissAllModals(rootController, Options.EMPTY, new CommandListenerAdapter());
|
|
201
|
+ uut.dismissAllModals(root, Options.EMPTY, new CommandListenerAdapter());
|
192
|
202
|
|
193
|
203
|
verify(modal1, times(1)).destroy();
|
194
|
204
|
verify(modal1, times(1)).onViewDisappear();
|
|
@@ -198,9 +208,9 @@ public class ModalStackTest extends BaseTest {
|
198
|
208
|
@Test
|
199
|
209
|
public void isEmpty() {
|
200
|
210
|
assertThat(uut.isEmpty()).isTrue();
|
201
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
|
211
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
202
|
212
|
assertThat(uut.isEmpty()).isFalse();
|
203
|
|
- uut.dismissAllModals(rootController, Options.EMPTY, new CommandListenerAdapter());
|
|
213
|
+ uut.dismissAllModals(root, Options.EMPTY, new CommandListenerAdapter());
|
204
|
214
|
assertThat(uut.isEmpty()).isTrue();
|
205
|
215
|
}
|
206
|
216
|
|
|
@@ -208,7 +218,7 @@ public class ModalStackTest extends BaseTest {
|
208
|
218
|
public void peek() {
|
209
|
219
|
assertThat(uut.isEmpty()).isTrue();
|
210
|
220
|
assertThatThrownBy(() -> uut.peek()).isInstanceOf(EmptyStackException.class);
|
211
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter() {
|
|
221
|
+ uut.showModal(modal1, root, new CommandListenerAdapter() {
|
212
|
222
|
@Override
|
213
|
223
|
public void onSuccess(String childId) {
|
214
|
224
|
assertThat(uut.peek()).isEqualTo(modal1);
|
|
@@ -220,9 +230,9 @@ public class ModalStackTest extends BaseTest {
|
220
|
230
|
public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
|
221
|
231
|
disableShowModalAnimation(modal1, modal2);
|
222
|
232
|
|
223
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
224
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
225
|
|
- uut.dismissModal(modal2.getId(), rootController, new CommandListenerAdapter());
|
|
233
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
234
|
+ uut.showModal(modal2, root, new CommandListenerAdapter());
|
|
235
|
+ uut.dismissModal(modal2.getId(), root, new CommandListenerAdapter());
|
226
|
236
|
verify(modal1, times(2)).onViewAppeared();
|
227
|
237
|
}
|
228
|
238
|
|
|
@@ -231,11 +241,11 @@ public class ModalStackTest extends BaseTest {
|
231
|
241
|
disableShowModalAnimation(modal1, modal2, modal3);
|
232
|
242
|
disableDismissModalAnimation(modal1, modal2, modal3);
|
233
|
243
|
|
234
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
235
|
|
- uut.showModal(modal2, rootController, new CommandListenerAdapter());
|
236
|
|
- uut.showModal(modal3, rootController, new CommandListenerAdapter());
|
|
244
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
245
|
+ uut.showModal(modal2, root, new CommandListenerAdapter());
|
|
246
|
+ uut.showModal(modal3, root, new CommandListenerAdapter());
|
237
|
247
|
|
238
|
|
- uut.dismissModal(modal2.getId(), rootController, new CommandListenerAdapter());
|
|
248
|
+ uut.dismissModal(modal2.getId(), root, new CommandListenerAdapter());
|
239
|
249
|
assertThat(uut.size()).isEqualTo(2);
|
240
|
250
|
verify(modal2, times(1)).onViewDisappear();
|
241
|
251
|
verify(modal2, times(1)).destroy();
|
|
@@ -245,14 +255,14 @@ public class ModalStackTest extends BaseTest {
|
245
|
255
|
@Test
|
246
|
256
|
public void handleBack_doesNothingIfModalStackIsEmpty() {
|
247
|
257
|
assertThat(uut.isEmpty()).isTrue();
|
248
|
|
- assertThat(uut.handleBack(new CommandListenerAdapter(), rootController)).isFalse();
|
|
258
|
+ assertThat(uut.handleBack(new CommandListenerAdapter(), root)).isFalse();
|
249
|
259
|
}
|
250
|
260
|
|
251
|
261
|
@Test
|
252
|
262
|
public void handleBack_dismissModal() {
|
253
|
263
|
disableDismissModalAnimation(modal1);
|
254
|
|
- uut.showModal(modal1, rootController, new CommandListenerAdapter());
|
255
|
|
- assertThat(uut.handleBack(new CommandListenerAdapter(), rootController)).isTrue();
|
|
264
|
+ uut.showModal(modal1, root, new CommandListenerAdapter());
|
|
265
|
+ assertThat(uut.handleBack(new CommandListenerAdapter(), root)).isTrue();
|
256
|
266
|
verify(modal1, times(1)).onViewDisappear();
|
257
|
267
|
|
258
|
268
|
}
|
|
@@ -265,9 +275,9 @@ public class ModalStackTest extends BaseTest {
|
265
|
275
|
return true;
|
266
|
276
|
}
|
267
|
277
|
});
|
268
|
|
- uut.showModal(backHandlingModal, rootController, new CommandListenerAdapter());
|
|
278
|
+ uut.showModal(backHandlingModal, root, new CommandListenerAdapter());
|
269
|
279
|
|
270
|
|
- rootController.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
280
|
+ root.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
271
|
281
|
|
272
|
282
|
assertThat(uut.handleBack(new CommandListenerAdapter(), any())).isTrue();
|
273
|
283
|
verify(backHandlingModal, times(1)).handleBack(any());
|
|
@@ -301,6 +311,6 @@ public class ModalStackTest extends BaseTest {
|
301
|
311
|
|
302
|
312
|
private void showModalWithoutAnimation(ViewController modal) {
|
303
|
313
|
disableShowModalAnimation(modal);
|
304
|
|
- uut.showModal(modal, rootController, new CommandListenerAdapter());
|
|
314
|
+ uut.showModal(modal, root, new CommandListenerAdapter());
|
305
|
315
|
}
|
306
|
316
|
}
|