Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mitteloupe.whoami.launcher

import androidx.activity.ComponentActivity
import androidx.activity.compose.LocalActivity
import androidx.appcompat.app.AppCompatActivity
import com.mitteloupe.whoami.di.testAppDependenciesEntryPoint
import com.mitteloupe.whoami.test.test.BaseTest.AppLauncher
import com.mitteloupe.whoami.test.test.TypedAndroidComposeTestRule
import com.mitteloupe.whoami.ui.main.AppNavHost
import com.mitteloupe.whoami.ui.theme.WhoAmITheme

data class FromScreen<ACTIVITY : ComponentActivity>(
private val composeContentTestRule: TypedAndroidComposeTestRule<ACTIVITY>,
private val startDestination: Any
) : AppLauncher() {
private val composableAppLauncher = FromComposable(composeContentTestRule) {
WhoAmITheme {
val activity = LocalActivity.current as AppCompatActivity
with(testAppDependenciesEntryPoint(activity).appNavHostDependencies) {
AppNavHost(
supportFragmentManager = activity.supportFragmentManager,
startDestination = startDestination
)
}
}
}

override fun launch() = composableAppLauncher.launch()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package com.mitteloupe.whoami.test

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.mitteloupe.whoami.analytics.Analytics
import com.mitteloupe.whoami.coroutine.CoroutineContextProvider
import com.mitteloupe.whoami.launcher.historyScreenLauncher
import com.mitteloupe.whoami.launcher.FromScreen
import com.mitteloupe.whoami.localstore.KEY_VALUE_SAVED_HISTORY
import com.mitteloupe.whoami.screen.HistoryScreen
import com.mitteloupe.whoami.test.annotation.LocalStore
import com.mitteloupe.whoami.test.test.BaseTest
import com.mitteloupe.whoami.test.test.retry
import com.mitteloupe.whoami.ui.main.MainActivity
import com.mitteloupe.whoami.ui.main.route.History
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import org.junit.Test
Expand All @@ -23,18 +22,12 @@ class HistoryHighlightedIpAddressTest : BaseTest() {
override val composeTestRule = createAndroidComposeRule<MainActivity>()

override val startActivityLauncher: AppLauncher by lazy {
historyScreenLauncher(highlightedIpAddress = HIGHLIGHTED_IP_ADDRESS)
FromScreen(composeTestRule, History(highlightedIpAddress = HIGHLIGHTED_IP_ADDRESS))
}

@Inject
lateinit var historyScreen: HistoryScreen

@Inject
lateinit var coroutineContextProvider: CoroutineContextProvider

@Inject
lateinit var analytics: Analytics

@Test
@LocalStore(
localStoreDataIds = [KEY_VALUE_SAVED_HISTORY]
Expand Down
13 changes: 3 additions & 10 deletions app/src/androidTest/java/com/mitteloupe/whoami/test/HistoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.mitteloupe.whoami.test

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.mitteloupe.whoami.analytics.Analytics
import com.mitteloupe.whoami.coroutine.CoroutineContextProvider
import com.mitteloupe.whoami.launcher.historyScreenLauncher
import com.mitteloupe.whoami.launcher.FromScreen
import com.mitteloupe.whoami.localstore.KEY_VALUE_NO_HISTORY
import com.mitteloupe.whoami.localstore.KEY_VALUE_SAVED_HISTORY
import com.mitteloupe.whoami.screen.HistoryScreen
Expand All @@ -13,6 +11,7 @@ import com.mitteloupe.whoami.test.test.BaseTest
import com.mitteloupe.whoami.test.test.doesNot
import com.mitteloupe.whoami.test.test.retry
import com.mitteloupe.whoami.ui.main.MainActivity
import com.mitteloupe.whoami.ui.main.route.History
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import org.junit.Test
Expand All @@ -23,18 +22,12 @@ class HistoryTest : BaseTest() {
override val composeTestRule = createAndroidComposeRule<MainActivity>()

override val startActivityLauncher: AppLauncher by lazy {
historyScreenLauncher(highlightedIpAddress = null)
FromScreen(composeTestRule, History(highlightedIpAddress = null))
}

@Inject
lateinit var historyScreen: HistoryScreen

@Inject
lateinit var coroutineContextProvider: CoroutineContextProvider

@Inject
lateinit var analytics: Analytics

@Test
@LocalStore(
localStoreDataIds = [KEY_VALUE_SAVED_HISTORY]
Expand Down
62 changes: 7 additions & 55 deletions app/src/androidTest/java/com/mitteloupe/whoami/test/HomeTest.kt
Original file line number Diff line number Diff line change
@@ -1,57 +1,28 @@
package com.mitteloupe.whoami.test

import androidx.activity.ComponentActivity
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.espresso.intent.Intents
import com.mitteloupe.whoami.launcher.FromScreen
import com.mitteloupe.whoami.screen.HomeScreen
import com.mitteloupe.whoami.screen.OpenSourceNoticesScreen
import com.mitteloupe.whoami.server.REQUEST_RESPONSE_GET_IP
import com.mitteloupe.whoami.server.REQUEST_RESPONSE_GET_IP_DETAILS
import com.mitteloupe.whoami.test.annotation.ServerRequestResponse
import com.mitteloupe.whoami.test.test.BaseTest
import com.mitteloupe.whoami.test.test.BaseTest.AppLauncher.FromComposable
import com.mitteloupe.whoami.ui.main.AppNavHost
import com.mitteloupe.whoami.ui.main.MainActivity
import com.mitteloupe.whoami.ui.main.di.AppNavHostDependencies
import com.mitteloupe.whoami.ui.theme.WhoAmITheme
import dagger.hilt.EntryPoint
import dagger.hilt.EntryPoints
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import com.mitteloupe.whoami.ui.main.route.Home
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.rules.TestRule

@HiltAndroidTest
@ExperimentalTestApi
class HomeTest : BaseTest() {
@EntryPoint
@InstallIn(ActivityComponent::class)
interface ActivityEntryPoint {
fun appNavHostDependencies(): AppNavHostDependencies
}

override val composeTestRule = createAndroidComposeRule<MainActivity>()

override val startActivityLauncher: AppLauncher by lazy {
@Suppress("UNCHECKED_CAST")
val composeContentTestRule =
composeTestRule as AndroidComposeTestRule<TestRule, ComponentActivity>
FromComposable(composeContentTestRule) {
WhoAmITheme {
val activity = LocalContext.current as MainActivity
EntryPoints.get(activity, ActivityEntryPoint::class.java).appNavHostDependencies()
.AppNavHost(
activity.supportFragmentManager
)
}
}
FromScreen(composeTestRule, Home)
}

@Inject
Expand All @@ -60,24 +31,8 @@ class HomeTest : BaseTest() {
@Inject
lateinit var openSourceNoticesScreen: OpenSourceNoticesScreen

@Before
override fun setUp() {
super.setUp()
Intents.init()
}

@After
fun tearDown() {
Intents.release()
}

@Test
@ServerRequestResponse(
[
REQUEST_RESPONSE_GET_IP,
REQUEST_RESPONSE_GET_IP_DETAILS
]
)
@ServerRequestResponse([REQUEST_RESPONSE_GET_IP, REQUEST_RESPONSE_GET_IP_DETAILS])
fun givenConnectedWhenStartingAppThenIpAddressPresented() {
with(composeTestRule) {
with(homeScreen) {
Expand All @@ -88,12 +43,7 @@ class HomeTest : BaseTest() {
}

@Test
@ServerRequestResponse(
[
REQUEST_RESPONSE_GET_IP,
REQUEST_RESPONSE_GET_IP_DETAILS
]
)
@ServerRequestResponse([REQUEST_RESPONSE_GET_IP, REQUEST_RESPONSE_GET_IP_DETAILS])
fun givenConnectedWhenStartingAppThenIpAddressDetailsPresented() {
with(composeTestRule) {
with(homeScreen) {
Expand All @@ -110,6 +60,7 @@ class HomeTest : BaseTest() {

@Test
fun whenTappingOnOpenSourceNoticesLaunchesActivity() {
Intents.init()
with(composeTestRule) {
with(homeScreen) {
tapOpenSourceNotices()
Expand All @@ -119,5 +70,6 @@ class HomeTest : BaseTest() {
seesScreen()
}
}
Intents.release()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResource as EspressoIdlingResource
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import com.mitteloupe.whoami.test.idlingresource.findAndCloseAppNotRespondingDialog
Expand All @@ -37,7 +38,9 @@ import org.junit.Before
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.rules.RuleChain
import org.junit.rules.TestRule

typealias TypedAndroidComposeTestRule<ACTIVITY> =
AndroidComposeTestRule<ActivityScenarioRule<ACTIVITY>, ACTIVITY>

abstract class BaseTest {
private val hiltAndroidRule by lazy { HiltAndroidRule(this) }
Expand Down Expand Up @@ -113,7 +116,7 @@ abstract class BaseTest {
composeIdlingResources.forEach(composeTestRule::registerIdlingResource)
}

sealed class AppLauncher {
abstract class AppLauncher {
abstract fun launch()

data class FromIntent(private val intent: Intent) : AppLauncher() {
Expand All @@ -130,8 +133,8 @@ abstract class BaseTest {
}
}

data class FromComposable(
private val composeContentTestRule: AndroidComposeTestRule<TestRule, ComponentActivity>,
data class FromComposable<ACTIVITY : ComponentActivity>(
private val composeContentTestRule: TypedAndroidComposeTestRule<ACTIVITY>,
private val composable: @Composable () -> Unit
) : AppLauncher() {
override fun launch() {
Expand Down