[#897] Fix failing keyboard_disappears_after_seed

* [#897] Fix failing keyboard_disappears_after_seed

* Rework test
This commit is contained in:
Honza Rychnovský 2023-07-06 11:16:28 +02:00 committed by GitHub
parent f2a50dd7bc
commit e1eb66326c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 29 deletions

View File

@ -11,7 +11,6 @@ import cash.z.ecc.android.sdk.model.WalletAddress
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.design.theme.ZcashTheme
import co.electriccoin.zcash.ui.test.getStringResource
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Rule
@ -23,7 +22,6 @@ import java.util.concurrent.atomic.AtomicInteger
* for that currently. A future enhancement could take a screenshot and try to analyze the
* screenshot contents.
*/
@OptIn(ExperimentalCoroutinesApi::class)
class ReceiveViewTest {
@get:Rule
val composeTestRule = createComposeRule()

View File

@ -4,9 +4,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build.VERSION_CODES
import android.os.SystemClock
import android.view.inputmethod.InputMethodManager
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertCountEquals
@ -14,7 +12,10 @@ import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performKeyInput
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.pressKey
import androidx.compose.ui.test.withKeyDown
import androidx.test.filters.MediumTest
@ -27,13 +28,13 @@ import co.electriccoin.zcash.ui.design.component.CommonTag
import co.electriccoin.zcash.ui.screen.restore.RestoreTag
import co.electriccoin.zcash.ui.screen.restore.model.RestoreStage
import co.electriccoin.zcash.ui.test.getAppContext
import co.electriccoin.zcash.ui.test.getStringResource
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import kotlin.test.Ignore
import kotlin.test.assertFalse
import kotlin.time.Duration.Companion.seconds
// Non-multiplatform tests that require interacting with the Android system (e.g. clipboard, Context)
@ -62,7 +63,7 @@ class RestoreViewAndroidTest : UiTestPrerequisites() {
assertTrue(inputMethodManager.isAcceptingText)
}
@OptIn(ExperimentalTestApi::class, ExperimentalComposeUiApi::class)
@OptIn(ExperimentalTestApi::class)
@Test
@MediumTest
// Functionality should be compatible with Android 27+, but a bug in the Android framework causes a crash
@ -106,42 +107,45 @@ class RestoreViewAndroidTest : UiTestPrerequisites() {
}
}
@OptIn(ExperimentalTestApi::class, ExperimentalComposeUiApi::class)
@Test
@MediumTest
@SdkSuppress(minSdkVersion = VERSION_CODES.TIRAMISU)
fun keyboard_disappears_after_seed() {
fun keyboard_disappears_after_correct_seed_inserted() {
newTestSetup()
composeTestRule.waitForIdle()
// This implementation stopped working with Compose 1.4.0, so we're using the clipboard instead
// composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
// it.performTextInput(SeedPhraseFixture.SEED_PHRASE)
// }
copyToClipboard(
getAppContext(),
SeedPhraseFixture.SEED_PHRASE
)
// Insert uncompleted seed words
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.performKeyInput {
withKeyDown(Key.CtrlLeft) {
pressKey(Key.V)
}
}
it.performTextInput("test")
}
// There appears to be a bug introduced in Compose 1.4.0 which makes this necessary
composeTestRule.mainClock.autoAdvance = false
val imm = getAppContext().getSystemService(Context.INPUT_METHOD_SERVICE)
as InputMethodManager
// Test that the input seed text field is still expecting an input, as the inserted seed words are not complete
composeTestRule.waitUntil(5.seconds.inWholeMilliseconds) {
imm.isAcceptingText
}
composeTestRule.waitForIdle()
val inputMethodManager = getAppContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
kotlin.runCatching { assertFalse(inputMethodManager.isAcceptingText) }.onFailure {
SystemClock.sleep(2.seconds.inWholeMilliseconds)
assertFalse(inputMethodManager.isAcceptingText)
// Clear test seed words
composeTestRule.onNodeWithText(getStringResource(R.string.restore_button_clear)).also {
it.performClick()
}
composeTestRule.waitForIdle()
// Insert complete seed words
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.performTextInput(SeedPhraseFixture.SEED_PHRASE)
}
// Test that the input seed text field is not expecting an input anymore, as the inserted seed words are
// complete
composeTestRule.waitUntil(5.seconds.inWholeMilliseconds) {
!imm.isAcceptingText
}
}