package com.cottondb.messages.warm import android.app.Application import android.view.ViewGroup import androidx.activity.ComponentActivity import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.core.graphics.Insets import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import com.cottondb.messages.chat.Avatar import com.cottondb.messages.chat.ChatList import com.cottondb.messages.chat.Words import com.cottondb.shell.core.CottonCore import kotlinx.serialization.json.jsonObject 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 /** * 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() 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(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") } }