package com.cottondb.messages.warmimport android.app.Applicationimport androidx.compose.foundation.lazy.LazyListStateimport androidx.compose.ui.test.assertCountEqualsimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onAllNodesWithTextimport androidx.compose.ui.test.onNodeWithTagimport com.cottondb.messages.chat.Itemimport com.cottondb.messages.chat.ThreadPageimport com.cottondb.messages.chat.ThreadStateimport com.cottondb.messages.chat.Wordsimport com.cottondb.shell.core.CottonCoreimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * THEIR PICTURE ONCE OVER THEIR WORDS (the iPhone lane's find, kept): in an imported chat whose lines are minutes * apart every line starts a run (`head`), and a starred bubble answered alone is a run of its own; the picture, and * in a group the name, stand only where the core answers `face`. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)classTheirPictureOnceTest { @get:Ruleval compose = createComposeRule()privateval words = Words { set, key -> "$set:$key" }privateval threadWords = ThreadWordsWarm("Back", "Call", "Video call", "Not sent", "Try again", "You", "Their page")privatefun j(text: String) = CottonCore.json.parseToJsonElement(text).jsonObjectprivateval asha = """{"name":"Asha Rao","tint":2,"picture":{"initials":"AR","tint":2}}"""/** Each line its own run (minutes apart), as the core answers an imported chat. */privatefun theirs(id: String, text: String, face: Boolean, starred: Boolean = false) ="""{"item":"bubble","message":"$id","mine":false,"kind":"text","text":"$text","sender":$asha,"head":true,"tail":true,"face":$face,"time":"19:0${id.last()}","pinned":false,"starred":$starred,"actions":["reply"]}"""privatefun mine(id: String, text: String) ="""{"item":"bubble","message":"$id","mine":true,"kind":"text","text":"$text","head":true,"tail":true,"face":true,"time":"19:05","tick":"sent","pinned":false,"actions":["reply"]}""" @Testfun their_picture_and_name_stand_once_over_their_words_however_long_they_paused() {val items = listOf( theirs("a1", "Leaving now", face = true), theirs("a2", "Traffic is bad", face = false), theirs("a3", "Almost there", face = false, starred = true), mine("b4", "See you soon"), theirs("a5", "Here", face = true), ).joinToString(",")val t = ThreadState("t1", ThreadPage.of(j("""{"thread":"t1","header":{"name":"Hill trip","picture":{"initials":"HT","tint":1},"status":"","group":true},"items":[$items]}"""), words))val acts = MessageActs({}, {}, { _, _ -> }, {}, { _, _ -> }, {}, { _, _ -> }, {}, {}, VoicePlayer(kotlinx.coroutines.MainScope())) compose.setContent { WarmTheme(night = false) { Conversation(t, LazyListState(), acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {} } } compose.waitForIdle() compose.onNodeWithTag("face-a1", useUnmergedTree = true).assertExists() compose.onNodeWithTag("face-a2", useUnmergedTree = true).assertDoesNotExist() compose.onNodeWithTag("face-a3", useUnmergedTree = true).assertDoesNotExist() compose.onNodeWithTag("face-a5", useUnmergedTree = true).assertExists()// The group's name: over a1 and again over a5 (after the person's own words), never over a2 or a3. compose.onAllNodesWithText("Asha Rao", useUnmergedTree = true).assertCountEquals(2)// A star answered alone (head and tail, as `bubble_of` lays it between its neighbours) keeps its place. compose.runOnIdle { t.sent(Item.of(j(theirs("a3", "Almost there", face = false, starred = true)), words)) } compose.waitForIdle() compose.onNodeWithTag("face-a3", useUnmergedTree = true).assertDoesNotExist() } @Testfun a_core_before_face_still_draws_the_picture_at_a_runs_head() {val old = """{"item":"bubble","message":"x1","mine":false,"kind":"text","text":"Hi","sender":$asha,"head":true,"tail":true,"time":"19:00","pinned":false,"actions":[]}"""val m = Item.of(j(old), words) asItem.Message assertEquals(true, m.face) assertEquals("Asha Rao", m.name) }}