6
6
import android .view .View ;
7
7
import android .view .ViewGroup .MarginLayoutParams ;
8
8
9
+ import com .aurelhubert .ahbottomnavigation .AHBottomNavigation ;
9
10
import com .reactnativenavigation .BaseTest ;
10
11
import com .reactnativenavigation .TestUtils ;
11
12
import com .reactnativenavigation .mocks .ImageLoaderMock ;
12
13
import com .reactnativenavigation .mocks .SimpleViewController ;
13
14
import com .reactnativenavigation .parse .Options ;
14
15
import com .reactnativenavigation .parse .params .Bool ;
15
16
import com .reactnativenavigation .parse .params .Colour ;
17
+ import com .reactnativenavigation .parse .params .NullText ;
16
18
import com .reactnativenavigation .parse .params .Number ;
17
19
import com .reactnativenavigation .parse .params .Text ;
18
20
import com .reactnativenavigation .presentation .BottomTabPresenter ;
43
45
import edu .emory .mathcs .backport .java .util .Collections ;
44
46
45
47
import static com .reactnativenavigation .TestUtils .hideBackButton ;
48
+ import static com .reactnativenavigation .utils .ObjectUtils .perform ;
46
49
import static org .assertj .core .api .Java6Assertions .assertThat ;
47
50
import static org .mockito .ArgumentMatchers .any ;
48
51
import static org .mockito .ArgumentMatchers .eq ;
@@ -74,32 +77,9 @@ public class BottomTabsControllerTest extends BaseTest {
74
77
@ Override
75
78
public void beforeEach () {
76
79
activity = newActivity ();
77
- bottomTabs = spy (new BottomTabs (activity ) {
78
- @ Override
79
- public void superCreateItems () {
80
-
81
- }
82
- });
83
80
childRegistry = new ChildControllersRegistry ();
84
81
eventEmitter = Mockito .mock (EventEmitter .class );
85
-
86
- child1 = spy (new SimpleViewController (activity , childRegistry , "child1" , tabOptions ));
87
- child2 = spy (new SimpleViewController (activity , childRegistry , "child2" , tabOptions ));
88
- child3 = spy (new SimpleViewController (activity , childRegistry , "child3" , tabOptions ));
89
- child4 = spy (createStack ());
90
- child5 = spy (new SimpleViewController (activity , childRegistry , "child5" , tabOptions ));
91
- when (child5 .handleBack (any ())).thenReturn (true );
92
- tabs = createTabs ();
93
- presenter = spy (new BottomTabsPresenter (tabs , new Options ()));
94
- bottomTabPresenter = spy (new BottomTabPresenter (activity , tabs , ImageLoaderMock .mock (), new Options ()));
95
- tabsAttacher = spy (new BottomTabsAttacher (tabs , presenter ));
96
- uut = createBottomTabs ();
97
-
98
- uut .setParentController (Mockito .mock (ParentController .class ));
99
- CoordinatorLayout parent = new CoordinatorLayout (activity );
100
- parent .addView (uut .getView ());
101
- activity .setContentView (parent );
102
-
82
+ prepareViewsForTests ();
103
83
StatusBarUtils .saveStatusBarHeight (63 );
104
84
}
105
85
@@ -110,6 +90,22 @@ public void createView_checkProperStructure() {
110
90
assertThat (((CoordinatorLayout .LayoutParams ) uut .getBottomTabs ().getLayoutParams ()).gravity ).isEqualTo (Gravity .BOTTOM );
111
91
}
112
92
93
+ @ Test
94
+ public void createView_tabsWithoutIconsAreAccepted () {
95
+ tabOptions .bottomTabOptions .icon = new NullText ();
96
+ prepareViewsForTests ();
97
+ assertThat (uut .getBottomTabs ().getItemsCount ()).isEqualTo (tabs .size ());
98
+ }
99
+
100
+ @ Test
101
+ public void createView_showTitlesWhenAllTabsDontHaveIcons () {
102
+ tabOptions .bottomTabOptions .icon = new NullText ();
103
+ assertThat (tabOptions .bottomTabsOptions .titleDisplayMode .hasValue ()).isFalse ();
104
+ prepareViewsForTests ();
105
+ presenter .applyOptions (Options .EMPTY );
106
+ assertThat (bottomTabs .getTitleState ()).isEqualTo (AHBottomNavigation .TitleState .ALWAYS_SHOW );
107
+ }
108
+
113
109
@ Test (expected = RuntimeException .class )
114
110
public void setTabs_ThrowWhenMoreThan5 () {
115
111
tabs .add (new SimpleViewController (activity , childRegistry , "6" , tabOptions ));
@@ -393,6 +389,36 @@ public void destroy() {
393
389
verify (tabsAttacher ).destroy ();
394
390
}
395
391
392
+ private void prepareViewsForTests () {
393
+ perform (uut , ViewController ::destroy );
394
+ bottomTabs = spy (new BottomTabs (activity ) {
395
+ @ Override
396
+ public void superCreateItems () {
397
+
398
+ }
399
+ });
400
+ createChildren ();
401
+ tabs = createTabs ();
402
+ presenter = spy (new BottomTabsPresenter (tabs , new Options ()));
403
+ bottomTabPresenter = spy (new BottomTabPresenter (activity , tabs , ImageLoaderMock .mock (), new Options ()));
404
+ tabsAttacher = spy (new BottomTabsAttacher (tabs , presenter ));
405
+ uut = createBottomTabs ();
406
+
407
+ uut .setParentController (Mockito .mock (ParentController .class ));
408
+ CoordinatorLayout parent = new CoordinatorLayout (activity );
409
+ parent .addView (uut .getView ());
410
+ activity .setContentView (parent );
411
+ }
412
+
413
+ private void createChildren () {
414
+ child1 = spy (new SimpleViewController (activity , childRegistry , "child1" , tabOptions ));
415
+ child2 = spy (new SimpleViewController (activity , childRegistry , "child2" , tabOptions ));
416
+ child3 = spy (new SimpleViewController (activity , childRegistry , "child3" , tabOptions ));
417
+ child4 = spy (createStack ());
418
+ child5 = spy (new SimpleViewController (activity , childRegistry , "child5" , tabOptions ));
419
+ when (child5 .handleBack (any ())).thenReturn (true );
420
+ }
421
+
396
422
@ NonNull
397
423
private List <ViewController > createTabs () {
398
424
return Arrays .asList (child1 , child2 , child3 , child4 , child5 );
0 commit comments