package com.cottondb.messages.warm import android.app.Application import androidx.compose.foundation.lazy.LazyListState import androidx.compose.ui.test.assertTextEquals import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import com.cottondb.messages.chat.Avatar import com.cottondb.messages.chat.ChatRow import com.cottondb.messages.chat.ThreadPage import com.cottondb.messages.chat.ThreadState import com.cottondb.messages.chat.Words import com.cottondb.shell.CircleGone import com.cottondb.shell.core.CottonCore import kotlinx.serialization.json.jsonObject import org.json.JSONObject import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import java.io.File /** * SHELL DRAW 3: a person no longer on Cotton (`circle.list`'s `gone`, cfc1e46c6f + 4ad9aab410) is said wherever Comms * shows them: their row in Chats (in place of the last line), the chat's header (in place of the status) and their * page. The words are the shipped circle lines', read by number as [CircleGone] reads them. Invented people. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class) class CircleGoneTest { @get:Rule val compose = createComposeRule() private val repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile } private val lines = JSONObject(File(repo, "crates/cotton-core/kits/shell/lines/circle.json").readText()).getJSONObject("detail") private val left = lines.getString("left") private val changed = lines.getString("changed") private val words = Words { set, key -> "$set:$key" } private fun j(text: String) = CottonCore.json.parseToJsonElement(text).jsonObject /** `circle.list` with one person who left and one whose number changed hands, as circle.rs lays them. */ private val gone = CircleGone.of( j( """{"title": "Your Circle", "sections": [{"id": "gone", "title": "No longer on Cotton", "rows": [ {"id": "p-lena", "number": "+15550100002", "words": "Lena Example", "detail": "$left", "state": "left", "acts": []}, {"id": "+15550100003", "number": "+15550100003", "words": "Chen Example", "detail": "$changed", "state": "changed", "acts": []}]}]}""", ), ) @Test fun the_chat_row_says_left_cotton_in_place_of_the_last_line() { val row = ChatRow.of( j("""{"thread":"t2","name":"Lena Example","group":false,"picture":{"initials":"LE","tint":2},"lastLine":{"text":"See you Sunday","mine":false},"when":"16:00","unread":0,"leading":[],"trailing":[]}"""), words, ).let { it.copy(gone = CircleGone.words(gone, "+15550100002")) } compose.setContent { WarmTheme(night = false) { RowView(row, ChatsWords("New chat", "You", "Muted", "Pinned", "Unread", "More"), {}, {}) } } compose.onNodeWithTag("chat-row-gone-t2", useUnmergedTree = true).assertTextEquals("Left Cotton") assertTrue(compose.onAllNodes(androidx.compose.ui.test.hasText("See you Sunday"), useUnmergedTree = true).fetchSemanticsNodes().isEmpty()) } @Test fun the_header_says_the_number_belongs_to_someone_else() { val t = ThreadState("t3", ThreadPage.of(j("""{"thread":"t3","header":{"name":"Chen Example","picture":{"initials":"CE","tint":1},"status":""},"items":[]}"""), words)) val acts = MessageActs({}, {}, { _, _ -> }, {}, { _, _ -> }, {}, { _, _ -> }, {}, {}, VoicePlayer(kotlinx.coroutines.MainScope())) val threadWords = ThreadWordsWarm("Back", "Call", "Video call", "Not sent", "Try again", "You", "Their page") compose.setContent { WarmTheme(night = false) { Conversation(t, LazyListState(), acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}, gone = CircleGone.words(gone, "+1 555 010 0003")) {} } } compose.onNodeWithTag("thread-gone", useUnmergedTree = true).assertTextEquals("This number belongs to someone else on Cotton now") } @Test fun the_person_page_says_left_cotton() { val words = PersonWords( "Back", "Message", "Call", "Video", "Between you", "Nothing between you yet.", { "Calls themselves $it" }, "Number", "Mute", "Unmute", "Mute notifications", "Block", "Unblock", "You blocked them.", "Close", ) val view = PersonView("Lena Example", null, Avatar("LE", 1, null), "+15550100002", "", emptyList(), emptyList(), false, false, emptyList(), emptyList()) compose.setContent { WarmTheme(night = false) { PersonPage(view.copy(gone = CircleGone.words(gone, view.number)), words, {}, {}, {}, {}, {}, {}, {}) } } compose.onNodeWithTag("person-gone", useUnmergedTree = true).assertTextEquals(left) assertEquals("Left Cotton", left) } }