Browse Source

Push and Pop always accept a promise (#2514)

Guy Carmeli 6 years ago
parent
commit
abb67a2640
No account linked to committer's email address

+ 0
- 8
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java View File

@@ -26,10 +26,6 @@ public class StackController extends ParentController {
26 26
 		this.animator = animator;
27 27
 	}
28 28
 
29
-	public void push(final ViewController child) {
30
-		push(child, null);
31
-	}
32
-
33 29
 	public void push(final ViewController child, final Promise promise) {
34 30
 		final ViewController previousTop = peek();
35 31
 
@@ -58,10 +54,6 @@ public class StackController extends ParentController {
58 54
 		pop(true, promise);
59 55
 	}
60 56
 
61
-	void pop() {
62
-		pop(true, null);
63
-	}
64
-
65 57
 	private void pop(boolean animate, final Promise promise) {
66 58
 		if (!canPop()) {
67 59
 			Navigator.rejectPromise(promise);

+ 4
- 14
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java View File

@@ -57,12 +57,7 @@ public class BottomTabsControllerTest extends BaseTest {
57 57
         List<ViewController> tabs = createTabs();
58 58
         uut.setTabs(tabs);
59 59
         assertThat(uut.getView().getChildCount()).isEqualTo(6);
60
-        assertThat(uut.getChildControllers()).extracting(new Extractor<ViewController, Integer>() {
61
-            @Override
62
-            public Integer extract(final ViewController input) {
63
-                return input.getView().getVisibility();
64
-            }
65
-        }).containsExactly(View.VISIBLE, View.GONE, View.GONE, View.GONE, View.GONE);
60
+        assertThat(uut.getChildControllers()).extracting((Extractor<ViewController, Integer>) input -> input.getView().getVisibility()).containsExactly(View.VISIBLE, View.GONE, View.GONE, View.GONE, View.GONE);
66 61
     }
67 62
 
68 63
     @Test
@@ -73,12 +68,7 @@ public class BottomTabsControllerTest extends BaseTest {
73 68
         uut.selectTabAtIndex(3);
74 69
 
75 70
         assertThat(uut.getSelectedIndex()).isEqualTo(3);
76
-        assertThat(uut.getChildControllers()).extracting(new Extractor<ViewController, Integer>() {
77
-            @Override
78
-            public Integer extract(final ViewController input) {
79
-                return input.getView().getVisibility();
80
-            }
81
-        }).containsExactly(View.GONE, View.GONE, View.GONE, View.VISIBLE, View.GONE);
71
+        assertThat(uut.getChildControllers()).extracting((Extractor<ViewController, Integer>) input -> input.getView().getVisibility()).containsExactly(View.GONE, View.GONE, View.GONE, View.VISIBLE, View.GONE);
82 72
     }
83 73
 
84 74
     @Test
@@ -86,9 +76,9 @@ public class BottomTabsControllerTest extends BaseTest {
86 76
         assertThat(uut.findControllerById("123")).isNull();
87 77
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
88 78
         StackController inner = new StackController(activity, "inner");
89
-        inner.push(child1);
79
+        inner.push(child1, new MockPromise());
90 80
         assertThat(uut.findControllerById(child1.getId())).isNull();
91
-        uut.setTabs(Arrays.<ViewController>asList(inner));
81
+        uut.setTabs(Collections.singletonList(inner));
92 82
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
93 83
     }
94 84
 

+ 27
- 27
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

@@ -62,7 +62,7 @@ public class NavigatorTest extends BaseTest {
62 62
     @Test
63 63
     public void push() throws Exception {
64 64
         StackController stackController = newStack();
65
-        stackController.push(child1);
65
+        stackController.push(child1, new MockPromise());
66 66
         uut.setRoot(stackController);
67 67
 
68 68
         assertIsChildById(uut.getView(), stackController.getView());
@@ -86,8 +86,8 @@ public class NavigatorTest extends BaseTest {
86 86
         BottomTabsController bottomTabsController = newTabs();
87 87
         StackController stack1 = newStack();
88 88
         StackController stack2 = newStack();
89
-        stack1.push(child1);
90
-        stack2.push(child2);
89
+        stack1.push(child1, new MockPromise());
90
+        stack2.push(child2, new MockPromise());
91 91
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
92 92
         uut.setRoot(bottomTabsController);
93 93
 
@@ -111,10 +111,10 @@ public class NavigatorTest extends BaseTest {
111 111
         BottomTabsController bottomTabsController = newTabs();
112 112
         StackController stack1 = newStack();
113 113
         StackController stack2 = newStack();
114
-        stack1.push(child1);
115
-        stack2.push(child2);
116
-        stack2.push(child3);
117
-        stack2.push(child4);
114
+        stack1.push(child1, new MockPromise());
115
+        stack2.push(child2, new MockPromise());
116
+        stack2.push(child3, new MockPromise());
117
+        stack2.push(child4, new MockPromise());
118 118
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
119 119
         uut.setRoot(bottomTabsController);
120 120
 
@@ -128,10 +128,10 @@ public class NavigatorTest extends BaseTest {
128 128
         BottomTabsController bottomTabsController = newTabs();
129 129
         StackController stack1 = newStack();
130 130
         StackController stack2 = newStack();
131
-        stack1.push(child1);
132
-        stack2.push(child2);
133
-        stack2.push(child3);
134
-        stack2.push(child4);
131
+        stack1.push(child1, new MockPromise());
132
+        stack2.push(child2, new MockPromise());
133
+        stack2.push(child3, new MockPromise());
134
+        stack2.push(child4, new MockPromise());
135 135
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
136 136
         uut.setRoot(bottomTabsController);
137 137
 
@@ -145,11 +145,11 @@ public class NavigatorTest extends BaseTest {
145 145
         BottomTabsController bottomTabsController = newTabs();
146 146
         StackController stack1 = newStack();
147 147
         StackController stack2 = newStack();
148
-        stack1.push(child1);
149
-        stack2.push(child2);
150
-        stack2.push(child3);
151
-        stack2.push(child4);
152
-        stack2.push(child5);
148
+        stack1.push(child1, new MockPromise());
149
+        stack2.push(child2, new MockPromise());
150
+        stack2.push(child3, new MockPromise());
151
+        stack2.push(child4, new MockPromise());
152
+        stack2.push(child5, new MockPromise());
153 153
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
154 154
         uut.setRoot(bottomTabsController);
155 155
 
@@ -163,11 +163,11 @@ public class NavigatorTest extends BaseTest {
163 163
         BottomTabsController bottomTabsController = newTabs();
164 164
         StackController stack1 = newStack();
165 165
         StackController stack2 = newStack();
166
-        stack1.push(child1);
167
-        stack2.push(child2);
168
-        stack2.push(child3);
169
-        stack2.push(child4);
170
-        stack2.push(child5);
166
+        stack1.push(child1, new MockPromise());
167
+        stack2.push(child2, new MockPromise());
168
+        stack2.push(child3, new MockPromise());
169
+        stack2.push(child4, new MockPromise());
170
+        stack2.push(child5, new MockPromise());
171 171
 
172 172
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
173 173
         uut.setRoot(bottomTabsController);
@@ -218,7 +218,7 @@ public class NavigatorTest extends BaseTest {
218 218
     @Test
219 219
     public void push_Promise() throws Exception {
220 220
         final StackController stackController = newStack();
221
-        stackController.push(child1);
221
+        stackController.push(child1, new MockPromise());
222 222
         uut.setRoot(stackController);
223 223
 
224 224
         assertIsChildById(uut.getView(), stackController.getView());
@@ -262,10 +262,10 @@ public class NavigatorTest extends BaseTest {
262 262
         BottomTabsController bottomTabsController = newTabs();
263 263
         StackController stack1 = newStack();
264 264
         final StackController stack2 = newStack();
265
-        stack1.push(child1);
266
-        stack2.push(child2);
267
-        stack2.push(child3);
268
-        stack2.push(child4);
265
+        stack1.push(child1, new MockPromise());
266
+        stack2.push(child2, new MockPromise());
267
+        stack2.push(child3, new MockPromise());
268
+        stack2.push(child4, new MockPromise());
269 269
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
270 270
         uut.setRoot(bottomTabsController);
271 271
 
@@ -280,7 +280,7 @@ public class NavigatorTest extends BaseTest {
280 280
     @Test
281 281
     public void pushIntoModal() throws Exception {
282 282
         StackController stackController = newStack();
283
-        stackController.push(child1);
283
+        stackController.push(child1, new MockPromise());
284 284
         uut.showModal(stackController, new MockPromise());
285 285
         uut.push(stackController.getId(), child2);
286 286
         assertIsChildById(stackController.getView(), child2.getView());

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java View File

@@ -49,7 +49,7 @@ public class OptionsApplyingTest extends BaseTest {
49 49
         assertThat(uut.getOptions()).isSameAs(initialNavigationOptions);
50 50
         initialNavigationOptions.topBarOptions.title = "the title";
51 51
         StackController stackController = new StackController(activity, "stackId");
52
-        stackController.push(uut);
52
+        stackController.push(uut, new MockPromise());
53 53
         assertThat(uut.getTopBar().getTitle()).isEmpty();
54 54
 
55 55
         uut.onViewAppeared();

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java View File

@@ -68,8 +68,8 @@ public class ParentControllerTest extends BaseTest {
68 68
         StackController stackController = new StackController(activity, "stack", new TestNavigationAnimator());
69 69
         SimpleViewController child1 = new SimpleViewController(activity, "child1");
70 70
         SimpleViewController child2 = new SimpleViewController(activity, "child2");
71
-        stackController.push(child1);
72
-        stackController.push(child2);
71
+        stackController.push(child1, new MockPromise());
72
+        stackController.push(child2, new MockPromise());
73 73
         children.add(stackController);
74 74
 
75 75
         assertThat(uut.findControllerById("child2")).isEqualTo(child2);

+ 49
- 54
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java View File

@@ -38,9 +38,9 @@ public class StackControllerTest extends BaseTest {
38 38
     @Test
39 39
     public void holdsAStackOfViewControllers() throws Exception {
40 40
         assertThat(uut.isEmpty()).isTrue();
41
-        uut.push(child1);
42
-        uut.push(child2);
43
-        uut.push(child3);
41
+        uut.push(child1, new MockPromise());
42
+        uut.push(child2, new MockPromise());
43
+        uut.push(child3, new MockPromise());
44 44
         assertThat(uut.peek()).isEqualTo(child3);
45 45
         assertContainsOnlyId(child1.getId(), child2.getId(), child3.getId());
46 46
     }
@@ -48,16 +48,16 @@ public class StackControllerTest extends BaseTest {
48 48
     @Test
49 49
     public void push() throws Exception {
50 50
         assertThat(uut.isEmpty()).isTrue();
51
-        uut.push(child1);
51
+        uut.push(child1, new MockPromise());
52 52
         assertContainsOnlyId(child1.getId());
53 53
     }
54 54
 
55 55
     @Test
56 56
     public void pop() throws Exception {
57
-        uut.push(child1);
58
-        uut.push(child2);
57
+        uut.push(child1, new MockPromise());
58
+        uut.push(child2, new MockPromise());
59 59
         assertContainsOnlyId(child2.getId(), child1.getId());
60
-        uut.pop();
60
+        uut.pop(new MockPromise());
61 61
         assertContainsOnlyId(child1.getId());
62 62
     }
63 63
 
@@ -66,7 +66,7 @@ public class StackControllerTest extends BaseTest {
66 66
         assertThat(uut.peek()).isNull();
67 67
         assertThat(uut.size()).isZero();
68 68
         assertThat(uut.isEmpty()).isTrue();
69
-        uut.push(child1);
69
+        uut.push(child1, new MockPromise());
70 70
         assertThat(uut.peek()).isEqualTo(child1);
71 71
         assertThat(uut.size()).isEqualTo(1);
72 72
         assertThat(uut.isEmpty()).isFalse();
@@ -75,11 +75,11 @@ public class StackControllerTest extends BaseTest {
75 75
     @Test
76 76
     public void pushAssignsRefToSelfOnPushedController() throws Exception {
77 77
         assertThat(child1.getParentStackController()).isNull();
78
-        uut.push(child1);
78
+        uut.push(child1, new MockPromise());
79 79
         assertThat(child1.getParentStackController()).isEqualTo(uut);
80 80
 
81 81
         StackController anotherNavController = new StackController(activity, "another", new TestNavigationAnimator());
82
-        anotherNavController.push(child2);
82
+        anotherNavController.push(child2, new MockPromise());
83 83
         assertThat(child2.getParentStackController()).isEqualTo(anotherNavController);
84 84
     }
85 85
 
@@ -88,11 +88,11 @@ public class StackControllerTest extends BaseTest {
88 88
         assertThat(uut.isEmpty()).isTrue();
89 89
         assertThat(uut.handleBack()).isFalse();
90 90
 
91
-        uut.push(child1);
91
+        uut.push(child1, new MockPromise());
92 92
         assertThat(uut.size()).isEqualTo(1);
93 93
         assertThat(uut.handleBack()).isFalse();
94 94
 
95
-        uut.push(child2);
95
+        uut.push(child2, new MockPromise());
96 96
         assertThat(uut.size()).isEqualTo(2);
97 97
         assertThat(uut.handleBack()).isTrue();
98 98
         assertThat(uut.size()).isEqualTo(1);
@@ -102,11 +102,11 @@ public class StackControllerTest extends BaseTest {
102 102
     @Test
103 103
     public void popDoesNothingWhenZeroOrOneChild() throws Exception {
104 104
         assertThat(uut.isEmpty()).isTrue();
105
-        uut.pop();
105
+        uut.pop(new MockPromise());
106 106
         assertThat(uut.isEmpty()).isTrue();
107 107
 
108
-        uut.push(child1);
109
-        uut.pop();
108
+        uut.push(child1, new MockPromise());
109
+        uut.pop(new MockPromise());
110 110
         assertContainsOnlyId(child1.getId());
111 111
     }
112 112
 
@@ -114,10 +114,10 @@ public class StackControllerTest extends BaseTest {
114 114
     public void canPopWhenSizeIsMoreThanOne() throws Exception {
115 115
         assertThat(uut.isEmpty()).isTrue();
116 116
         assertThat(uut.canPop()).isFalse();
117
-        uut.push(child1);
117
+        uut.push(child1, new MockPromise());
118 118
         assertContainsOnlyId(child1.getId());
119 119
         assertThat(uut.canPop()).isFalse();
120
-        uut.push(child2);
120
+        uut.push(child2, new MockPromise());
121 121
         assertContainsOnlyId(child1.getId(), child2.getId());
122 122
         assertThat(uut.canPop()).isTrue();
123 123
     }
@@ -125,37 +125,37 @@ public class StackControllerTest extends BaseTest {
125 125
     @Test
126 126
     public void pushAddsToViewTree() throws Exception {
127 127
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
128
-        uut.push(child1);
128
+        uut.push(child1, new MockPromise());
129 129
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
130 130
     }
131 131
 
132 132
     @Test
133 133
     public void pushRemovesPreviousFromTree() throws Exception {
134 134
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
135
-        uut.push(child1);
135
+        uut.push(child1, new MockPromise());
136 136
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
137
-        uut.push(child2);
137
+        uut.push(child2, new MockPromise());
138 138
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
139 139
         assertThat(uut.getView().findViewById(child2.getView().getId())).isNotNull();
140 140
     }
141 141
 
142 142
     @Test
143 143
     public void popReplacesViewWithPrevious() throws Exception {
144
-        uut.push(child1);
145
-        uut.push(child2);
144
+        uut.push(child1, new MockPromise());
145
+        uut.push(child2, new MockPromise());
146 146
         final View child2View = child2.getView();
147 147
         final View child1View = child1.getView();
148 148
         assertIsChildById(uut.getView(), child2View);
149 149
         assertNotChildOf(uut.getView(), child1View);
150
-        uut.pop();
150
+        uut.pop(new MockPromise());
151 151
         assertNotChildOf(uut.getView(), child2View);
152 152
         assertIsChildById(uut.getView(), child1View);
153 153
     }
154 154
 
155 155
     @Test
156 156
     public void popSpecificWhenTopIsRegularPop() throws Exception {
157
-        uut.push(child1);
158
-        uut.push(child2);
157
+        uut.push(child1, new MockPromise());
158
+        uut.push(child2, new MockPromise());
159 159
         uut.popSpecific(child2);
160 160
         assertContainsOnlyId(child1.getId());
161 161
         assertIsChildById(uut.getView(), child1.getView());
@@ -163,8 +163,8 @@ public class StackControllerTest extends BaseTest {
163 163
 
164 164
     @Test
165 165
     public void popSpecificDeepInStack() throws Exception {
166
-        uut.push(child1);
167
-        uut.push(child2);
166
+        uut.push(child1, new MockPromise());
167
+        uut.push(child2, new MockPromise());
168 168
         assertIsChildById(uut.getView(), child2.getView());
169 169
         uut.popSpecific(child1);
170 170
         assertContainsOnlyId(child2.getId());
@@ -173,9 +173,9 @@ public class StackControllerTest extends BaseTest {
173 173
 
174 174
     @Test
175 175
     public void popTo_PopsTopUntilControllerIsNewTop() throws Exception {
176
-        uut.push(child1);
177
-        uut.push(child2);
178
-        uut.push(child3);
176
+        uut.push(child1, new MockPromise());
177
+        uut.push(child2, new MockPromise());
178
+        uut.push(child3, new MockPromise());
179 179
 
180 180
         assertThat(uut.size()).isEqualTo(3);
181 181
         assertThat(uut.peek()).isEqualTo(child3);
@@ -188,8 +188,8 @@ public class StackControllerTest extends BaseTest {
188 188
 
189 189
     @Test
190 190
     public void popTo_NotAChildOfThisStack_DoesNothing() throws Exception {
191
-        uut.push(child1);
192
-        uut.push(child3);
191
+        uut.push(child1, new MockPromise());
192
+        uut.push(child3, new MockPromise());
193 193
         assertThat(uut.size()).isEqualTo(2);
194 194
         uut.popTo(child2);
195 195
         assertThat(uut.size()).isEqualTo(2);
@@ -197,9 +197,9 @@ public class StackControllerTest extends BaseTest {
197 197
 
198 198
     @Test
199 199
     public void popToRoot_PopsEverythingAboveFirstController() throws Exception {
200
-        uut.push(child1);
201
-        uut.push(child2);
202
-        uut.push(child3);
200
+        uut.push(child1, new MockPromise());
201
+        uut.push(child2, new MockPromise());
202
+        uut.push(child3, new MockPromise());
203 203
 
204 204
         assertThat(uut.size()).isEqualTo(3);
205 205
         assertThat(uut.peek()).isEqualTo(child3);
@@ -221,15 +221,15 @@ public class StackControllerTest extends BaseTest {
221 221
     public void findControllerById_ReturnsSelfOrChildrenById() throws Exception {
222 222
         assertThat(uut.findControllerById("123")).isNull();
223 223
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
224
-        uut.push(child1);
224
+        uut.push(child1, new MockPromise());
225 225
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
226 226
     }
227 227
 
228 228
     @Test
229 229
     public void findControllerById_Deeply() throws Exception {
230 230
         StackController stack = new StackController(activity, "stack2", new TestNavigationAnimator());
231
-        stack.push(child2);
232
-        uut.push(stack);
231
+        stack.push(child2, new MockPromise());
232
+        uut.push(stack, new MockPromise());
233 233
         assertThat(uut.findControllerById(child2.getId())).isEqualTo(child2);
234 234
     }
235 235
 
@@ -238,12 +238,12 @@ public class StackControllerTest extends BaseTest {
238 238
         child1 = spy(child1);
239 239
         child2 = spy(child2);
240 240
         child3 = spy(child3);
241
-        uut.push(child1);
242
-        uut.push(child2);
243
-        uut.push(child3);
241
+        uut.push(child1, new MockPromise());
242
+        uut.push(child2, new MockPromise());
243
+        uut.push(child3, new MockPromise());
244 244
 
245 245
         verify(child3, times(0)).destroy();
246
-        uut.pop();
246
+        uut.pop(new MockPromise());
247 247
         verify(child3, times(1)).destroy();
248 248
     }
249 249
 
@@ -252,9 +252,9 @@ public class StackControllerTest extends BaseTest {
252 252
         child1 = spy(child1);
253 253
         child2 = spy(child2);
254 254
         child3 = spy(child3);
255
-        uut.push(child1);
256
-        uut.push(child2);
257
-        uut.push(child3);
255
+        uut.push(child1, new MockPromise());
256
+        uut.push(child2, new MockPromise());
257
+        uut.push(child3, new MockPromise());
258 258
 
259 259
         verify(child2, times(0)).destroy();
260 260
         uut.popSpecific(child2);
@@ -266,9 +266,9 @@ public class StackControllerTest extends BaseTest {
266 266
         child1 = spy(child1);
267 267
         child2 = spy(child2);
268 268
         child3 = spy(child3);
269
-        uut.push(child1);
270
-        uut.push(child2);
271
-        uut.push(child3);
269
+        uut.push(child1, new MockPromise());
270
+        uut.push(child2, new MockPromise());
271
+        uut.push(child3, new MockPromise());
272 272
 
273 273
         verify(child2, times(0)).destroy();
274 274
         verify(child3, times(0)).destroy();
@@ -279,11 +279,6 @@ public class StackControllerTest extends BaseTest {
279 279
 
280 280
     private void assertContainsOnlyId(String... ids) {
281 281
         assertThat(uut.size()).isEqualTo(ids.length);
282
-        assertThat(uut.getChildControllers()).extracting(new Extractor<ViewController, String>() {
283
-            @Override
284
-            public String extract(final ViewController input) {
285
-                return input.getId();
286
-            }
287
-        }).containsOnly(ids);
282
+        assertThat(uut.getChildControllers()).extracting((Extractor<ViewController, String>) ViewController::getId).containsOnly(ids);
288 283
     }
289 284
 }

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java View File

@@ -6,6 +6,7 @@ import android.view.ViewParent;
6 6
 import android.widget.LinearLayout;
7 7
 
8 8
 import com.reactnativenavigation.BaseTest;
9
+import com.reactnativenavigation.mocks.MockPromise;
9 10
 import com.reactnativenavigation.mocks.SimpleViewController;
10 11
 
11 12
 import org.assertj.android.api.Assertions;
@@ -58,7 +59,7 @@ public class ViewControllerTest extends BaseTest {
58 59
     public void holdsAReferenceToStackControllerOrNull() throws Exception {
59 60
         assertThat(uut.getParentStackController()).isNull();
60 61
         StackController nav = new StackController(activity, "stack");
61
-        nav.push(uut);
62
+        nav.push(uut, new MockPromise());
62 63
         assertThat(uut.getParentStackController()).isEqualTo(nav);
63 64
     }
64 65