Cotton code
81 lines · 4.0 KB · KotlinRaw
package com.cottondb.messages.warmimport android.app.Applicationimport android.view.ViewGroupimport androidx.activity.ComponentActivityimport androidx.compose.foundation.lazy.LazyListStateimport androidx.compose.runtime.Composableimport androidx.compose.ui.test.junit4.createAndroidComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.onNodeWithTextimport androidx.core.graphics.Insetsimport androidx.core.view.ViewCompatimport androidx.core.view.WindowCompatimport androidx.core.view.WindowInsetsCompatimport com.cottondb.messages.chat.Avatarimport com.cottondb.messages.chat.ChatListimport com.cottondb.messages.chat.Wordsimport com.cottondb.shell.core.CottonCoreimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * Turned sideways, the emulator's camera cutout stands at the left edge: Chats' rows, You's card and the welcome's * words start clear of it, as a person's page, a group's and New chat do. Invented people. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w731dp-h411dp-land-mdpi", application = Application::class)class CutoutTest {    @get:Rule val compose = createAndroidComposeRule<ComponentActivity>()    private val cutout = 52    private fun sideways(face: @Composable () -> Unit) {        compose.runOnUiThread { WindowCompat.setDecorFitsSystemWindows(compose.activity.window, false) }        compose.setContent { WarmTheme(night = false) { face() } }        compose.waitForIdle()        compose.runOnUiThread {            val view = compose.activity.findViewById<ViewGroup>(android.R.id.content).getChildAt(0)            ViewCompat.dispatchApplyWindowInsets(view, WindowInsetsCompat.Builder().setInsets(WindowInsetsCompat.Type.displayCutout(), Insets.of(cutout, 0, 0, 0)).build())        }        compose.waitForIdle()    }    private fun startsClear(x: Float, what: String) = assertTrue("$what starts at $x, under the cutout's $cutout", x >= cutout)    @Test    fun chats_rows_stand_clear_of_the_cutout_sideways() {        val list = ChatList.of(CottonCore.json.parseToJsonElement("""{"words":{"title":"Chats","search":"Search"},"filters":[],            "rows":[{"thread":"t1","name":"Invented Person","group":false,"source":"cotton","picture":{"initials":"IP","tint":1},            "lastLine":{"text":"See you at seven","mine":false},"when":"19:02","unread":0,"markedUnread":false,"pinned":false,"muted":false,            "archived":false,"leading":[],"trailing":[]}]}""").jsonObject, Words { set, key -> "$set:$key" })        sideways { ChatsPlace(list, LazyListState(), "", ChatsWords("New chat", "You", "Muted", "Pinned", "Unread", "More"), {}, {}, {}, { _, _ -> }, {}, {}, {}) }        startsClear(compose.onNodeWithTag("chat-title").fetchSemanticsNode().positionInRoot.x, "the title")        startsClear(compose.onNodeWithTag("chat-row-t1").fetchSemanticsNode().positionInRoot.x, "the row")    }    @Test    fun you_stands_clear_of_the_cutout_sideways() {        sideways {            YouTop("You", "Invented Person", "+15550100000", Avatar("IP", 1, null), "Edit", listOf(YouRow("sync", "Sync", "Synced just now")), {}, {})        }        startsClear(compose.onNodeWithTag("you-card").fetchSemanticsNode().positionInRoot.x, "You's card")    }    @Test    fun calls_stands_clear_of_the_cutout_sideways() {        sideways { CallsPlace(com.cottondb.messages.calls.CallsPage("Calls", "No calls yet.", "Call back", emptyList(), null), {}, {}) }        startsClear(compose.onNodeWithText("Calls").fetchSemanticsNode().positionInRoot.x, "Calls' title")    }    @Test    fun the_welcome_stands_clear_of_the_cutout_sideways() {        sideways { Welcome("Chat", "Invented words.", "Sign in") {} }        startsClear(compose.onNodeWithText("Chat").fetchSemanticsNode().positionInRoot.x, "the welcome's title")    }}