Cotton code
64 lines · 3.7 KB · KotlinRaw
package com.cottondb.messages.warmimport android.app.Applicationimport androidx.compose.foundation.lazy.LazyListStateimport androidx.compose.ui.test.junit4.createAndroidComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport com.cottondb.messages.chat.ThreadPageimport com.cottondb.messages.chat.ThreadStateimport com.cottondb.messages.chat.Wordsimport com.cottondb.shell.core.CottonCoreimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Configimport org.robolectric.annotation.GraphicsMode/** * THE HEADER ON A GROUND OF ITS OWN (the iPhone lane's find, 13d90447fe): scrolling a filled conversation showed the * page beside and under the floating header, which stood on a fade opaque only to 0.7 of 80 dp. Every point of the * header's own height, beside and below its rounds, is now the page's ground, whatever stands behind it. */@RunWith(RobolectricTestRunner::class)@GraphicsMode(GraphicsMode.Mode.NATIVE)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)class HeaderGroundTest {    @get:Rule val compose = createAndroidComposeRule<androidx.activity.ComponentActivity>()    private val words = Words { set, key -> "$set:$key" }    private val threadWords = ThreadWordsWarm("Back", "Call", "Video call", "Not sent", "Try again", "You", "Their page")    private fun j(text: String) = CottonCore.json.parseToJsonElement(text).jsonObject    @Test    fun the_header_stands_on_the_ground_however_the_page_scrolls_under_it() {        // One long message of the person's own (its warm tinted block) runs the whole page, behind the header.        val long = (1..160).joinToString(" ") { "word$it" }        val items = (1..3).joinToString(",") {            """{"item":"bubble","message":"m$it","mine":true,"kind":"text","text":"$long","head":true,"tail":true,"face":true,"time":"19:0$it","tick":"read","pinned":false,"actions":[]}"""        }        val t = ThreadState("t1", ThreadPage.of(j("""{"thread":"t1","header":{"name":"Rose Martin","picture":{"initials":"RM","tint":1},"status":"",            "calls":[{"video":false,"label":"Call"},{"video":true,"label":"Video call"}]},"items":[$items]}"""), words))        val list = LazyListState()        val acts = MessageActs({}, {}, { _, _ -> }, {}, { _, _ -> }, {}, { _, _ -> }, {}, {}, VoicePlayer(kotlinx.coroutines.MainScope()))        compose.setContent { WarmTheme(night = false) { Conversation(t, list, acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {} } }        compose.waitForIdle()        val chip = compose.onNodeWithTag("chat-person").fetchSemanticsNode().boundsInWindow        val density = compose.density.density        for (scrolled in 0 until 3) {            if (scrolled > 0) { compose.runOnIdle { list.dispatchRawDelta(300f * scrolled) }; compose.waitForIdle() }            val view = compose.activity.window.decorView            val shot = android.graphics.Bitmap.createBitmap(view.width, view.height, android.graphics.Bitmap.Config.ARGB_8888)            compose.runOnIdle { view.draw(android.graphics.Canvas(shot)) }            val ground = shot.getPixel(2, 2)            // From just under the chip's rounded foot to the header's (8 dp under it), across the page: the ground, never the page.            val from = (chip.bottom + 2 * density).toInt()            val to = (chip.bottom + 7 * density).toInt()            for (y in from..to) for (x in 0 until shot.width step 6) {                assertEquals("at ($x, $y) after $scrolled scrolls", Integer.toHexString(ground), Integer.toHexString(shot.getPixel(x, y)))            }        }    }}