Skip to content

Commit 89f0074

Browse files
committed
Enabled instrumentation and add run them on ATD
1 parent d72186c commit 89f0074

13 files changed

Lines changed: 206 additions & 183 deletions

File tree

lib/android/app/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ android {
5555
}
5656

5757
testOptions {
58+
managedDevices {
59+
localDevices {
60+
pixel3aapi34 {
61+
device = "Pixel 3a"
62+
apiLevel = 34
63+
systemImageSource = "aosp-atd"
64+
}
65+
}
66+
}
5867
unitTests.includeAndroidResources = true
5968
unitTests.all { t ->
6069
maxHeapSize = "4g"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.modes
2+
3+
import androidx.test.espresso.Espresso
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import org.junit.Before
6+
import org.junit.Test
7+
import org.mockito.Mockito.verify
8+
import org.mockito.kotlin.any
9+
10+
class AfterInitialTabTest : AttachModeTest() {
11+
12+
@Before
13+
override fun setup() {
14+
super.setup()
15+
uut = AfterInitialTab(parent, tabs, presenter, options)
16+
}
17+
18+
@Test
19+
fun attach_initialTabIsAttached() {
20+
uut.attach()
21+
assertIsChild(parent, tab2)
22+
}
23+
24+
@Test
25+
fun attach_otherTabsAreAttachedAfterInitialTab() {
26+
InstrumentationRegistry.getInstrumentation().runOnMainSync {
27+
uut.attach()
28+
29+
assertNotChildOf(parent, *otherTabs())
30+
31+
initialTab().onViewWillAppear()
32+
}
33+
Espresso.onIdle()
34+
assertIsChild(parent, *otherTabs())
35+
}
36+
37+
@Test
38+
fun destroy() {
39+
uut.destroy()
40+
verify(initialTab()).removeOnAppearedListener(any())
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.modes
2+
3+
import android.view.View
4+
import android.view.ViewGroup
5+
import androidx.coordinatorlayout.widget.CoordinatorLayout
6+
import androidx.test.ext.junit.rules.ActivityScenarioRule
7+
import androidx.test.ext.junit.runners.AndroidJUnit4
8+
import com.reactnativenavigation.TestActivity
9+
import com.reactnativenavigation.mocks.SimpleViewController
10+
import com.reactnativenavigation.options.Options
11+
import com.reactnativenavigation.options.params.Number
12+
import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsPresenter
13+
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry
14+
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController
15+
import com.reactnativenavigation.views.bottomtabs.BottomTabsBehaviour
16+
import org.assertj.core.api.AssertionsForInterfaceTypes.assertThat
17+
import org.junit.Before
18+
import org.junit.Rule
19+
import org.junit.Test
20+
import org.junit.runner.RunWith
21+
import org.mockito.Mockito
22+
import org.mockito.Mockito.spy
23+
24+
@RunWith(AndroidJUnit4::class)
25+
abstract class AttachModeTest {
26+
private val INITIAL_TAB = 1
27+
28+
private lateinit var childRegistry: ChildControllersRegistry
29+
protected lateinit var parent: ViewGroup
30+
protected lateinit var tab1: ViewController<*>
31+
protected lateinit var tab2: ViewController<*>
32+
protected lateinit var tabs: List<ViewController<*>>
33+
protected lateinit var options: Options
34+
protected lateinit var presenter: BottomTabsPresenter
35+
protected lateinit var uut: AttachMode
36+
37+
@get:Rule
38+
val rule = ActivityScenarioRule(TestActivity::class.java)
39+
40+
@Before
41+
open fun setup() {
42+
rule.scenario.onActivity { activity ->
43+
childRegistry = ChildControllersRegistry()
44+
parent = CoordinatorLayout(activity)
45+
tabs = createTabs(activity)
46+
}
47+
options = Options()
48+
options.bottomTabsOptions.currentTabIndex = Number(INITIAL_TAB)
49+
presenter = Mockito.mock(BottomTabsPresenter::class.java)
50+
}
51+
52+
@Test
53+
fun attach_layoutOptionsAreApplied() {
54+
uut.attach(tab1)
55+
val lp = tab1.getView().layoutParams as CoordinatorLayout.LayoutParams
56+
assertThat(lp).isNotNull
57+
assertThat(lp.behavior).isInstanceOf(BottomTabsBehaviour::class.java)
58+
}
59+
60+
@Test
61+
fun attach_initialTabIsVisible() {
62+
uut.attach(initialTab())
63+
assertThat(initialTab().getView().visibility).isEqualTo(View.VISIBLE)
64+
}
65+
66+
@Test
67+
fun attach_otherTabsAreInvisibleWhenAttached() {
68+
otherTabs().forEach { t -> uut.attach(t) }
69+
otherTabs().forEach { t -> assertThat(t.getView().visibility).isEqualTo(View.INVISIBLE) }
70+
}
71+
72+
protected fun otherTabs(): Array<ViewController<*>> {
73+
return tabs.filter { t -> t != initialTab() }.toTypedArray()
74+
}
75+
76+
protected fun initialTab(): ViewController<*> {
77+
return tabs[INITIAL_TAB]
78+
}
79+
80+
private fun createTabs(activity: android.app.Activity): List<ViewController<*>> {
81+
tab1 = SimpleViewController(activity, childRegistry, "child1", Options())
82+
tab2 = spy(SimpleViewController(activity, childRegistry, "child2", Options()))
83+
val tab3 = SimpleViewController(activity, childRegistry, "child3", Options())
84+
return listOf(tab1, tab2, tab3)
85+
}
86+
87+
protected fun assertIsChild(parent: ViewGroup, vararg children: ViewController<*>) {
88+
children.forEach { child ->
89+
assertThat(child.getView().parent).isEqualTo(parent)
90+
}
91+
}
92+
93+
protected fun assertNotChildOf(parent: ViewGroup, vararg children: ViewController<*>) {
94+
children.forEach { child ->
95+
assertThat(child.getView().parent).isNotEqualTo(parent)
96+
}
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.modes
2+
3+
import org.junit.Before
4+
import org.junit.Test
5+
6+
class OnSwitchToTabTest : AttachModeTest() {
7+
8+
@Before
9+
override fun setup() {
10+
super.setup()
11+
uut = OnSwitchToTab(parent, tabs, presenter, options)
12+
}
13+
14+
@Test
15+
fun attach_onlyInitialTabIsAttached() {
16+
uut.attach()
17+
assertIsChild(parent, initialTab())
18+
assertNotChildOf(parent, *otherTabs())
19+
}
20+
21+
@Test
22+
fun onTabSelected_initialTabIsNotHandled() {
23+
uut.onTabSelected(initialTab())
24+
assertNotChildOf(parent, initialTab())
25+
}
26+
27+
@Test
28+
fun onTabSelected_otherTabIsAttached() {
29+
uut.onTabSelected(tab1)
30+
assertIsChild(parent, tab1)
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.modes
2+
3+
import org.junit.Before
4+
import org.junit.Test
5+
6+
class TogetherTest : AttachModeTest() {
7+
8+
@Before
9+
override fun setup() {
10+
super.setup()
11+
uut = Together(parent, tabs, presenter, options)
12+
}
13+
14+
@Test
15+
fun attach_allTabsAreAttached() {
16+
uut.attach()
17+
assertIsChild(parent, *tabs.toTypedArray())
18+
}
19+
}

lib/android/app/src/test/java/com/reactnativenavigation/presentation/PresenterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.junit.Test;
2626
import org.mockito.Mockito;
2727

28-
@Ignore("New architecture - WIP")
28+
@Ignore("New architecture - failed to fix")
2929
public class PresenterTest extends BaseTest {
3030
private Presenter uut;
3131
private Activity activity;

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/AfterInitialTabTest.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/AttachModeTest.java

Lines changed: 0 additions & 87 deletions
This file was deleted.

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/attacher/modes/OnSwitchToTabTest.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)