Skip to content

Commit 0b583d5

Browse files
committed
Implement CrossFadeTest
1 parent a7d6294 commit 0b583d5

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

core/ui/build.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ plugins {
55

66
android {
77
namespace = "io.jja08111.gemini.core.ui"
8+
9+
defaultConfig {
10+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
11+
}
812
}
913

1014
dependencies {
1115

1216
implementation(libs.androidx.compose.ui)
1317
implementation(libs.androidx.animation.android)
18+
androidTestImplementation(libs.androidx.ui.test.junit4.android)
19+
androidTestImplementation(libs.androidx.compose.material3)
20+
androidTestImplementation(libs.espresso.core)
1421
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application>
3+
<activity android:name="androidx.activity.ComponentActivity" />
4+
</application>
5+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.jja08111.gemini.core.ui
2+
3+
import androidx.compose.material3.Text
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.runtime.getValue
6+
import androidx.compose.runtime.mutableStateOf
7+
import androidx.compose.runtime.setValue
8+
import androidx.compose.ui.test.assertIsDisplayed
9+
import androidx.compose.ui.test.assertIsNotDisplayed
10+
import androidx.compose.ui.test.junit4.createComposeRule
11+
import androidx.compose.ui.test.onNodeWithText
12+
import org.junit.Rule
13+
import org.junit.Test
14+
15+
class CrossFadeTest {
16+
@get:Rule
17+
val composeRule = createComposeRule()
18+
19+
@Test
20+
fun shouldSwitchToSecondComponent() {
21+
var showFirst by mutableStateOf(true)
22+
composeRule.setContent {
23+
CrossFade(
24+
showFirst = showFirst,
25+
firstContent = { FirstComponent() },
26+
secondContent = { SecondComponent() },
27+
)
28+
}
29+
30+
composeRule.onNodeWithText(FIRST_TITLE).assertIsDisplayed()
31+
composeRule.onNodeWithText(SECOND_TITLE).assertIsNotDisplayed()
32+
33+
showFirst = false
34+
35+
composeRule.onNodeWithText(FIRST_TITLE).assertIsNotDisplayed()
36+
composeRule.onNodeWithText(SECOND_TITLE).assertIsDisplayed()
37+
}
38+
39+
@Suppress("TestFunctionName")
40+
@Composable
41+
private fun FirstComponent() {
42+
Text(text = FIRST_TITLE)
43+
}
44+
45+
@Suppress("TestFunctionName")
46+
@Composable
47+
private fun SecondComponent() {
48+
Text(text = SECOND_TITLE)
49+
}
50+
51+
companion object {
52+
private const val FIRST_TITLE = "First"
53+
private const val SECOND_TITLE = "Second"
54+
}
55+
}

gradle/libs.versions.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ kotlin = "1.9.22"
2020
hilt = "2.50"
2121
junit = "4.13.2"
2222
androidx-test-ext-junit = "1.1.5"
23-
espresso-core = "3.5.1"
23+
espresso-core = "3.5.0"
2424
material = "1.11.0"
2525
ktlint = "12.1.0"
2626
ksp = "1.9.22-1.0.17"
@@ -30,6 +30,7 @@ androidDesugarJdkLibs = "2.0.4"
3030
glideCompose = "1.0.0-beta01"
3131
kotlinCoroutineTest = "1.6.4"
3232
robolectric = "4.13"
33+
uiTestJunit4Android = "1.6.8"
3334

3435
# Wearables
3536
playServicesWearable = "18.1.0"
@@ -72,6 +73,7 @@ hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-comp
7273
glide-compose = { group = "com.github.bumptech.glide", name = "compose", version.ref = "glideCompose" }
7374
kotlin-coroutine-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinCoroutineTest" }
7475
robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" }
76+
androidx-ui-test-junit4-android = { group = "androidx.compose.ui", name = "ui-test-junit4-android", version.ref = "uiTestJunit4Android" }
7577

7678
# Wearables
7779
play-services-wearable = { module = "com.google.android.gms:play-services-wearable", version.ref = "playServicesWearable" }

0 commit comments

Comments
 (0)