package com.cottondb.messages.chat import com.cottondb.shell.core.CottonCore import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.Shadows.shadowOf import org.robolectric.annotation.Config /** * One copy, one notice (OLD-LOOK item 1, 22 Nov 2026). On emulator-5554 (Android 15) Copy on a held message showed * Comms' own "Copied" pill over the system's own clipboard preview of the same words: from Android 13 the phone says * every copy itself. Comms now says "Copied" only on a phone that does not. Invented words. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], application = android.app.Application::class) class CopiedOnceTest { private val words = Words { set, key -> "$set:$key" } private fun model(phoneSays: Boolean = android.os.Build.VERSION.SDK_INT >= 33): ChatModel { val model = ChatModel(ChatData(null, null, words, CoroutineScope(SupervisorJob()), null), CoroutineScope(SupervisorJob()), phoneSays) model.prefetched["t1"] = ThreadPage.of(CottonCore.json.parseToJsonElement(""" {"thread":"t1","header":{"name":"Kavya Invented","picture":{"initials":"KI","tint":2},"source":"cotton","status":""}, "actions":{"copy":"Copy","copied":"Copied"}, "items":[{"item":"bubble","message":"m1","mine":false,"kind":"text","text":"Saffron lantern ferry.","head":true,"tail":true,"time":"09:01", "pinned":false,"actions":["copy"]}]} """).jsonObject, words) model.open("t1", unread = false) return model } private fun copyHeld(model: ChatModel): String? { var board: String? = null val m = model.thread!!.items.filterIsInstance().single() model.act(m, Act("copy", "Copy")) { board = it } shadowOf(android.os.Looper.getMainLooper()).idle() return board } @Test fun on_a_phone_that_says_every_copy_itself_comms_says_nothing_more() { val model = model() assertTrue("Android 13 and later preview every copy", model.phoneSaysCopied) assertEquals("Saffron lantern ferry.", copyHeld(model)) assertNull("one copy, one notice: the phone's", model.said) model.copied("Copied") assertNull(model.said) } @Test fun on_an_older_phone_comms_says_copied_once() { val model = model(phoneSays = false) assertEquals("Saffron lantern ferry.", copyHeld(model)) assertEquals("Copied", model.said) } }