secant-android-wallet/ui-lib/src/androidTest/java/cash/z/ecc/ui/screen/wallet_address/view/WalletAddressViewTest.kt

178 lines
5.5 KiB
Kotlin
Raw Normal View History

package cash.z.ecc.ui.screen.wallet_address.view
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.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.filters.MediumTest
import cash.z.ecc.sdk.fixture.WalletAddressesFixture
import cash.z.ecc.sdk.model.WalletAddresses
import cash.z.ecc.ui.R
import cash.z.ecc.ui.test.getStringResource
import cash.z.ecc.ui.theme.ZcashTheme
2022-01-13 09:49:08 -08:00
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
2022-01-13 09:49:08 -08:00
@OptIn(ExperimentalCoroutinesApi::class)
class WalletAddressViewTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
@MediumTest
2022-01-13 09:49:08 -08:00
fun initial_screen_setup() = runTest {
val walletAddresses = WalletAddressesFixture.new()
newTestSetup(walletAddresses)
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_unified)).also {
it.assertExists()
}
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_shielded_sapling)).also {
it.assertExists()
}
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_transparent)).also {
it.assertExists()
}
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_viewing_key)).also {
it.assertExists()
}
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.unified.address).also {
it.assertExists()
}
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.shieldedSapling.address).also {
it.assertDoesNotExist()
}
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.transparent.address).also {
it.assertDoesNotExist()
}
composeTestRule.onNodeWithText(walletAddresses.viewingKey).also {
it.assertDoesNotExist()
}
}
@Test
@MediumTest
2022-01-13 09:49:08 -08:00
fun unified_collapses() = runTest {
val walletAddresses = WalletAddressesFixture.new()
newTestSetup(walletAddresses)
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.unified.address).also {
it.assertExists()
}
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_unified)).also {
it.assertExists()
it.performClick()
}
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.unified.address).also {
it.assertDoesNotExist()
}
}
@Test
@MediumTest
2022-01-13 09:49:08 -08:00
fun shielded_sapling_expands() = runTest {
val walletAddresses = WalletAddressesFixture.new()
newTestSetup(walletAddresses)
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.shieldedSapling.address).also {
it.assertDoesNotExist()
}
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_shielded_sapling)).also {
it.assertExists()
it.performClick()
}
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.shieldedSapling.address).also {
it.assertExists()
}
}
@Test
@MediumTest
2022-01-13 09:49:08 -08:00
fun transparent_expands() = runTest {
val walletAddresses = WalletAddressesFixture.new()
newTestSetup(walletAddresses)
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.transparent.address).also {
it.assertDoesNotExist()
}
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_transparent)).also {
it.assertExists()
it.performClick()
}
2022-01-13 09:49:08 -08:00
composeTestRule.onNodeWithText(walletAddresses.transparent.address).also {
it.assertExists()
}
}
@Test
@MediumTest
2022-01-13 09:49:08 -08:00
fun viewing_expands() = runTest {
val walletAddresses = WalletAddressesFixture.new()
newTestSetup(walletAddresses)
composeTestRule.onNodeWithText(walletAddresses.viewingKey).also {
it.assertDoesNotExist()
}
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_viewing_key)).also {
it.assertExists()
it.performClick()
}
composeTestRule.onNodeWithText(walletAddresses.viewingKey).also {
it.assertExists()
}
}
@Test
@MediumTest
2022-01-13 09:49:08 -08:00
fun back() = runTest {
val testSetup = newTestSetup(WalletAddressesFixture.new())
assertEquals(0, testSetup.getOnBackCount())
composeTestRule.onNodeWithContentDescription(getStringResource(R.string.wallet_address_back_content_description)).also {
it.performClick()
}
assertEquals(1, testSetup.getOnBackCount())
}
2022-01-13 09:49:08 -08:00
private fun newTestSetup(initialState: WalletAddresses) = TestSetup(composeTestRule, initialState)
private class TestSetup(private val composeTestRule: ComposeContentTestRule, initialState: WalletAddresses) {
private var onBackCount = 0
fun getOnBackCount(): Int {
composeTestRule.waitForIdle()
return onBackCount
}
init {
composeTestRule.setContent {
ZcashTheme {
WalletAddresses(
initialState,
onBack = {
onBackCount++
}
)
}
}
}
}
}