Skip to content

Commit

Permalink
testing navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
omer358 committed Jun 13, 2024
1 parent 35e20f5 commit a406b5f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ dependencies {

// Navigation Compose
implementation(libs.androidx.navigation.compose)
androidTestImplementation(libs.androidx.navigation.testing)


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.rememberme
package com.example.rememberme.data

import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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], {})
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit a406b5f

Please sign in to comment.