package com.cottondb.books.reader import android.app.Application import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.remember import androidx.compose.ui.geometry.Offset import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.performTouchInput import com.cottondb.shell.LocalMaterials import com.cottondb.shell.Materials import com.cottondb.shell.ReaderFace import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import 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 }) } }