Browse Source

Test SideMenuController delegate handleBack to center controller

Guy Carmeli 6 years ago
parent
commit
64de774571

+ 16
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/sidemenu/SideMenuControllerTest.java View File

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 import android.content.res.Resources;
4
 import android.content.res.Resources;
5
-import android.view.ViewGroup.LayoutParams;
6
 import android.util.TypedValue;
5
 import android.util.TypedValue;
7
 import android.view.Gravity;
6
 import android.view.Gravity;
7
+import android.view.ViewGroup.LayoutParams;
8
 
8
 
9
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.BaseTest;
10
 import com.reactnativenavigation.mocks.SimpleComponentViewController;
10
 import com.reactnativenavigation.mocks.SimpleComponentViewController;
21
 
21
 
22
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
22
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
23
 import static org.assertj.core.api.Java6Assertions.assertThat;
23
 import static org.assertj.core.api.Java6Assertions.assertThat;
24
+import static org.mockito.ArgumentMatchers.any;
24
 import static org.mockito.Mockito.spy;
25
 import static org.mockito.Mockito.spy;
26
+import static org.mockito.Mockito.times;
25
 import static org.mockito.Mockito.verify;
27
 import static org.mockito.Mockito.verify;
26
 
28
 
27
 @SuppressWarnings("MagicNumber")
29
 @SuppressWarnings("MagicNumber")
30
     private Activity activity;
32
     private Activity activity;
31
     private ChildControllersRegistry childRegistry;
33
     private ChildControllersRegistry childRegistry;
32
     private SideMenuOptionsPresenter presenter;
34
     private SideMenuOptionsPresenter presenter;
35
+    private SimpleComponentViewController left;
36
+    private SimpleComponentViewController right;
37
+    private SimpleComponentViewController center;
33
 
38
 
34
     @Override
39
     @Override
35
     public void beforeEach() {
40
     public void beforeEach() {
36
         activity = newActivity();
41
         activity = newActivity();
37
         childRegistry = new ChildControllersRegistry();
42
         childRegistry = new ChildControllersRegistry();
38
         presenter = spy(new SideMenuOptionsPresenter());
43
         presenter = spy(new SideMenuOptionsPresenter());
44
+        left = new SimpleComponentViewController(activity, childRegistry, "left", new Options());
45
+        right = new SimpleComponentViewController(activity, childRegistry, "right", new Options());
46
+        center = spy(new SimpleComponentViewController(activity, childRegistry, "center", new Options()));
39
         uut = new SideMenuController(activity, childRegistry, "sideMenu", new Options(), presenter, new OptionsPresenter(activity, new Options()));
47
         uut = new SideMenuController(activity, childRegistry, "sideMenu", new Options(), presenter, new OptionsPresenter(activity, new Options()));
48
+        uut.setCenterController(center);
40
     }
49
     }
41
 
50
 
42
     @Test
51
     @Test
140
 
149
 
141
     @Test
150
     @Test
142
     public void handleBack_closesLeftMenu() {
151
     public void handleBack_closesLeftMenu() {
143
-        uut.setLeftController(new SimpleComponentViewController(activity, childRegistry, "left", new Options()));
152
+        uut.setLeftController(left);
144
         assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
153
         assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
154
+        verify(center, times(1)).handleBack(any());
145
 
155
 
146
         uut.mergeOptions(SideMenuTestHelper.LEFT_OPEN);
156
         uut.mergeOptions(SideMenuTestHelper.LEFT_OPEN);
147
         assertThat(uut.handleBack(new CommandListenerAdapter())).isTrue();
157
         assertThat(uut.handleBack(new CommandListenerAdapter())).isTrue();
158
+        verify(center, times(1)).handleBack(any());
148
     }
159
     }
149
 
160
 
150
     @Test
161
     @Test
151
     public void handleBack_closesRightMenu() {
162
     public void handleBack_closesRightMenu() {
152
-        uut.setRightController(new SimpleComponentViewController(activity, childRegistry, "right", new Options()));
163
+        uut.setRightController(right);
153
         assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
164
         assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
165
+        verify(center, times(1)).handleBack(any());
154
 
166
 
155
         uut.mergeOptions(SideMenuTestHelper.RIGHT_OPEN);
167
         uut.mergeOptions(SideMenuTestHelper.RIGHT_OPEN);
156
         assertThat(uut.handleBack(new CommandListenerAdapter())).isTrue();
168
         assertThat(uut.handleBack(new CommandListenerAdapter())).isTrue();
169
+        verify(center, times(1)).handleBack(any());
157
     }
170
     }
158
 }
171
 }