2022-06-22 02:48:19 -07:00
|
|
|
package co.electriccoin.zcash.ui.screen.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
|
2023-07-17 03:33:14 -07:00
|
|
|
import androidx.compose.ui.test.onNodeWithTag
|
2021-12-31 05:28:16 -08:00
|
|
|
import androidx.compose.ui.test.onNodeWithText
|
|
|
|
import androidx.compose.ui.test.performClick
|
|
|
|
import androidx.test.filters.MediumTest
|
2023-02-17 03:05:23 -08:00
|
|
|
import cash.z.ecc.android.sdk.fixture.WalletAddressesFixture
|
|
|
|
import cash.z.ecc.android.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
|
2023-07-17 03:33:14 -07:00
|
|
|
import co.electriccoin.zcash.ui.screen.address.WalletAddressesTag
|
2022-03-08 11:05:03 -08:00
|
|
|
import co.electriccoin.zcash.ui.test.getStringResource
|
2022-01-13 09:49:08 -08:00
|
|
|
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-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()
|
|
|
|
}
|
2022-11-25 00:30:27 -08:00
|
|
|
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_sapling)).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertExists()
|
|
|
|
}
|
|
|
|
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_transparent)).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-11-25 00:30:27 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.sapling.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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-11-25 00:30:27 -08:00
|
|
|
fun sapling_expands() = runTest {
|
2021-12-31 05:28:16 -08:00
|
|
|
val walletAddresses = WalletAddressesFixture.new()
|
|
|
|
newTestSetup(walletAddresses)
|
|
|
|
|
2022-11-25 00:30:27 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.sapling.address).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertDoesNotExist()
|
|
|
|
}
|
|
|
|
|
2022-11-25 00:30:27 -08:00
|
|
|
composeTestRule.onNodeWithText(getStringResource(R.string.wallet_address_sapling)).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.assertExists()
|
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
2022-11-25 00:30:27 -08:00
|
|
|
composeTestRule.onNodeWithText(walletAddresses.sapling.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
|
2023-07-17 03:33:14 -07:00
|
|
|
fun back_clicked() = runTest {
|
2022-01-13 09:49:08 -08:00
|
|
|
val testSetup = newTestSetup(WalletAddressesFixture.new())
|
2021-12-31 05:28:16 -08:00
|
|
|
|
|
|
|
assertEquals(0, testSetup.getOnBackCount())
|
|
|
|
|
2023-06-18 23:59:00 -07:00
|
|
|
composeTestRule.onNodeWithContentDescription(
|
|
|
|
getStringResource(R.string.wallet_address_back_content_description)
|
|
|
|
).also {
|
2021-12-31 05:28:16 -08:00
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, testSetup.getOnBackCount())
|
|
|
|
}
|
|
|
|
|
2023-07-17 03:33:14 -07:00
|
|
|
@Test
|
|
|
|
@MediumTest
|
|
|
|
fun copy_to_clipboard_clicked() = runTest {
|
|
|
|
val testSetup = newTestSetup(WalletAddressesFixture.new())
|
|
|
|
|
|
|
|
assertEquals(0, testSetup.getOnCopyToClipboardCount())
|
|
|
|
|
|
|
|
composeTestRule.onNodeWithTag(
|
|
|
|
WalletAddressesTag.WALLET_ADDRESS
|
|
|
|
).also {
|
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, testSetup.getOnCopyToClipboardCount())
|
|
|
|
}
|
|
|
|
|
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)
|
2023-07-17 03:33:14 -07:00
|
|
|
private val onCopyToClipboardCount = 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
|
|
|
}
|
|
|
|
|
2023-07-17 03:33:14 -07:00
|
|
|
fun getOnCopyToClipboardCount(): Int {
|
|
|
|
composeTestRule.waitForIdle()
|
|
|
|
return onCopyToClipboardCount.get()
|
|
|
|
}
|
|
|
|
|
2021-12-31 05:28:16 -08:00
|
|
|
init {
|
|
|
|
composeTestRule.setContent {
|
|
|
|
ZcashTheme {
|
|
|
|
WalletAddresses(
|
2023-07-17 03:33:14 -07:00
|
|
|
walletAddresses = initialState,
|
|
|
|
onCopyToClipboard = {
|
|
|
|
onCopyToClipboardCount.incrementAndGet()
|
|
|
|
},
|
2021-12-31 05:28:16 -08:00
|
|
|
onBack = {
|
2022-03-01 05:11:23 -08:00
|
|
|
onBackCount.incrementAndGet()
|
2021-12-31 05:28:16 -08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|