package com.cottondb.messages.warm import android.app.Application import androidx.activity.ComponentActivity import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyListState import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performScrollToKey import androidx.compose.ui.unit.dp 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.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * Sideways, a slip standing (the recovery code, a device to approve) and the chips left Chats' rows no room at all: * they now scroll with the rows, so the rows come into view under them. Invented chats. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w731dp-h411dp-land-mdpi", application = Application::class) class ChatsRoomTest { @get:Rule val compose = createAndroidComposeRule() private fun row(i: Int) = """{"thread":"t$i","name":"Invented Example $i","group":false,"source":"whatsapp","picture":{"initials":"IE","tint":1}, "lastLine":{"text":"See you at seven","mine":false},"when":"Tue","unread":0,"markedUnread":false,"pinned":false,"muted":false, "archived":false,"leading":[],"trailing":[]}""" @Test fun sideways_with_a_slip_the_rows_scroll_into_view() { val list = ChatList.of(CottonCore.json.parseToJsonElement("""{"words":{"title":"Chats","search":"Search"}, "filters":[{"id":"all","label":"All","on":true},{"id":"waiting","label":"Waiting on you","count":2,"on":false},{"id":"groups","label":"Groups","on":false}], "rows":[${(1..30).joinToString(",") { row(it) }}]}""").jsonObject, Words { set, key -> "$set:$key" }) compose.setContent { WarmTheme(night = false) { ChatsPlace( list, LazyListState(), "", ChatsWords("New chat", "You", "Muted", "Pinned", "Unread", "More"), {}, {}, {}, { _, _ -> }, {}, {}, {}, slips = { Box(Modifier.fillMaxWidth().height(260.dp).testTag("a-slip")) }, ) } } compose.waitForIdle() compose.onNodeWithTag("chat-list").performScrollToKey("t3") compose.waitForIdle() compose.onNodeWithTag("chat-row-t3").assertIsDisplayed() } }