67 lines · 2.9 KB · KotlinRaw
package com.cottondb.messages.warmimport android.app.Applicationimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.setValueimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.test.assertIsFocusedimport androidx.compose.ui.test.assertIsNotFocusedimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.performClickimport com.cottondb.shell.CodeAskWordsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport 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")}