package com.cottondb.messages.warm import android.app.Application import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText import com.cottondb.messages.chat.ChatData import com.cottondb.messages.chat.ChatModel import com.cottondb.messages.chat.ThreadPage import com.cottondb.messages.chat.Words import com.cottondb.shell.core.CottonCore import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.runBlocking 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 /** * Seen on an emulator (21 Nov 2026): Meera set Disappearing messages to 24 hours from Kabir's page and went Back: the * header said "Disappearing messages: 24 hours", but "You turned on disappearing messages…" stood below the screen, * found only by scrolling down, though the conversation had stood at its foot. Invented numbers and words. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class) class LineAtFootTest { @get:Rule val compose = createComposeRule() private val words = Words { set, key -> "$set:$key" } private val threadWords = ThreadWordsWarm("Back", "Call", "Video call", "Not sent", "Try again", "You", "Their page") private val acts = MessageActs({}, {}, { _, _ -> }, {}, { _, _ -> }, {}, { _, _ -> }, {}, {}, VoicePlayer(kotlinx.coroutines.MainScope())) private val line = "You turned on disappearing messages. New messages will disappear 24 hours after they're sent." private fun page(foot: String) = ThreadPage.of(CottonCore.json.parseToJsonElement(""" {"thread":"t1","header":{"name":"+15550100123","picture":{"initials":"","tint":1},"source":"cotton","status":"","calls":[]}, "items":[${(1..24).joinToString(",") { """{"item":"bubble","message":"m$it","mine":${it % 2 == 0},"kind":"text","text":"Invented words $it","head":true,"tail":true,"time":"20:0${it % 10}","pinned":false,"actions":["reply"]}""" }}$foot]} """).jsonObject, words) @Test fun a_line_set_from_the_page_stands_at_the_foot_on_going_back() { val model = ChatModel(ChatData(null, null, words, CoroutineScope(SupervisorJob()), null), CoroutineScope(SupervisorJob())) model.prefetched["t1"] = page("") model.open("t1", unread = false) compose.setContent { WarmTheme(night = false) { Conversation(model.thread!!, model.threadList, acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {} } } compose.waitForIdle() compose.onNodeWithText("Invented words 24").assertIsDisplayed() runBlocking { model.actOn("t1", work = {}, read = { page(""",{"item":"event","message":"e1","text":"$line"}""") }) } compose.waitForIdle() compose.onNodeWithText(line).assertIsDisplayed() } // Seen on two emulators (21 Nov 2026): Tara called Meera, who declined: Tara's conversation, at its foot, had the // line "Voice call · Declined" below the screen, found only by closing and opening it again. @Test fun a_call_ended_puts_its_line_at_the_foot_in_sight() { val model = ChatModel(ChatData(null, null, words, CoroutineScope(SupervisorJob()), null), CoroutineScope(SupervisorJob())) model.prefetched["t1"] = page("") model.open("t1", unread = false) compose.setContent { WarmTheme(night = false) { Conversation(model.thread!!, model.threadList, acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {} } } compose.waitForIdle() runBlocking { model.callEnded { page(""",{"item":"event","message":"c1","text":"Voice call · Declined"}""") } } compose.waitForIdle() compose.onNodeWithText("Voice call · Declined").assertIsDisplayed() } }