Skip to content

Commit

Permalink
[feature/#245] Apply code review & add test config for type safe navi…
Browse files Browse the repository at this point in the history
…gation
  • Loading branch information
l2hyunwoo committed Aug 12, 2024
1 parent 6576fa1 commit b3c02a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<TimetableItem>(
startDestination = { TimetableItem(firstSessionId) },
) {
KaigiTheme {
TimetableItemDetailScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ class RobotTestRule(
}
}

inline fun <reified T: Any> setContentWithNavigation(
crossinline startDestination: () -> T,
crossinline content: @Composable () -> Unit,
) {
setContent {
NavHost(
navController = rememberNavController(),
startDestination = startDestination(),
) {
composable<T> {
content()
}
}
}
}

fun captureScreen(name: String? = null) {
if (name != null) {
captureScreenRoboImage("$name.png")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,7 +57,7 @@ fun NavGraphBuilder.sessionScreens(
onCalendarRegistrationClick: (TimetableItem) -> Unit,
onShareClick: (TimetableItem) -> Unit,
) {
composable<TimeTableItem> {
composable<io.github.droidkaigi.confsched.sessions.navigation.TimetableItem> {
TimetableItemDetailScreen(
onNavigationIconClick = onNavigationIconClick,
onLinkClick = onLinkClick,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class TimeTableItem(
data class TimetableItem(
@SerialName("timetableItemId")
val timetableItemId: String,
)

0 comments on commit b3c02a4

Please sign in to comment.