secant-android-wallet/ui-lib/src/androidTest/java/co/electriccoin/zcash/ui/screen/restore/view/RestoreViewTest.kt

237 lines
7.3 KiB
Kotlin
Raw Normal View History

package co.electriccoin.zcash.ui.screen.restore.view
2021-12-09 12:21:30 -08:00
import android.content.Context
import android.view.inputmethod.InputMethodManager
import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.test.filters.MediumTest
import cash.z.ecc.android.bip39.Mnemonics
import cash.z.ecc.sdk.fixture.SeedPhraseFixture
import cash.z.ecc.sdk.model.SeedPhrase
import co.electriccoin.zcash.test.UiTestPrerequisites
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.design.component.CommonTag
import co.electriccoin.zcash.ui.design.theme.ZcashTheme
import co.electriccoin.zcash.ui.screen.restore.RestoreTag
import co.electriccoin.zcash.ui.screen.restore.state.WordList
[#310] [Scaffold] Progress Status Circular Bar * [#310] [Scaffold] Progress Status Circular Bar - Added Z to Home ZECs balance - Added USD balance text to Home - Prepared Text extension functions for both - Provided Zatoshi to USD conversion methods + filed related SDK conversion issue * Update Home screen UI with progress bars - Implemented scaffolding UI of progress bars - Added related texts to strings * Update Home screen UI with progress bars - Connected some of the implemented UI elements to SDK values - Added app update information to Home screen - Update WalletSnapshot with progress field * Update Home screen UI with progress bars - Capturing and handling errors from SDK Synchronizer. - Added related error strings. - Simplified Home screen UI. * Zboto font added. Load it in runtime. Import to Typography. * Updated ZEC sign icon. * Draw ZEC balance with Zboto font * Simplify Home screen balances assigning * Switch to PercentDecimal progress representatiton * Support different locales while working with fiat currency * Fix bug in checking of fiat currency value * Generalize strings to provide possibility of other fiat currencies * Add fiat currency conversion states mechanism * Add TODO comment with reference to follow up SynchronizerError issue * Add WalletDisplayValues to simplify HomeView composable * Add CurrencyConversion class for connection to Price API (and convert Zatoshi to fiat currency) * Add basic HomeView tests * Add basic HomeViewIntegration test * Review changes - Used Duration API for times - Allow injecting clock into currency conversion - Moved FiatCurrencyConversionRateState to sdk-ext-ui because I suspect that we’ll consider this to be a UI object. I based this on the fact that current/stale cutoff values are arbitrary and probably should be the domain of the UI rather than the SDK. - Added some tests, although additional coverage is needed - Added fixtures for model objects * Minor code refactoring - Move UpdateInfoFixture class to fixture dir - Remove unnecessary annotation - Add common application context method to test suite - Fix Test class import - Move several WalletSnapshotFixture parameters to const fields * Add WalletDisplayValuesTest to cover the model class. * Fix import after changes merged * Use the new MonetarySeparatorsFixture in related tests * Add a few basic Zatoshi -> USD conversion tests * Turn on core lib desugaring for sdk-ext-ui-lib module * Make WalletDisplayValues a data class I think there may be some instances where this can help with recomposition * Add preference key for fiat currency This allows us to configure reading the value with observers correctly, even if we don’t allow the user to change it right now. * Delegate symbol and formatting to JVM * Add tests for Locale Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-07-13 00:16:05 -07:00
import co.electriccoin.zcash.ui.test.getAppContext
import co.electriccoin.zcash.ui.test.getStringResource
2021-12-09 12:21:30 -08:00
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import java.util.Locale
import java.util.concurrent.atomic.AtomicInteger
2021-12-09 12:21:30 -08:00
class RestoreViewTest : UiTestPrerequisites() {
2021-12-09 12:21:30 -08:00
@get:Rule
val composeTestRule = createComposeRule()
@Test
@MediumTest
fun keyboard_appears_on_launch() {
newTestSetup(emptyList())
composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.assertIsFocused()
}
[#310] [Scaffold] Progress Status Circular Bar * [#310] [Scaffold] Progress Status Circular Bar - Added Z to Home ZECs balance - Added USD balance text to Home - Prepared Text extension functions for both - Provided Zatoshi to USD conversion methods + filed related SDK conversion issue * Update Home screen UI with progress bars - Implemented scaffolding UI of progress bars - Added related texts to strings * Update Home screen UI with progress bars - Connected some of the implemented UI elements to SDK values - Added app update information to Home screen - Update WalletSnapshot with progress field * Update Home screen UI with progress bars - Capturing and handling errors from SDK Synchronizer. - Added related error strings. - Simplified Home screen UI. * Zboto font added. Load it in runtime. Import to Typography. * Updated ZEC sign icon. * Draw ZEC balance with Zboto font * Simplify Home screen balances assigning * Switch to PercentDecimal progress representatiton * Support different locales while working with fiat currency * Fix bug in checking of fiat currency value * Generalize strings to provide possibility of other fiat currencies * Add fiat currency conversion states mechanism * Add TODO comment with reference to follow up SynchronizerError issue * Add WalletDisplayValues to simplify HomeView composable * Add CurrencyConversion class for connection to Price API (and convert Zatoshi to fiat currency) * Add basic HomeView tests * Add basic HomeViewIntegration test * Review changes - Used Duration API for times - Allow injecting clock into currency conversion - Moved FiatCurrencyConversionRateState to sdk-ext-ui because I suspect that we’ll consider this to be a UI object. I based this on the fact that current/stale cutoff values are arbitrary and probably should be the domain of the UI rather than the SDK. - Added some tests, although additional coverage is needed - Added fixtures for model objects * Minor code refactoring - Move UpdateInfoFixture class to fixture dir - Remove unnecessary annotation - Add common application context method to test suite - Fix Test class import - Move several WalletSnapshotFixture parameters to const fields * Add WalletDisplayValuesTest to cover the model class. * Fix import after changes merged * Use the new MonetarySeparatorsFixture in related tests * Add a few basic Zatoshi -> USD conversion tests * Turn on core lib desugaring for sdk-ext-ui-lib module * Make WalletDisplayValues a data class I think there may be some instances where this can help with recomposition * Add preference key for fiat currency This allows us to configure reading the value with observers correctly, even if we don’t allow the user to change it right now. * Delegate symbol and formatting to JVM * Add tests for Locale Co-authored-by: Carter Jernigan <git@carterjernigan.com>
2022-07-13 00:16:05 -07:00
val inputMethodManager = getAppContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
2021-12-09 12:21:30 -08:00
assertTrue(inputMethodManager.isAcceptingText)
}
@Test
@MediumTest
fun autocomplete_suggestions_appear() {
newTestSetup(emptyList())
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.performTextInput("ab")
// Make sure text isn't cleared
it.assertTextContains("ab")
}
composeTestRule.onNode(hasText("abandon") and hasTestTag(RestoreTag.AUTOCOMPLETE_ITEM)).also {
it.assertExists()
}
composeTestRule.onNode(hasText("able") and hasTestTag(RestoreTag.AUTOCOMPLETE_ITEM)).also {
it.assertExists()
}
}
@Test
@MediumTest
fun choose_autocomplete() {
newTestSetup(emptyList())
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.performTextInput("ab")
}
composeTestRule.onNode(hasText("abandon") and hasTestTag(RestoreTag.AUTOCOMPLETE_ITEM)).also {
it.performClick()
}
composeTestRule.onNodeWithTag(RestoreTag.AUTOCOMPLETE_LAYOUT).also {
it.assertDoesNotExist()
}
composeTestRule.onNode(hasText("abandon") and hasTestTag(CommonTag.CHIP), useUnmergedTree = true).also {
it.assertExists()
}
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.assertTextEquals("")
}
}
@Test
@MediumTest
fun type_full_word() {
newTestSetup(emptyList())
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.performTextInput("abandon")
}
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.assertTextEquals("")
}
composeTestRule.onNodeWithTag(RestoreTag.AUTOCOMPLETE_LAYOUT).also {
it.assertDoesNotExist()
}
composeTestRule.onNode(hasText("abandon") and hasTestTag(CommonTag.CHIP), useUnmergedTree = true).also {
it.assertExists()
}
composeTestRule.onNodeWithTag(RestoreTag.SEED_WORD_TEXT_FIELD).also {
it.assertTextEquals("")
}
}
@Test
@MediumTest
fun invalid_phrase_does_not_progress() {
newTestSetup(generateSequence { "abandon" }.take(SeedPhrase.SEED_PHRASE_SIZE).toList())
composeTestRule.onNodeWithText(getStringResource(R.string.restore_complete_header)).also {
it.assertDoesNotExist()
}
}
@Test
@MediumTest
fun finish_appears_after_24_words() {
newTestSetup(SeedPhraseFixture.new().split)
composeTestRule.onNodeWithText(getStringResource(R.string.restore_complete_header)).also {
it.assertExists()
}
}
@Test
@MediumTest
fun click_take_to_wallet() {
val testSetup = newTestSetup(SeedPhraseFixture.new().split)
assertEquals(0, testSetup.getOnFinishedCount())
composeTestRule.onNodeWithText(getStringResource(R.string.restore_button_see_wallet)).also {
it.performClick()
}
assertEquals(1, testSetup.getOnFinishedCount())
}
@Test
@MediumTest
fun back() {
val testSetup = newTestSetup()
assertEquals(0, testSetup.getOnBackCount())
composeTestRule.onNodeWithContentDescription(getStringResource(R.string.restore_back_content_description)).also {
it.performClick()
}
assertEquals(1, testSetup.getOnBackCount())
}
@Test
@MediumTest
fun clear() {
newTestSetup(listOf("abandon"))
composeTestRule.onNode(hasText("abandon") and hasTestTag(CommonTag.CHIP), useUnmergedTree = true).also {
it.assertExists()
}
composeTestRule.onNodeWithText(getStringResource(R.string.restore_button_clear)).also {
it.performClick()
}
composeTestRule.onNode(hasText("abandon") and hasTestTag(CommonTag.CHIP), useUnmergedTree = true).also {
it.assertDoesNotExist()
}
}
private fun newTestSetup(initialState: List<String> = emptyList()) = TestSetup(composeTestRule, initialState)
private class TestSetup(private val composeTestRule: ComposeContentTestRule, initialState: List<String>) {
private val state = WordList(initialState)
private val onBackCount = AtomicInteger(0)
2021-12-09 12:21:30 -08:00
private val onFinishedCount = AtomicInteger(0)
2021-12-09 12:21:30 -08:00
fun getUserInputWords(): List<String> {
composeTestRule.waitForIdle()
return state.current.value
}
fun getOnBackCount(): Int {
composeTestRule.waitForIdle()
return onBackCount.get()
2021-12-09 12:21:30 -08:00
}
fun getOnFinishedCount(): Int {
composeTestRule.waitForIdle()
return onFinishedCount.get()
2021-12-09 12:21:30 -08:00
}
init {
composeTestRule.setContent {
ZcashTheme {
RestoreWallet(
Mnemonics.getCachedWords(Locale.ENGLISH.language).toSortedSet(),
state,
onBack = {
onBackCount.incrementAndGet()
2021-12-09 12:21:30 -08:00
},
paste = { "" },
onFinished = {
onFinishedCount.incrementAndGet()
2022-06-22 02:48:19 -07:00
}
2021-12-09 12:21:30 -08:00
)
}
}
}
}
}