diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a4323a7..1864821 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -97,6 +97,7 @@ dependencies { // Navigation Compose implementation(libs.androidx.navigation.compose) + androidTestImplementation(libs.androidx.navigation.testing) } \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/rememberme/PeopleDatabaseTest.kt b/app/src/androidTest/java/com/example/rememberme/data/PeopleDatabaseTest.kt similarity index 98% rename from app/src/androidTest/java/com/example/rememberme/PeopleDatabaseTest.kt rename to app/src/androidTest/java/com/example/rememberme/data/PeopleDatabaseTest.kt index 1947c63..f83f7aa 100644 --- a/app/src/androidTest/java/com/example/rememberme/PeopleDatabaseTest.kt +++ b/app/src/androidTest/java/com/example/rememberme/data/PeopleDatabaseTest.kt @@ -1,4 +1,4 @@ -package com.example.rememberme +package com.example.rememberme.data import androidx.room.Room import androidx.test.core.app.ApplicationProvider diff --git a/app/src/androidTest/java/com/example/rememberme/presentation/navgraph/NavGraphTest.kt b/app/src/androidTest/java/com/example/rememberme/presentation/navgraph/NavGraphTest.kt new file mode 100644 index 0000000..6fba3b0 --- /dev/null +++ b/app/src/androidTest/java/com/example/rememberme/presentation/navgraph/NavGraphTest.kt @@ -0,0 +1,37 @@ +package com.example.rememberme + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.rememberme.presentation.navgraph.NavGraph +import com.example.rememberme.presentation.navgraph.Routes +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class NavGraphTest { + + @get:Rule + val composeTestRule = createComposeRule() + + @Test + fun testNavigationToOnBoardingScreen() { + composeTestRule.setContent { + NavGraph(startDestination = Routes.AppStartNavigation.route) + } + + composeTestRule.onNodeWithText("OnBoarding Screen").assertIsDisplayed() + } + + @Test + fun testNavigationToPeopleScreen() { + composeTestRule.setContent { + NavGraph(startDestination = Routes.PeopleNavigation.route) + } + + composeTestRule.onNodeWithTag("PeopleListScreen").assertIsDisplayed() + } +} diff --git a/app/src/main/java/com/example/rememberme/presentation/navgraph/NavGraph.kt b/app/src/main/java/com/example/rememberme/presentation/navgraph/NavGraph.kt index 6d1bf81..f24e3fb 100644 --- a/app/src/main/java/com/example/rememberme/presentation/navgraph/NavGraph.kt +++ b/app/src/main/java/com/example/rememberme/presentation/navgraph/NavGraph.kt @@ -1,6 +1,7 @@ package com.example.rememberme.presentation.navgraph import androidx.compose.runtime.Composable +import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController @@ -10,9 +11,10 @@ import com.example.rememberme.presentation.people.PeopleScreen @Composable fun NavGraph( - startDestination: String + startDestination: String, + navController: NavHostController = rememberNavController() ){ - val navController = rememberNavController() + NavHost( navController = navController, startDestination = startDestination diff --git a/app/src/main/java/com/example/rememberme/presentation/people/PeopleListScreen.kt b/app/src/main/java/com/example/rememberme/presentation/people/PeopleListScreen.kt index 9eb48cf..d639e7e 100644 --- a/app/src/main/java/com/example/rememberme/presentation/people/PeopleListScreen.kt +++ b/app/src/main/java/com/example/rememberme/presentation/people/PeopleListScreen.kt @@ -15,6 +15,7 @@ import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.example.rememberme.R @@ -59,6 +60,7 @@ fun PeopleScreenContent(modifier: Modifier = Modifier) { LazyColumn( modifier = modifier.padding(it) .fillMaxSize() + .testTag("PeopleListScreen") ) { items(count = peopleList.size) { index -> PeopleListItem(peopleList[index], {}) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6f4a2de..cd03848 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,6 +25,7 @@ androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", versi androidx-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "coreTesting" } androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleRuntimeKtx" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" } +androidx-navigation-testing = { module = "androidx.navigation:navigation-testing", version.ref = "navigationCompose" } androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomRuntime" } androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomRuntime" } androidx-room-room-testing = { module = "androidx.room:room-testing", version.ref = "roomRuntime" }