Skip to content

Commit f12b403

Browse files
authored
Streamlined fromComposable and fromScreen. Removed casting. (#394)
1 parent 9a48979 commit f12b403

File tree

2 files changed

+5
-9
lines changed
  • app/src/androidTest/java/com/mitteloupe/whoami/launcher
  • architecture/instrumentation-test/src/main/java/com/mitteloupe/whoami/test/launcher

2 files changed

+5
-9
lines changed

app/src/androidTest/java/com/mitteloupe/whoami/launcher/FromScreen.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mitteloupe.whoami.launcher
22

3-
import androidx.activity.ComponentActivity
4-
import androidx.activity.compose.LocalActivity
53
import androidx.appcompat.app.AppCompatActivity
64
import com.mitteloupe.whoami.di.testAppDependenciesEntryPoint
75
import com.mitteloupe.whoami.test.launcher.AppLauncher
@@ -10,13 +8,12 @@ import com.mitteloupe.whoami.test.test.TypedAndroidComposeTestRule
108
import com.mitteloupe.whoami.ui.main.AppNavHost
119
import com.mitteloupe.whoami.ui.theme.WhoAmITheme
1210

13-
fun <ACTIVITY : ComponentActivity> fromScreen(
11+
fun <ACTIVITY : AppCompatActivity> fromScreen(
1412
composeContentTestRule: TypedAndroidComposeTestRule<ACTIVITY>,
1513
startDestination: Any
1614
) = AppLauncher {
17-
fromComposable(composeContentTestRule) {
15+
fromComposable(composeContentTestRule) { activity ->
1816
WhoAmITheme {
19-
val activity = LocalActivity.current as AppCompatActivity
2017
with(testAppDependenciesEntryPoint(activity).appNavHostDependencies) {
2118
AppNavHost(
2219
supportFragmentManager = activity.supportFragmentManager,

architecture/instrumentation-test/src/main/java/com/mitteloupe/whoami/test/launcher/FromComposable.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import kotlinx.coroutines.runBlocking
99

1010
fun <ACTIVITY : ComponentActivity> fromComposable(
1111
composeContentTestRule: TypedAndroidComposeTestRule<ACTIVITY>,
12-
composable: @Composable () -> Unit
12+
composable: @Composable (ACTIVITY) -> Unit
1313
) = AppLauncher {
1414
val activity = composeContentTestRule.activity
15-
val root = activity.findViewById<ViewGroup>(android.R.id.content)
16-
if (root != null) {
15+
activity.findViewById<ViewGroup>(android.R.id.content)?.let { root ->
1716
runBlocking(Dispatchers.Main) {
1817
root.removeAllViews()
1918
}
2019
}
21-
composeContentTestRule.setContent(composable)
20+
composeContentTestRule.setContent { composable(activity) }
2221
}

0 commit comments

Comments
 (0)