Cotton code
350 lines · 25.4 KB · KotlinRaw
package com.cottondb.messages.warmimport androidx.compose.ui.graphics.luminanceimport kotlinx.serialization.json.jsonPrimitiveimport kotlinx.serialization.json.jsonArrayimport android.app.Applicationimport android.graphics.Bitmapimport android.graphics.Canvasimport android.graphics.LinearGradientimport android.graphics.Paintimport android.graphics.Shaderimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.lazy.LazyListStateimport androidx.compose.runtime.Composableimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalDensityimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.onRootimport androidx.compose.ui.unit.Densityimport androidx.compose.ui.unit.dpimport com.cottondb.messages.calls.CallViewimport com.cottondb.messages.calls.CallsPageimport com.cottondb.messages.chat.ChatListimport com.cottondb.messages.chat.ComposerStateimport com.cottondb.messages.chat.Composeimport com.cottondb.messages.chat.ThreadPageimport com.cottondb.messages.chat.ThreadStateimport com.cottondb.messages.chat.Wordsimport com.cottondb.shell.core.CottonCoreimport com.github.takahirom.roborazzi.captureRoboImageimport kotlinx.serialization.json.JsonObjectimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Configimport org.robolectric.annotation.GraphicsModeimport java.io.File/** * THE WARM SCREENS DRAWN with invented people and words (warm.html's, and a few of our own), light and night and at * the largest text, so each is looked at once: with CHAT_SHOTS naming a folder, each picture is kept there. Without * it, every screen is still drawn and must stand. A conversation of 5,000 messages scrolls end to end. */@RunWith(RobolectricTestRunner::class)@GraphicsMode(GraphicsMode.Mode.NATIVE)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)class WarmShotsTest {    @get:Rule val compose = createComposeRule()    private val shots: File? = System.getenv("CHAT_SHOTS")?.let { File(it).apply { mkdirs() } }    private val words = Words { set, key -> "$set:$key" }    private fun j(text: String): JsonObject = CottonCore.json.parseToJsonElement(text).jsonObject    /** A stand-in photograph: a soft two-colour wash, written once to a file the picture cache reads. */    private fun photo(name: String, a: Int, b: Int): String {        val dir = File(System.getProperty("java.io.tmpdir"), "warm-shots").apply { mkdirs() }        val f = File(dir, "$name.png")        if (!f.isFile) {            val bmp = Bitmap.createBitmap(240, 240, Bitmap.Config.ARGB_8888)            Canvas(bmp).drawRect(0f, 0f, 240f, 240f, Paint().apply { shader = LinearGradient(0f, 0f, 240f, 240f, a, b, Shader.TileMode.CLAMP) })            f.outputStream().use { bmp.compress(Bitmap.CompressFormat.PNG, 100, it) }        }        return "file:${f.path}"    }    private val rose by lazy { photo("rose", 0xFFE9B9A0.toInt(), 0xFF8C5A48.toInt()) }    private val family by lazy { photo("family", 0xFFB7C9A8.toInt(), 0xFF56704A.toInt()) }    private val akash by lazy { photo("akash", 0xFFA9B8D8.toInt(), 0xFF3F4F7A.toInt()) }    private val meena by lazy { photo("meena", 0xFFE6CF9A.toInt(), 0xFF8A6A2C.toInt()) }    private val book by lazy { photo("book", 0xFFD7B4C8.toInt(), 0xFF7A4A66.toInt()) }    private val dev by lazy { photo("dev", 0xFFC2D9D6.toInt(), 0xFF3E6E69.toInt()) }    private val dinner by lazy { photo("dinner", 0xFFF1D2A8.toInt(), 0xFF9C5B2E.toInt()) }    private fun shoot(name: String, night: Boolean = false, scale: Float = 1f, face: @Composable () -> Unit) {        compose.setContent {            val d = LocalDensity.current            CompositionLocalProvider(LocalDensity provides Density(d.density, scale)) {                WarmTheme(night = night) { Box(Modifier.fillMaxSize()) { face() } }            }        }        compose.waitForIdle()        // The pictures open off the main thread: give them a moment, then let the frames that draw them run.        repeat(3) { Thread.sleep(150); compose.mainClock.advanceTimeBy(200); compose.waitForIdle() }        shots?.let { compose.onRoot().captureRoboImage(File(it, "$name.png").path) }    }    private fun row(id: String, name: String, picture: String?, initials: String, line: String, time: String, unread: Int = 0, sender: String? = null, mine: Boolean = false, pinned: Boolean = false, group: Boolean = false) =        """{"thread":"$id","name":"$name","group":$group,"source":"cotton","picture":{"initials":"$initials","tint":1${picture?.let { ",\"photo\":\"$it\"" } ?: ""}},            "lastLine":{"text":"$line"${sender?.let { ",\"sender\":\"$it\"" } ?: ""},"mine":$mine${if (mine) ",\"tick\":\"read\"" else ""}},"when":"$time","unread":$unread,            "markedUnread":false,"pinned":$pinned,"muted":false,"archived":false,"leading":[{"act":"pinChat","label":"Pin"}],            "trailing":[{"act":"mute","label":"Mute"},{"act":"archive","label":"Archive"},{"act":"deleteChat","label":"Delete","confirm":"Delete your chat with $name?"}]}"""    private fun chatList(): ChatList = ChatList.of(j("""{"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":[${listOf(            row("t1", "Rose Martin", rose, "RM", "See you at seven then", "19:02"),            row("t2", "Family", family, "F", "photos from Sunday", "18:40", unread = 3, sender = "Dev", group = true),            row("t3", "Akash Rao", akash, "AR", "Missed call", "17:15"),            row("t4", "Meena Iyer", meena, "MI", "Sent the draft, tell me what you think", "Tue", unread = 1),            row("t5", "Book club", book, "BC", "next one is the 4th", "Mon", sender = "Lila", group = true),            row("t6", "Dev Mehta", dev, "DM", "Voice message · 0:42", "Mon"),            row("t7", "Tom Becker", null, "TB", "on my way", "Sat", mine = true),            row("t8", "प्रिया शर्मा", null, "प्र", "कल मिलते हैं, शाम छह बजे", "Fri"),        ).joinToString(",")}]}"""), words)    private fun msg(id: String, mine: Boolean, text: String, head: Boolean = true, tail: Boolean = true, extra: String = "", sender: String? = null) =        """{"item":"bubble","message":"$id","mine":$mine,"kind":"text","text":"$text","head":$head,"tail":$tail,"time":"19:0${id.last()}",           "pinned":false,"actions":["reply","react","copy","forward","delete"]${sender ?: ""}$extra}"""    private fun them(name: String?, picture: String, tint: Int, initials: String) = ""","sender":{${name?.let { "\"name\":\"$it\"," } ?: ""}"tint":"$tint","picture":{"initials":"$initials","tint":1,"photo":"$picture"}}"""    private fun page(name: String, status: String, picture: String, initials: String, items: String) = ThreadState("t1", ThreadPage.of(j("""        {"thread":"t1","header":{"name":"$name","picture":{"initials":"$initials","tint":1,"photo":"$picture"},"status":"$status",          "calls":[{"video":false,"label":"Call"},{"video":true,"label":"Video call"}]},         "items":[$items],"composer":{"thread":"t1","text":"","placeholder":"Message $name","button":"mic","buttonLabel":"Hold to record","attach":true,"attachLabel":"Attach","sendEnabled":false},         "actions":{"reply":"Reply","copy":"Copy","forward":"Forward","delete":"Delete","emoji":["👍","❤️","😂"]}}"""), words))    private fun roseThread(): ThreadState {        val r = them(null, rose, 0, "RM")        return page("Rose Martin", "", rose, "RM", listOf(            """{"item":"day","label":"Friday","numeral":"20","words":"Friday · November"}""",            msg("m1", false, "Are we still on for dinner?", sender = r),            msg("m2", true, "Yes. Seven at the usual place?"),            msg("m3", false, "Perfect. I will book.", tail = false, sender = r),            msg("m4", false, "Got the corner one", head = false, sender = r, extra = ""","media":[{"index":0,"kind":"photo","width":400,"height":300}]"""),            msg("m5", true, "Lovely. See you at seven then", extra = ""","tick":"read","reply":{"message":"m4","sender":"Rose","line":"Photo","mark":"photo"}"""),            msg("m6", true, "शाम को मिलते हैं 🙂", extra = ""","tick":"failed""""),        ).joinToString(","))    }    private fun familyThread(): ThreadState {        val d = them("Dev", dev, 0, "DM"); val m = them("Meena", meena, 1, "MI"); val a = them("Akash", akash, 2, "AR")        return page("Family", "5 people", family, "F", listOf(            """{"item":"day","label":"Friday","numeral":"20","words":"Friday · November"}""",            msg("m1", false, "Photos from Sunday are up.", tail = false, sender = d.replace("\"Dev\"", "\"Dev\"")).replace("\"head\":true", "\"head\":true").let { it.replace("\"sender\":{", "\"sender\":{") },            msg("m2", false, "Tell me which ones to print.", head = false, sender = d),            msg("m3", false, "The one by the gate, please.", sender = m),            msg("m4", true, "Second that. And the one with the dog.", extra = ""","tick":"delivered""""),            msg("m5", false, "Lunch at ours next Sunday?", sender = a, extra = ""","reactions":[{"emoji":"👍","count":"3","mine":true}]"""),            msg("m7", false, "", sender = d, extra = ""","kind":"voice","media":[{"index":0,"kind":"voice","length":"0:42","waveform":[0.1,0.2,0.3,0.25,0.15,0.3,0.2,0.1,0.28,0.31,0.2,0.12,0.22,0.3,0.18,0.1]}]"""),            msg("m8", false, "", sender = m, extra = ""","media":[{"index":0,"kind":"file","name":"Trip plan.pdf","size":"240 KB","index":"0"}]"""),        ).joinToString(","))    }    private val chatsWords = ChatsWords("New chat", "You", "Muted", "Pinned", "Unread", "More")    private val threadWords = ThreadWordsWarm("Back", "Call", "Video call", "Not sent", "Try again", "You", "Their page", "Not on Cotton yet", "Your messages will be delivered when they join.", "Invite")    private val acts = MessageActs({}, {}, { _, _ -> }, {}, { _, _ -> }, {}, { _, _ -> }, {}, {}, VoicePlayer(kotlinx.coroutines.MainScope()))    @Composable    private fun ChatsScreen() {        Box(Modifier.fillMaxSize()) {            ChatsPlace(chatList(), LazyListState(), "", chatsWords, {}, {}, {}, { _, _ -> }, {}, {}, {})            Places(listOf("Chats", "Calls", "You"), 0, Modifier.align(Alignment.BottomCenter).androidxPadding()) {}        }    }    @Composable    private fun ConversationScreen(t: ThreadState) {        val state = ComposerState()        Conversation(t, LazyListState(), acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {            WritingBox(state, Compose.of(j("""{"thread":"t1","placeholder":"Message ${t.header?.name?.substringBefore(' ')}","button":"mic","buttonLabel":"Hold to record","attach":true,"attachLabel":"Attach"}""")),                WritingWords("Send", "Attach", "Hold to record"), com.cottondb.messages.chat.VoiceRecorder(androidx.compose.ui.platform.LocalContext.current, kotlinx.coroutines.MainScope()), {}, {}, {}, {}, { true }, {})        }    }    @Test fun chats() { shoot("01-chats") { ChatsScreen() }; compose.onNodeWithTag("chat-row-t2").assertExists() }    @Test fun chats_night() = shoot("01-chats-night", night = true) { ChatsScreen() }    @Test fun chats_largest_text() = shoot("01-chats-largest", scale = 2f) { ChatsScreen() }    @Test fun conversation() { shoot("02-conversation") { ConversationScreen(roseThread()) }; compose.onNodeWithTag("retry-m6").assertExists() }    @Test fun conversation_night() = shoot("02-conversation-night", night = true) { ConversationScreen(roseThread()) }    @Test fun conversation_largest_text() = shoot("02-conversation-largest", scale = 2f) { ConversationScreen(roseThread()) }    @Test fun group() = shoot("03-group") { ConversationScreen(familyThread()) }    private val personWords = PersonWords(        "Back", "Message", "Call", "Video", "Between you", "Nothing between you yet.", { "Calls themselves $it" }, "Number", "Mute", "Unmute",        "Mute notifications", "Block", "Unblock", "You blocked them. They can't write to you or call you.", "Close",    )    private fun personView(blocked: Boolean = false) = PersonView(        "Rose Martin", "Rosie", com.cottondb.messages.chat.Avatar("RM", 1, rose), "+44 7700 900456", "", listOf(dinner, rose, meena),        listOf("Photos" to 24, "Voice messages" to 8, "Files" to 3, "Links" to 12), blocked, muted = false,        mutes = listOf(MuteFor("For 8 hours", null), MuteFor("For a week", null), MuteFor("Until I turn it back on", null)), calls = listOf(false to "Call", true to "Video call"),    )    @Test fun person() = shoot("04-person") { PersonPage(personView(), personWords, {}, {}, {}, {}, {}, {}, {}) }    @Test fun person_blocked() = shoot("04-person-blocked") { PersonPage(personView(blocked = true), personWords, {}, {}, {}, {}, {}, {}, {}) }    @Test fun person_night() = shoot("04-person-night", night = true) { PersonPage(personView(), personWords, {}, {}, {}, {}, {}, {}, {}) }    private fun say(key: String) = mapOf(        "app.group.add" to "Add people", "app.group.rename" to "Rename", "app.group.picture" to "Change picture", "app.group.members" to "Members",        "app.group.past" to "No longer in the group", "app.group.leave" to "Leave group", "app.group.you" to "You", "app.group.admin" to "Admin",        "app.group.left" to "You're no longer in this group.", "app.group.info" to "Message info", "app.group.sent" to "Sent", "app.group.delivered" to "Delivered", "app.group.read" to "Read",        "app.reach.invite" to "Invite",    )[key] ?: if (key.startsWith("members:")) "${key.removePrefix("members:")} members" else key    private fun groupView(you: String = "member", admin: Boolean = true) = GroupView.of(j("""{"title":"Family","count":5,"max":64,"you":"$you",        "can":{"send":true,"add":$admin,"remove":$admin,"rename":$admin,"picture":$admin,"admins":$admin,"leave":${you == "member"}},        "members":[{"number":"+447700900111","name":"You","you":true,"admin":true},{"number":"+447700900222","name":"Dev Mehta","admin":true},          {"number":"+447700900333","name":"Meena Iyer"},{"number":"+447700900444","name":"Akash Rao"},{"number":"+447700900555","name":"+44 7700 900555"}],        "past":[{"number":"+447700900666","name":"Tom Becker","out":"left"}]}"""))    @Test fun group_page() = shoot("11-group-page") { GroupPage(groupView(), com.cottondb.messages.chat.Avatar("F", 1, family), ::say, "Back", "Close", {}, {}, {}, {}, {}, {}) }    @Test fun group_page_member() = shoot("11-group-page-member") { GroupPage(groupView(admin = false), com.cottondb.messages.chat.Avatar("F", 1, family), ::say, "Back", "Close", {}, {}, {}, {}, {}, {}) }    @Test fun group_page_left() = shoot("11-group-page-left", night = true) { GroupPage(groupView(you = "left", admin = false), com.cottondb.messages.chat.Avatar("F", 1, family), ::say, "Back", "Close", {}, {}, {}, {}, {}, {}) }    @Test fun group_receipts() = shoot("12-receipts") {        Box(Modifier.fillMaxSize()) {            ConversationScreen(familyThread())            ReceiptsSheet(j("""{"message":"m4","state":"delivered","members":[{"number":"1","name":"Dev Mehta","state":"read"},{"number":"2","name":"Meena Iyer","state":"delivered"},{"number":"3","name":"Akash Rao","state":"sent"}]}"""), ::say, "Close") {}        }    }    @Test fun not_on_cotton_yet() {        val t = page("Lila Shah", "", rose, "LS", msg("m1", true, "Hello! Trying this new app.", extra = ""","tick":"sending"""")).let { it }        val reached = ThreadState("t1", ThreadPage.of(j("""{"thread":"t1","header":{"name":"Lila Shah","picture":{"initials":"LS","tint":1}},"reach":{"state":"notYet","waiting":"1","number":"+447700900777"},            "items":[${msg("m1", true, "Hello! Trying this new app.", extra = ""","tick":"sending"""")}]}"""), words))        check(t.chat == "t1")        shoot("14-not-on-cotton") { ConversationScreen(reached) }        compose.onNodeWithTag("chat-reach").assertExists()    }    @Test fun calls() = shoot("05-calls") {        Box(Modifier.fillMaxSize()) {            CallsPlace(CallsPage.of(j("""{"words":{"title":"Calls","empty":"No calls yet.","back":"Call back"},"rows":[                {"call":"c1","name":"Akash Rao","picture":{"initials":"AR","tint":1,"photo":"$akash"},"incoming":true,"video":false,"missed":true,"line":"Missed voice call","when":"17:15"},                {"call":"c2","name":"Rose Martin","picture":{"initials":"RM","tint":1,"photo":"$rose"},"incoming":false,"video":true,"missed":false,"line":"Video call · 12 min","when":"Tue"},                {"call":"c3","name":"Tom Becker","picture":{"initials":"TB","tint":1},"incoming":true,"video":false,"missed":false,"line":"Voice call · 3 min","when":"Sat"}]}""")), {}, {})            Places(listOf("Chats", "Calls", "You"), 1, Modifier.align(Alignment.BottomCenter).androidxPadding()) {}        }    }    @Test fun ringing() = shoot("06-ringing") {        CallScreen(CallView.of(j("""{"shown":true,"phase":"ringing_in","name":"Rose Martin","picture":{"initials":"RM","tint":1,"photo":"$rose"},"status":"Cotton voice call",            "ring":{"title":"Cotton voice call","answer":"Answer","decline":"Decline"},"controls":[]}""")), null, null, null, {}, {}, {})    }    @Test fun in_call() = shoot("07-in-call") {        CallScreen(CallView.of(j("""{"shown":true,"phase":"live","name":"Rose Martin","picture":{"initials":"RM","tint":1,"photo":"$rose"},"status":"4:12",            "controls":[{"id":"mute","label":"Mute","on":false},{"id":"speaker","label":"Speaker","on":true},{"id":"video","label":"Camera","on":false},{"id":"end","label":"End","on":false}]}""")), null, null, null, {}, {}, {})    }    /**     * LOOK (shared/DECISIONS.md "Look"): Comms in a paper, ink and face the way the core lays them (the kit's colours, an     * ink's light values on a light ground and its dark ones on a dark ground), as `look` answers them.     */    private fun look(paper: String, ink: String, face: String = "own"): JsonObject {        val kit = j(File("../../crates/cotton-core/kits/look/look.json").let { if (it.exists()) it else File("../../../crates/cotton-core/kits/look/look.json") }.readText())        val comms = kit["apps"]!!.jsonObject["messages"]!!.jsonObject        val p = comms["papers"]!!.jsonArray.map { it.jsonObject }.first { it["id"]!!.jsonPrimitive.content == paper }        val i = comms["inks"]!!.jsonArray.map { it.jsonObject }.first { it["id"]!!.jsonPrimitive.content == ink }        fun half(dark: Boolean): JsonObject {            val h = p[if (dark) "dark" else "light"]!!.jsonObject            val ground = h["ground"]!!.jsonPrimitive.content            val light = com.cottondb.shell.look.lookColour(ground)!!.luminance() > 0.18f            return JsonObject(h + i[if (light) "light" else "dark"]!!.jsonObject)        }        val files = if (face == "serif") """[{"file":"Literata.ttf","weight":400,"variable":true}]""" else "[]"        return j("""{"app":"messages","light":"$paper","dark":"$paper","ink":"$ink","face":"$face","size":1.0,"sizes_are":"scale",            "faces":[{"id":"$face","name":"F","family":"$face-family","files":$files}],"colours":{"light":${half(false)},"dark":${half(true)}}}""")    }    private fun inLook(answer: JsonObject, name: String, night: Boolean = false, face: @Composable () -> Unit) {        com.cottondb.shell.look.LookState.standForTest(answer)        try { shoot(name, night = night, face = face) } finally { com.cottondb.shell.look.LookState.standForTest(null) }    }    private val youWithLook: @Composable () -> Unit = {        Box(Modifier.fillMaxSize()) {            YouTop("You", "Asha Example", "+44 7700 900123", com.cottondb.messages.chat.Avatar("AE", 1, meena), "Edit", youRows, {}, {}, starred = "Starred messages", look = "Look" to "Warm · Warm")            Places(listOf("Chats", "Calls", "You"), 2, Modifier.align(Alignment.BottomCenter).androidxPadding()) {}        }    }    @Test fun look_default_chats() = inLook(look("warm", "terracotta"), "20-look-default-chats") { ChatsScreen() }    @Test fun look_default_conversation_night() = inLook(look("warm", "terracotta"), "20-look-default-conversation-night", night = true) { ConversationScreen(roseThread()) }    @Test fun look_default_you() { inLook(look("warm", "terracotta"), "20-look-default-you", face = youWithLook); compose.onNodeWithTag("you-row-look").assertExists() }    @Test fun look_mist_chats() = inLook(look("mist", "blue", "serif"), "21-look-mist-chats") { ChatsScreen() }    @Test fun look_mist_conversation() = inLook(look("mist", "blue", "serif"), "21-look-mist-conversation") { ConversationScreen(roseThread()) }    @Test fun look_mist_conversation_night() = inLook(look("mist", "blue", "serif"), "21-look-mist-conversation-night", night = true) { ConversationScreen(roseThread()) }    @Test fun look_dusk_you_night() = inLook(look("dusk", "green"), "22-look-dusk-you-night", night = true, face = youWithLook)    @Test fun you() = shoot("08-you") {        Box(Modifier.fillMaxSize()) {            YouTop("You", "Asha Example", "+44 7700 900123", com.cottondb.messages.chat.Avatar("AE", 1, meena), "Edit", youRows, {}, {}, starred = "Starred messages")            Places(listOf("Chats", "Calls", "You"), 2, Modifier.align(Alignment.BottomCenter).androidxPadding()) {}        }    }    private val youRows = listOf(        YouRow("sync", "Sync", "Synced at 9:53"), YouRow("claude", "Your Claude", "Can read any time"), YouRow("privacy", "Privacy", "2 blocked · read receipts off"),        YouRow("notifications", "Notifications", "On · 3 chats muted"), YouRow("storage", "Storage", "1.4 GB on this phone"),        YouRow("help", "Help and feedback", "Share a report"), YouRow("about", "About", "Version 1.4"),    )    @Test fun you_profile() = shoot("08-you-profile") {        Box(Modifier.fillMaxSize()) {            YouTop("You", "Asha Example", "+44 7700 900123", com.cottondb.messages.chat.Avatar("AE", 1, null), "Edit", youRows, {}, {})            ProfileSheet("Asha Example", com.cottondb.messages.chat.Avatar("AE", 1, null), ProfileWords("Your name", "How people see you", "Save", "Change picture", "Add a picture", "Take away picture", "Close"), false, {}, {}, {}, {})        }    }    @Test fun you_blocked() = shoot("08-you-blocked", night = true) {        Box(Modifier.fillMaxSize()) {            YouTop("You", "Asha Example", null, com.cottondb.messages.chat.Avatar("AE", 1, null), "Edit", youRows, {}, {})            BlockedSheet(listOf("+447700900999" to "Sam Doe", "+447700900998" to "+44 7700 900998"), "Blocked", "Nobody", "Unblock", "Close", {}, {})        }    }    @Test fun welcome() = shoot("00-welcome") { Welcome("Chat", "Messages and calls with the people you know. Only you and they can read them.", "Sign in with your number") {} }    @Test fun welcome_night() = shoot("00-welcome-night", night = true) { Welcome("Chat", "Messages and calls with the people you know. Only you and they can read them.", "Sign in with your number") {} }    @Test fun attach_and_delete() {        shoot("09-attach") { Box(Modifier.fillMaxSize()) { ConversationScreen(roseThread()); AttachSheet(AttachWords("Camera", "Photos and videos", "File", "Close"), {}, {}, {}, {}) } }    }    @Test fun delete_asks_first() = shoot("10-delete") { Box(Modifier.fillMaxSize()) { ChatsScreen(); Ask("Delete your chat with Rose Martin? Its messages go from this phone and your other devices.", "Delete", "Keep", {}, {}) } }    /** A conversation of 5,000 messages: drawn, then walked from the newest to the oldest and back without a stall. */    @Test fun five_thousand_messages_scroll_end_to_end() {        val r = them(null, rose, 0, "RM")        val items = (1..5000).joinToString(",") { i ->            val day = if (i % 200 == 1) """{"item":"day","label":"Day","numeral":"${1 + i / 200}","words":"Monday · March"},""" else ""            day + msg("m$i", i % 3 == 0, "Message number $i, with a few words to wrap now and then across the line", head = i % 4 == 1, tail = i % 4 == 0, sender = if (i % 3 == 0) "" else r)        }        val t = ThreadState("t1", ThreadPage.of(j("""{"thread":"t1","header":{"name":"Rose Martin","picture":{"initials":"RM","tint":1},"status":""},"items":[$items]}"""), words))        val list = LazyListState()        compose.setContent { WarmTheme(night = false) { Conversation(t, list, acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {} } }        compose.waitForIdle()        val started = System.nanoTime()        var at = 0        while (at < t.items.size - 1) {            at = minOf(t.items.size - 1, at + 250)            compose.runOnIdle { kotlinx.coroutines.runBlocking { list.scrollToItem(at) } }            compose.waitForIdle()        }        compose.runOnIdle { kotlinx.coroutines.runBlocking { list.scrollToItem(0) } }        compose.waitForIdle()        val seconds = (System.nanoTime() - started) / 1e9        assertTrue("walked 5,000 messages in ${"%.1f".format(seconds)} s", seconds < 30)        assertTrue(list.firstVisibleItemIndex == 0)    }}/** The switch's place at the foot, as the root lays it. */private fun Modifier.androidxPadding(): Modifier = this.then(Modifier.padding(bottom = 12.dp))