package com.cottondb.messages.warm import android.app.Application import androidx.compose.foundation.layout.Box import androidx.compose.foundation.text.BasicTextField import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.assertIsFocused import androidx.compose.ui.test.assertIsNotFocused import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import com.cottondb.messages.calls.CallView import com.cottondb.shell.core.CottonCore import kotlinx.serialization.json.jsonObject import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * A CALL PLACED WITH THE KEYBOARD UP (two emulators, 21 Nov 2026): Emma wrote, tapped Call, and the * keyboard stayed open over the call's Mute, Speaker and Camera. The call screen now takes the focus from the field * under it, so the keyboard goes. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class) class CallKeyboardTest { @get:Rule val compose = createComposeRule() @Test fun the_call_screen_takes_the_focus_from_the_writing_box() { val view = CallView.of(CottonCore.json.parseToJsonElement("""{"shown":true,"phase":"ringing_out","name":"Pat","picture":{"initials":"P","tint":1},"status":"Ringing…","controls":[{"id":"end","label":"End","on":false}]}""").jsonObject) var calling by mutableStateOf(false) compose.setContent { WarmTheme(night = false) { Box { var text by remember { mutableStateOf("Hello Pat") } BasicTextField(text, { text = it }, Modifier.testTag("field")) if (calling) CallScreen(view, remote = null, local = null, egl = null, onAnswer = {}, onDecline = {}, onControl = {}) } } } compose.onNodeWithTag("field").performClick() compose.onNodeWithTag("field").assertIsFocused() calling = true compose.waitForIdle() compose.onNodeWithTag("field").assertIsNotFocused() } }