Skip to content

Commit d72186c

Browse files
committed
Converted TitleSubTitleLayoutTest
1 parent 2872fc0 commit d72186c

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

lib/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ dependencies {
123123
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
124124

125125
androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito-inline:2.28.4"
126+
androidTestImplementation 'org.opentest4j:opentest4j:1.2.0'
127+
androidTestImplementation ("org.mockito.kotlin:mockito-kotlin:5.4.0") {
128+
exclude group: 'org.mockito', module: 'mockito-core'
129+
}
126130

127131
androidTestImplementation "androidx.test.uiautomator:uiautomator:2.3.0"
128132

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.reactnativenavigation.views
2+
3+
import android.view.ViewGroup
4+
import android.widget.FrameLayout
5+
import androidx.test.ext.junit.rules.ActivityScenarioRule
6+
import androidx.test.ext.junit.runners.AndroidJUnit4
7+
import com.reactnativenavigation.TestActivity
8+
import com.reactnativenavigation.views.stack.topbar.titlebar.TitleSubTitleLayout
9+
import org.assertj.core.api.AssertionsForInterfaceTypes.assertThat
10+
import org.junit.Before
11+
import org.junit.Rule
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
15+
private const val UUT_WIDTH = 1000
16+
private const val UUT_HEIGHT = 100
17+
18+
@RunWith(AndroidJUnit4::class)
19+
class TitleSubTitleLayoutTest {
20+
private val testId = "mock-testId"
21+
22+
private lateinit var uut: TitleSubTitleLayout
23+
24+
@get:Rule
25+
val rule = ActivityScenarioRule(TestActivity::class.java)
26+
27+
@Before
28+
fun setup() {
29+
rule.scenario.onActivity { activity ->
30+
uut = TitleSubTitleLayout(activity)
31+
activity.setContentView(FrameLayout(activity).apply {
32+
addView(uut, ViewGroup.LayoutParams(UUT_WIDTH, UUT_HEIGHT))
33+
})
34+
}
35+
}
36+
37+
@Test
38+
fun shouldSetTestIdCanonically() {
39+
uut.setTestId(testId)
40+
assertThat(uut.getTitleTxtView().tag).isEqualTo("$testId.title")
41+
assertThat(uut.getSubTitleTxtView().tag).isEqualTo("$testId.subtitle")
42+
}
43+
44+
@Test
45+
fun shouldClearTestId() {
46+
uut.setTestId(testId)
47+
uut.setTestId("")
48+
assertThat(uut.getTitleTxtView().tag).isNull()
49+
assertThat(uut.getSubTitleTxtView().tag).isNull()
50+
}
51+
}

0 commit comments

Comments
 (0)