2022-03-08 11:05:03 -08:00
|
|
|
package co.electriccoin.zcash.ui.screen.wallet_address.view
|
2021-12-31 05:28:16 -08:00
|
|
|
|
|
|
|
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
|
2022-05-02 12:49:49 -07:00
|
|
|
import co.electriccoin.zcash.test.UiTestPrerequisites
|
2022-03-08 11:05:03 -08:00
|
|
|
import co.electriccoin.zcash.ui.R
|
|
|
|
import co.electriccoin.zcash.ui.design.theme.ZcashTheme
|
|
|
|
import co.electriccoin.zcash.ui.test.getStringResource
|
2022-01-13 09:49:08 -08:00
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import kotlinx.coroutines.test.runTest
|
2021-12-31 05:28:16 -08:00
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
2022-03-01 05:11:23 -08:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger
|
2021-12-31 05:28:16 -08:00
|
|
|
|
2022-01-13 09:49:08 -08:00
|
|
|
@OptIn(ExperimentalCoroutinesApi::class)
|
2022-05-02 12:49:49 -07:00
|
|
|
class WalletAddressViewTest : UiTestPrerequisites() {
|
2021-12-31 05:28:16 -08:00
|
|
|
@get:Rule
|
|
|
|
val composeTestRule = createComposeRule()
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
2022-01-13 09:49:08 -08:00
|
|
|
fun initial_screen_setup() = runTest {
|
2021-12-31 05:28:16 -08:00
|
|
|
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 {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertExists()
|
|
|
|
}
|
|
|
|
|
2022-01-13 09:49:08 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.shieldedSapling.address).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertDoesNotExist()
|
|
|
|
}
|
2022-01-13 09:49:08 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.transparent.address).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertDoesNotExist()
|
|
|
|
}
|
|
|
|
composeTestRule.onNodeWithText(walletAddresses.viewingKey).also {
|
|
|
|
it.assertDoesNotExist()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
2022-01-13 09:49:08 -08:00
|
|
|
fun unified_collapses() = runTest {
|
2021-12-31 05:28:16 -08:00
|
|
|
val walletAddresses = WalletAddressesFixture.new()
|
|
|
|
newTestSetup(walletAddresses)
|
|
|
|
|
2022-01-13 09:49:08 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.unified.address).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
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 {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertDoesNotExist()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
2022-01-13 09:49:08 -08:00
|
|
|
fun shielded_sapling_expands() = runTest {
|
2021-12-31 05:28:16 -08:00
|
|
|
val walletAddresses = WalletAddressesFixture.new()
|
|
|
|
newTestSetup(walletAddresses)
|
|
|
|
|
2022-01-13 09:49:08 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.shieldedSapling.address).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
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 {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertExists()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
2022-01-13 09:49:08 -08:00
|
|
|
fun transparent_expands() = runTest {
|
2021-12-31 05:28:16 -08:00
|
|
|
val walletAddresses = WalletAddressesFixture.new()
|
|
|
|
newTestSetup(walletAddresses)
|
|
|
|
|
2022-01-13 09:49:08 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.transparent.address).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
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 {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertExists()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
2022-01-13 09:49:08 -08:00
|
|
|
fun viewing_expands() = runTest {
|
2021-12-31 05:28:16 -08:00
|
|
|
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())
|
2021-12-31 05:28:16 -08:00
|
|
|
|
|
|
|
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)
|
2021-12-31 05:28:16 -08:00
|
|
|
|
|
|
|
private class TestSetup(private val composeTestRule: ComposeContentTestRule, initialState: WalletAddresses) {
|
|
|
|
|
2022-03-01 05:11:23 -08:00
|
|
|
private val onBackCount = AtomicInteger(0)
|
2021-12-31 05:28:16 -08:00
|
|
|
|
|
|
|
fun getOnBackCount(): Int {
|
|
|
|
composeTestRule.waitForIdle()
|
2022-03-01 05:11:23 -08:00
|
|
|
return onBackCount.get()
|
2021-12-31 05:28:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
init {
|
|
|
|
composeTestRule.setContent {
|
|
|
|
ZcashTheme {
|
|
|
|
WalletAddresses(
|
|
|
|
initialState,
|
|
|
|
onBack = {
|
2022-03-01 05:11:23 -08:00
|
|
|
onBackCount.incrementAndGet()
|
2021-12-31 05:28:16 -08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|