87 lines · 4.9 KB · KotlinRaw
package com.cottondb.messages.warmimport android.app.Applicationimport androidx.compose.foundation.lazy.LazyListStateimport androidx.compose.ui.test.assertTextEqualsimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport com.cottondb.messages.chat.Avatarimport com.cottondb.messages.chat.ChatRowimport com.cottondb.messages.chat.ThreadPageimport com.cottondb.messages.chat.ThreadStateimport com.cottondb.messages.chat.Wordsimport com.cottondb.shell.CircleGoneimport com.cottondb.shell.core.CottonCoreimport kotlinx.serialization.json.jsonObjectimport org.json.JSONObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Configimport 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) }}