Skip to content

Commit

Permalink
test: Check the launch of CropImageScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
warahiko committed Sep 6, 2024
1 parent 899c7d7 commit 9b0728c
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.droidkaigi.confsched.testing.robot

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasTestTag
import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched.profilecard.CropImageScreen
import io.github.droidkaigi.confsched.profilecard.CropImageScreenTestTag
import javax.inject.Inject

class CropImageScreenRobot @Inject constructor(
screenRobot: DefaultScreenRobot,
) : ScreenRobot by screenRobot {

fun setupScreenContent() {
robotTestRule.setContent {
KaigiTheme {
CropImageScreen(
onNavigationIconClick = {},
onBackWithConfirm = {},
)
}
}
waitUntilIdle()
}

fun checkScreenDisplayed() {
composeTestRule
.onNode(hasTestTag(CropImageScreenTestTag))
.assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.github.droidkaigi.confsched.profilecard

import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidTest
import io.github.droidkaigi.confsched.testing.DescribedBehavior
import io.github.droidkaigi.confsched.testing.describeBehaviors
import io.github.droidkaigi.confsched.testing.execute
import io.github.droidkaigi.confsched.testing.robot.CropImageScreenRobot
import io.github.droidkaigi.confsched.testing.robot.runRobot
import io.github.droidkaigi.confsched.testing.rules.RobotTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import javax.inject.Inject

@RunWith(ParameterizedRobolectricTestRunner::class)
@HiltAndroidTest
class CropImageScreenTest(
private val testCase: DescribedBehavior<CropImageScreenRobot>,
) {

@get:Rule
@BindValue
val robotTestRule: RobotTestRule = RobotTestRule(testInstance = this)

@Inject
lateinit var cropImageScreenRobot: CropImageScreenRobot

@Test
fun runTest() {
runRobot(cropImageScreenRobot) {
testCase.execute(cropImageScreenRobot)
}
}

companion object {
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters(name = "{0}")
fun behaviors(): List<DescribedBehavior<CropImageScreenRobot>> {
return describeBehaviors(name = "CropImageScreen") {
describe("when launch") {
doIt {
setupScreenContent()
}
itShould("show screen") {
captureScreenWithChecks {
checkScreenDisplayed()
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.ui.geometry.Size
import androidx.compose.ui.geometry.toRect
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.IntRect
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.roundToIntRect
Expand All @@ -50,6 +51,8 @@ import kotlin.math.max

const val cropImageScreenRoute = "cropImage"

const val CropImageScreenTestTag = "CropImageScreenTestTag"

fun NavGraphBuilder.cropImageScreens(
onNavigationIconClick: () -> Unit,
onBackWithConfirm: () -> Unit,
Expand Down Expand Up @@ -78,6 +81,20 @@ internal sealed interface CropImageScreenState {
) : CropImageScreenState
}

@Composable
fun CropImageScreen(
onNavigationIconClick: () -> Unit,
onBackWithConfirm: () -> Unit,
modifier: Modifier = Modifier,
) {
CropImageScreen(
onNavigationIconClick = onNavigationIconClick,
onBackWithConfirm = onBackWithConfirm,
modifier = modifier,
eventFlow = rememberEventFlow(),
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun CropImageScreen(
Expand All @@ -94,7 +111,9 @@ internal fun CropImageScreen(
}

Scaffold(
modifier = modifier.fillMaxSize(),
modifier = modifier
.testTag(CropImageScreenTestTag)
.fillMaxSize(),
topBar = {
TopAppBar(
title = {
Expand Down

0 comments on commit 9b0728c

Please sign in to comment.