From b3c02a466d1796d373f801cb45832e91d9ff0f0a Mon Sep 17 00:00:00 2001 From: HyunWoo Lee Date: Mon, 12 Aug 2024 12:43:49 +0900 Subject: [PATCH] [feature/#245] Apply code review & add test config for type safe navigation --- .../robot/TimetableItemDetailScreenRobot.kt | 7 +++---- .../confsched/testing/rules/RobotTestRule.kt | 16 ++++++++++++++++ .../sessions/TimetableItemDetailScreen.kt | 6 +++--- .../{TimeTableItem.kt => TimetableItem.kt} | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) rename feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/navigation/{TimeTableItem.kt => TimetableItem.kt} (89%) diff --git a/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/robot/TimetableItemDetailScreenRobot.kt b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/robot/TimetableItemDetailScreenRobot.kt index 8eb70257f..40af10f6b 100644 --- a/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/robot/TimetableItemDetailScreenRobot.kt +++ b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/robot/TimetableItemDetailScreenRobot.kt @@ -14,7 +14,7 @@ import io.github.droidkaigi.confsched.data.sessions.response.SessionsAllResponse import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme import io.github.droidkaigi.confsched.sessions.TimetableItemDetailBookmarkIconTestTag import io.github.droidkaigi.confsched.sessions.TimetableItemDetailScreen -import io.github.droidkaigi.confsched.sessions.timetableItemDetailScreenRoute +import io.github.droidkaigi.confsched.sessions.navigation.TimetableItem import javax.inject.Inject class TimetableItemDetailScreenRobot @Inject constructor( @@ -27,9 +27,8 @@ class TimetableItemDetailScreenRobot @Inject constructor( suspend fun setupScreenContent() { val firstSessionId = SessionsAllResponse.Companion.fake().sessions.first().id - robotTestRule.setContentWithNavigation( - startDestination = "timetableItemDetail/$firstSessionId", - route = timetableItemDetailScreenRoute, + robotTestRule.setContentWithNavigation( + startDestination = { TimetableItem(firstSessionId) }, ) { KaigiTheme { TimetableItemDetailScreen( diff --git a/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/rules/RobotTestRule.kt b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/rules/RobotTestRule.kt index 61fa4514e..a725bf499 100644 --- a/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/rules/RobotTestRule.kt +++ b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/rules/RobotTestRule.kt @@ -150,6 +150,22 @@ class RobotTestRule( } } + inline fun setContentWithNavigation( + crossinline startDestination: () -> T, + crossinline content: @Composable () -> Unit, + ) { + setContent { + NavHost( + navController = rememberNavController(), + startDestination = startDestination(), + ) { + composable { + content() + } + } + } + } + fun captureScreen(name: String? = null) { if (name != null) { captureScreenRoboImage("$name.png") diff --git a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/TimetableItemDetailScreen.kt b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/TimetableItemDetailScreen.kt index 13cde7670..3a6e83ed6 100644 --- a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/TimetableItemDetailScreen.kt +++ b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/TimetableItemDetailScreen.kt @@ -40,7 +40,7 @@ import io.github.droidkaigi.confsched.sessions.component.TimetableItemDetailCont import io.github.droidkaigi.confsched.sessions.component.TimetableItemDetailHeadline import io.github.droidkaigi.confsched.sessions.component.TimetableItemDetailSummaryCard import io.github.droidkaigi.confsched.sessions.component.TimetableItemDetailTopAppBar -import io.github.droidkaigi.confsched.sessions.navigation.TimeTableItem +import io.github.droidkaigi.confsched.sessions.navigation.TimetableItem import io.github.droidkaigi.confsched.ui.SnackbarMessageEffect import io.github.droidkaigi.confsched.ui.UserMessageStateHolder import io.github.droidkaigi.confsched.ui.UserMessageStateHolderImpl @@ -57,7 +57,7 @@ fun NavGraphBuilder.sessionScreens( onCalendarRegistrationClick: (TimetableItem) -> Unit, onShareClick: (TimetableItem) -> Unit, ) { - composable { + composable { TimetableItemDetailScreen( onNavigationIconClick = onNavigationIconClick, onLinkClick = onLinkClick, @@ -70,7 +70,7 @@ fun NavGraphBuilder.sessionScreens( fun NavController.navigateToTimetableItemDetailScreen( timetableItem: TimetableItem, ) { - navigate(TimeTableItem(timetableItem.id.value)) + navigate(io.github.droidkaigi.confsched.sessions.navigation.TimetableItem(timetableItem.id.value)) } @Composable diff --git a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/navigation/TimeTableItem.kt b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/navigation/TimetableItem.kt similarity index 89% rename from feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/navigation/TimeTableItem.kt rename to feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/navigation/TimetableItem.kt index d0bb79d2a..1c3c9f0ef 100644 --- a/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/navigation/TimeTableItem.kt +++ b/feature/sessions/src/commonMain/kotlin/io/github/droidkaigi/confsched/sessions/navigation/TimetableItem.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class TimeTableItem( +data class TimetableItem( @SerialName("timetableItemId") val timetableItemId: String, )