Cotton code
60 lines · 2.6 KB · KotlinRaw
package com.cottondb.books.readerimport android.app.Applicationimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.runtime.rememberimport androidx.compose.ui.geometry.Offsetimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.platform.LocalViewimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onRootimport androidx.compose.ui.test.performTouchInputimport com.cottondb.shell.LocalMaterialsimport com.cottondb.shell.Materialsimport com.cottondb.shell.ReaderFaceimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertNotNullimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * THE SEEK LINE at the screen's edge, as the emulator met it: a drag begun on the ribbon at the book's start, a * finger's width from the edge, fell in the line's inset, outside its touch band and outside the band kept from the * system's back swipe, and the book closed. The band runs to the screen's edges; the line is drawn inset in it. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)class SeekLineTest {    @get:Rule val compose = createComposeRule()    private val state = SeekLineState(0f, listOf(SeekTick(0f, "One", true), SeekTick(0.5f, "Two", false)), null, "One · 0%", "Place in the book", "Contents", null, 0.5f)    @Test    fun a_drag_from_the_edge_is_the_lines() {        var went: Float? = null        var view: android.view.View? = null        compose.setContent {            val context = LocalContext.current            view = LocalView.current            CompositionLocalProvider(LocalMaterials provides remember { Materials(context) }) {                SeekLine(state, ReaderFace.of("paper"), say = { null }, onGo = { at, _ -> went = at })            }        }        compose.waitForIdle()        // xhdpi: 2 px a dp. Down 6 dp from the left edge, inside the 20 dp inset, then along to the middle.        compose.onRoot().performTouchInput {            down(Offset(12f, 50f))            repeat(20) { moveBy(Offset((width / 2f - 12f) / 20f, 0f)) }            up()        }        compose.waitForIdle()        assertNotNull("a drag begun in the line's inset never reached the line", went)        assertEquals(0.5f, went!!, 0.05f)        val rects = view!!.systemGestureExclusionRects        assertTrue("the system's back swipe is not kept off the screen's edge: $rects", rects.any { it.left == 0 })    }}