package com.cottondb.messages.warm import android.app.Application import androidx.compose.foundation.lazy.LazyListState import androidx.compose.ui.test.getBoundsInRoot import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import com.cottondb.messages.calls.CallView import com.cottondb.messages.chat.ThreadPage import com.cottondb.messages.chat.ThreadState import com.cottondb.messages.chat.Words import com.cottondb.shell.core.CottonCore import kotlinx.serialization.json.jsonObject 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 /** * 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() } }