package com.cottondb.messages.warm import android.app.Application import androidx.compose.foundation.layout.Column import androidx.compose.foundation.text.BasicTextField import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext 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.shell.CodeAskWords import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * THE RECOVERY CODE'S ASK over Chats (the coordinator's walk, 22 Nov 2026): after Open the keyboard stayed up over * Chats, attached to the search field, and once typed "for for" into it. Done (Open, Not now), the ask leaves no * field behind it holding the focus, so the keyboard has nothing to come back for. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class) class CodeAskTest { @get:Rule val compose = createComposeRule() private fun over(done: String) { var asking by mutableStateOf(false) var typed by mutableStateOf("") var search by mutableStateOf("") compose.setContent { WarmTheme(night = false) { val look = WarmCardLook(WarmColours.light, WarmType.of(LocalContext.current)) Column { BasicTextField(search, { search = it }, Modifier.testTag("search")) // The card as its dialog holds it (a dialog never settles under Robolectric); behind it, this page. val behind = com.cottondb.shell.rememberLetGoOfKeyboard() if (asking) look.CodeAskCard( CodeAskWords("Enter your recovery code", "XXXX", "Open", "Not now"), typed, { typed = it }, null, false, onOpen = { asking = false }, onClose = { asking = false }, behind = behind, ) } } } compose.onNodeWithTag("search").performClick() compose.onNodeWithTag("search").assertIsFocused() compose.runOnIdle { asking = true; typed = "ABCD EFGH IJKL MNOP QRST UVWX" } compose.waitForIdle() compose.onNodeWithTag(done).performClick() compose.waitForIdle() compose.onNodeWithTag("recovery-code-field").assertDoesNotExist() compose.onNodeWithTag("search").assertIsNotFocused() } @Test fun open_leaves_no_field_behind_with_the_keyboard() = over("recovery-open") @Test fun not_now_leaves_no_field_behind_with_the_keyboard() = over("recovery-not-now") }