63 lines · 3.3 KB · KotlinRaw
package com.cottondb.messages.warmimport android.app.Applicationimport androidx.compose.foundation.lazy.LazyListStateimport androidx.compose.ui.test.getBoundsInRootimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport com.cottondb.messages.calls.CallViewimport 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.assertTrueimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * A CALL FOLDED BEHIND CHAT (the emulator's fault, kept): Back in a call left its "tap to return" bar floating over * the page's top, where it covered a conversation's header (the person's chip and the call buttons could not be * reached) and the Chats title. The bar now stands in the page's flow and the page starts under it. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)class CallBarTest { @get:Rule val compose = createComposeRule() private fun j(text: String) = CottonCore.json.parseToJsonElement(text).jsonObject private val words = Words { set, key -> "$set:$key" } @Test fun a_folded_call_bar_stands_above_the_conversations_header_not_over_it() { val view = CallView.of(j("""{"shown":true,"phase":"live","name":"Rose Martin","picture":{"initials":"RM","tint":1},"status":"0:12","bar":"Rose Martin · tap to return", "controls":[{"id":"end","label":"End","on":false}]}""")) val t = ThreadState("t1", ThreadPage.of(j("""{"thread":"t1","header":{"name":"Rose Martin","picture":{"initials":"RM","tint":1},"status":"", "calls":[{"video":false,"label":"Call"}]},"items":[]}"""), words)) val acts = MessageActs({}, {}, { _, _ -> }, {}, { _, _ -> }, {}, { _, _ -> }, {}, {}, VoicePlayer(kotlinx.coroutines.MainScope())) compose.setContent { WarmTheme(night = false) { CallBarSlot(view, folded = true, onReturn = {}) { Conversation(t, LazyListState(), acts, ThreadWordsWarm("Back", "Call", "Video call", "Not sent", "Try again", "You", "Their page"), {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {} } } } compose.waitForIdle() val bar = compose.onNodeWithTag("call-bar").getBoundsInRoot() val back = compose.onNodeWithTag("chat-back").getBoundsInRoot() val person = compose.onNodeWithTag("chat-person").getBoundsInRoot() assertTrue("bar ${bar.bottom} over back ${back.top}", bar.bottom <= back.top) assertTrue("bar ${bar.bottom} over the person ${person.top}", bar.bottom <= person.top) } @Test fun without_a_folded_call_the_page_is_as_it_was() { val view = CallView.of(j("""{"shown":true,"phase":"live","name":"Rose Martin","picture":{"initials":"RM","tint":1},"status":"0:12","bar":"Rose","controls":[]}""")) compose.setContent { WarmTheme(night = false) { CallBarSlot(view, folded = false, onReturn = {}) { Welcome("Chat", "Line", "Sign in") {} } } } compose.waitForIdle() compose.onNodeWithTag("call-bar").assertDoesNotExist() }}