|
@@ -5,10 +5,10 @@ import android.content.Context;
|
5
|
5
|
import android.graphics.Typeface;
|
6
|
6
|
import android.view.Gravity;
|
7
|
7
|
import android.view.View;
|
8
|
|
-import android.view.ViewGroup;
|
9
|
8
|
|
10
|
9
|
import com.reactnativenavigation.BaseTest;
|
11
|
10
|
import com.reactnativenavigation.TestUtils;
|
|
11
|
+import com.reactnativenavigation.mocks.BackDrawable;
|
12
|
12
|
import com.reactnativenavigation.mocks.ImageLoaderMock;
|
13
|
13
|
import com.reactnativenavigation.mocks.Mocks;
|
14
|
14
|
import com.reactnativenavigation.mocks.SimpleViewController;
|
|
@@ -29,7 +29,10 @@ import com.reactnativenavigation.parse.params.Number;
|
29
|
29
|
import com.reactnativenavigation.parse.params.Text;
|
30
|
30
|
import com.reactnativenavigation.presentation.RenderChecker;
|
31
|
31
|
import com.reactnativenavigation.presentation.StackPresenter;
|
|
32
|
+import com.reactnativenavigation.utils.CommandListenerAdapter;
|
32
|
33
|
import com.reactnativenavigation.utils.TitleBarHelper;
|
|
34
|
+import com.reactnativenavigation.utils.UiUtils;
|
|
35
|
+import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver;
|
33
|
36
|
import com.reactnativenavigation.viewcontrollers.stack.StackController;
|
34
|
37
|
import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
|
35
|
38
|
import com.reactnativenavigation.views.StackLayout;
|
|
@@ -39,6 +42,8 @@ import com.reactnativenavigation.views.topbar.TopBar;
|
39
|
42
|
import org.json.JSONObject;
|
40
|
43
|
import org.junit.Test;
|
41
|
44
|
import org.mockito.ArgumentCaptor;
|
|
45
|
+import org.robolectric.annotation.LooperMode;
|
|
46
|
+import org.robolectric.shadows.ShadowLooper;
|
42
|
47
|
|
43
|
48
|
import java.util.ArrayList;
|
44
|
49
|
import java.util.Collection;
|
|
@@ -47,6 +52,7 @@ import java.util.List;
|
47
|
52
|
|
48
|
53
|
import androidx.appcompat.widget.ActionMenuView;
|
49
|
54
|
import androidx.appcompat.widget.Toolbar;
|
|
55
|
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
50
|
56
|
|
51
|
57
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
52
|
58
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
@@ -62,6 +68,7 @@ import static org.mockito.Mockito.times;
|
62
|
68
|
import static org.mockito.Mockito.verify;
|
63
|
69
|
import static org.mockito.Mockito.when;
|
64
|
70
|
|
|
71
|
+@LooperMode(LooperMode.Mode.PAUSED)
|
65
|
72
|
public class StackPresenterTest extends BaseTest {
|
66
|
73
|
|
67
|
74
|
private static final Options EMPTY_OPTIONS = new Options();
|
|
@@ -78,6 +85,8 @@ public class StackPresenterTest extends BaseTest {
|
78
|
85
|
private Button componentBtn1 = TitleBarHelper.reactViewButton("btn1_");
|
79
|
86
|
private Button componentBtn2 = TitleBarHelper.reactViewButton("btn2_");
|
80
|
87
|
private TopBarController topBarController;
|
|
88
|
+ private ChildControllersRegistry childRegistry;
|
|
89
|
+ private NavigationIconResolver iconResolver;
|
81
|
90
|
|
82
|
91
|
@Override
|
83
|
92
|
public void beforeEach() {
|
|
@@ -89,24 +98,19 @@ public class StackPresenterTest extends BaseTest {
|
89
|
98
|
}
|
90
|
99
|
};
|
91
|
100
|
renderChecker = spy(new RenderChecker());
|
92
|
|
- uut = spy(new StackPresenter(activity, titleViewCreator, new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), ImageLoaderMock.mock(), renderChecker, new Options()));
|
93
|
|
- topBar = mockTopBar();
|
94
|
|
- topBarController = spy(new TopBarController() {
|
95
|
|
- @Override
|
96
|
|
- protected TopBar createTopBar(Context context, StackLayout stackLayout) {
|
97
|
|
- return topBar;
|
98
|
|
- }
|
99
|
|
- });
|
|
101
|
+ iconResolver = new NavigationIconResolver(activity, ImageLoaderMock.mock());
|
|
102
|
+ uut = spy(new StackPresenter(activity, titleViewCreator, new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), iconResolver, renderChecker, new Options()));
|
|
103
|
+ createTopBarController();
|
100
|
104
|
|
101
|
105
|
parent = TestUtils.newStackController(activity)
|
102
|
106
|
.setTopBarController(topBarController)
|
103
|
107
|
.setStackPresenter(uut)
|
104
|
108
|
.build();
|
105
|
|
- parent.ensureViewIsCreated();
|
106
|
109
|
|
107
|
|
- ChildControllersRegistry childRegistry = new ChildControllersRegistry();
|
|
110
|
+ childRegistry = new ChildControllersRegistry();
|
108
|
111
|
child = spy(new SimpleViewController(activity, childRegistry, "child1", Options.EMPTY));
|
109
|
112
|
otherChild = spy(new SimpleViewController(activity, childRegistry, "child1", Options.EMPTY));
|
|
113
|
+ activity.setContentView(parent.getView());
|
110
|
114
|
}
|
111
|
115
|
|
112
|
116
|
@Test
|
|
@@ -114,13 +118,13 @@ public class StackPresenterTest extends BaseTest {
|
114
|
118
|
Options o1 = new Options();
|
115
|
119
|
o1.topBar.title.component = component(Alignment.Default);
|
116
|
120
|
o1.topBar.background.component = component(Alignment.Default);
|
117
|
|
- o1.topBar.buttons.right = new ArrayList(Collections.singletonList(componentBtn1));
|
|
121
|
+ o1.topBar.buttons.right = new ArrayList<>(Collections.singletonList(componentBtn1));
|
118
|
122
|
uut.applyChildOptions(o1, parent, child);
|
119
|
123
|
|
120
|
124
|
uut.isRendered(child.getView());
|
121
|
125
|
ArgumentCaptor<Collection<ViewController>> controllers = ArgumentCaptor.forClass(Collection.class);
|
122
|
126
|
verify(renderChecker).areRendered(controllers.capture());
|
123
|
|
- ArrayList<ViewController> items = new ArrayList(controllers.getValue());
|
|
127
|
+ ArrayList<ViewController> items = new ArrayList<>(controllers.getValue());
|
124
|
128
|
assertThat(items.contains(uut.getComponentButtons(child.getView()).get(0))).isTrue();
|
125
|
129
|
assertThat(items.contains(uut.getTitleComponents().get(child.getView()))).isTrue();
|
126
|
130
|
assertThat(items.contains(uut.getBackgroundComponents().get(child.getView()))).isTrue();
|
|
@@ -250,6 +254,27 @@ public class StackPresenterTest extends BaseTest {
|
250
|
254
|
assertThat(initialButtons.get(1).isDestroyed()).isTrue();
|
251
|
255
|
}
|
252
|
256
|
|
|
257
|
+ @Test
|
|
258
|
+ public void mergeButtons_backButtonIsRemovedIfVisibleFalse() {
|
|
259
|
+ ViewController pushedChild = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
|
|
260
|
+ disablePushAnimation(child, pushedChild);
|
|
261
|
+ parent.push(child, new CommandListenerAdapter());
|
|
262
|
+
|
|
263
|
+ assertThat(topBar.getTitleBar().getNavigationIcon()).isNull();
|
|
264
|
+
|
|
265
|
+ parent.push(pushedChild, new CommandListenerAdapter());
|
|
266
|
+ ShadowLooper.idleMainLooper();
|
|
267
|
+ verify(pushedChild).onViewAppeared();
|
|
268
|
+ assertThat(topBar.getTitleBar().getNavigationIcon()).isInstanceOf(BackDrawable.class);
|
|
269
|
+
|
|
270
|
+ Options backButtonHidden = new Options();
|
|
271
|
+ backButtonHidden.topBar.buttons.back.setHidden();
|
|
272
|
+ uut.mergeChildOptions(backButtonHidden, backButtonHidden, parent, child);
|
|
273
|
+
|
|
274
|
+ ShadowLooper.idleMainLooper();
|
|
275
|
+ assertThat(topBar.getTitleBar().getNavigationIcon()).isNull();
|
|
276
|
+ }
|
|
277
|
+
|
253
|
278
|
@Test
|
254
|
279
|
public void mergeTopBarOptions() {
|
255
|
280
|
Options options = new Options();
|
|
@@ -302,20 +327,6 @@ public class StackPresenterTest extends BaseTest {
|
302
|
327
|
verify(topBar, times(1)).setTopTabsVisible(anyBoolean());
|
303
|
328
|
}
|
304
|
329
|
|
305
|
|
- @Test
|
306
|
|
- public void mergeTopTabOptions() {
|
307
|
|
- Options options = new Options();
|
308
|
|
- uut.mergeChildOptions(options, EMPTY_OPTIONS, parent, child);
|
309
|
|
-
|
310
|
|
- verify(topBar, times(0)).setTopTabFontFamily(anyInt(), any());
|
311
|
|
-
|
312
|
|
- options.topTabOptions.tabIndex = 1;
|
313
|
|
- options.topTabOptions.fontFamily = Typeface.DEFAULT_BOLD;
|
314
|
|
- uut.mergeChildOptions(options, EMPTY_OPTIONS, parent, child);
|
315
|
|
-
|
316
|
|
- verify(topBar, times(1)).setTopTabFontFamily(1, Typeface.DEFAULT_BOLD);
|
317
|
|
- }
|
318
|
|
-
|
319
|
330
|
@Test
|
320
|
331
|
public void applyInitialChildLayoutOptions() {
|
321
|
332
|
Options options = new Options();
|
|
@@ -571,10 +582,22 @@ public class StackPresenterTest extends BaseTest {
|
571
|
582
|
toolbar.addView(new ActionMenuView(activity));
|
572
|
583
|
when(topBar.getTitleBar()).then(invocation -> toolbar);
|
573
|
584
|
when(topBar.getContext()).then(invocation -> activity);
|
574
|
|
- when(topBar.getLayoutParams()).thenReturn(new ViewGroup.MarginLayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
|
585
|
+ when(topBar.dispatchApplyWindowInsets(any())).then(invocation -> invocation.getArguments()[0]);
|
|
586
|
+ when(topBar.getLayoutParams()).thenReturn(new CoordinatorLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
575
|
587
|
return topBar;
|
576
|
588
|
}
|
577
|
589
|
|
|
590
|
+ private void createTopBarController() {
|
|
591
|
+ topBarController = spy(new TopBarController() {
|
|
592
|
+ @Override
|
|
593
|
+ protected TopBar createTopBar(Context context, StackLayout stackLayout) {
|
|
594
|
+ topBar = spy(super.createTopBar(context, stackLayout));
|
|
595
|
+ topBar.layout(0, 0, 1000, UiUtils.getTopBarHeight(activity));
|
|
596
|
+ return topBar;
|
|
597
|
+ }
|
|
598
|
+ });
|
|
599
|
+ }
|
|
600
|
+
|
578
|
601
|
private Component component(Alignment alignment) {
|
579
|
602
|
Component component = new Component();
|
580
|
603
|
component.name = new Text("myComp");
|