Yokan / rebuild
Course 1 8624561

DetailActionRowTest.kt

composeApp/src/desktopTest/kotlin/eu/friedcutlet/yokan/ui/screens/detail/DetailActionRowTest.kt

test / fixture70 lines
1package eu.friedcutlet.yokan.ui.screens.detail23import androidx.compose.foundation.layout.Column4import androidx.compose.ui.ImageComposeScene5import androidx.compose.ui.geometry.Offset6import androidx.compose.ui.input.pointer.PointerEventType7import eu.friedcutlet.yokan.data.DefaultYokanRepository8import eu.friedcutlet.yokan.database.DbManga9import eu.friedcutlet.yokan.database.InMemoryYokanDatabase10import eu.friedcutlet.yokan.database.emptySnapshot11import eu.friedcutlet.yokan.ui.theme.YokanTheme12import java.util.concurrent.FutureTask13import javax.swing.SwingUtilities14import kotlin.test.Test15import kotlin.test.assertEquals1617class DetailActionRowTest {18    @Test fun migrationImmediatelyFollowsWebViewOnPhoneAndDesktop() {19        for (width in listOf(360, 1024)) checkActions(width, showWeb = true)20    }2122    @Test fun migrationRemainsAvailableWhenWebViewIsHidden() {23        checkActions(360, showWeb = false)24    }2526    private fun checkActions(width: Int, showWeb: Boolean) {27        val repository = DefaultYokanRepository(InMemoryYokanDatabase(emptySnapshot().copy(28            mangas = listOf(DbManga(id = 1, name = "Test title")),29        )))30        val manga = checkNotNull(repository.manga(1))31        val clicks = mutableListOf<String>()32        val scene = onUi { ImageComposeScene(width, 140) {33            YokanTheme(darkTheme = false) {34                Column {35                    DetailActionRow(36                        manga = manga, trackCount = 0, showWeb = showWeb,37                        onFavorite = { clicks += "favorite" }, onFavoriteLongClick = null,38                        automaticUpdateDays = null, onSmartUpdate = { clicks += "updates" },39                        onTrack = { clicks += "track" }, onWeb = { clicks += "web" },40                        onMigrate = { clicks += "migrate" },41                    )42                }43            }44        } }45        try {46            var time = 0L47            fun render() = onUi { time += 100_000_000L; scene.render(time).close() }48            repeat(4) { render() }49            fun click(fraction: Float) {50                onUi {51                    val point = Offset(width * fraction, 24f)52                    scene.sendPointerEvent(PointerEventType.Press, point)53                    scene.sendPointerEvent(PointerEventType.Release, point)54                }55                render()56            }57            if (showWeb) click(.7f) // Fourth of five equal-width actions.58            click(if (showWeb) .9f else 5f / 6f)59            assertEquals(if (showWeb) listOf("web", "migrate") else listOf("migrate"), clicks)60        } finally {61            onUi { scene.close() }62        }63    }6465    private fun <T> onUi(block: () -> T): T {66        val task = FutureTask<T> { block() }67        SwingUtilities.invokeAndWait(task)68        return task.get()69    }70}71

Search chapters, reference and source filenames.