2022-03-08 11:05:03 -08:00
|
|
|
package co.electriccoin.zcash.ui.screen.settings.view
|
2022-01-26 13:33:02 -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
|
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-26 13:33:02 -08:00
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import kotlinx.coroutines.test.runTest
|
|
|
|
import org.junit.Assert.assertEquals
|
2022-06-13 09:47:22 -07:00
|
|
|
import org.junit.Ignore
|
2022-01-26 13:33:02 -08:00
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger
|
|
|
|
|
|
|
|
@OptIn(ExperimentalCoroutinesApi::class)
|
2022-05-02 12:49:49 -07:00
|
|
|
class SettingsViewTest : UiTestPrerequisites() {
|
2022-01-26 13:33:02 -08:00
|
|
|
@get:Rule
|
|
|
|
val composeTestRule = createComposeRule()
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
|
|
|
fun back() = runTest {
|
|
|
|
val testSetup = TestSetup(composeTestRule)
|
|
|
|
|
|
|
|
assertEquals(0, testSetup.getOnBackCount())
|
|
|
|
|
|
|
|
composeTestRule.onNodeWithContentDescription(getStringResource(R.string.settings_back_content_description)).also {
|
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, testSetup.getOnBackCount())
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
|
|
|
fun backup() = runTest {
|
|
|
|
val testSetup = TestSetup(composeTestRule)
|
|
|
|
|
|
|
|
assertEquals(0, testSetup.getBackupCount())
|
|
|
|
|
|
|
|
composeTestRule.onNodeWithText(getStringResource(R.string.settings_backup)).also {
|
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, testSetup.getBackupCount())
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@MediumTest
|
|
|
|
fun rescan() = runTest {
|
|
|
|
val testSetup = TestSetup(composeTestRule)
|
|
|
|
|
|
|
|
assertEquals(0, testSetup.getBackupCount())
|
|
|
|
|
|
|
|
composeTestRule.onNodeWithText(getStringResource(R.string.settings_rescan)).also {
|
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, testSetup.getRescanCount())
|
|
|
|
}
|
|
|
|
|
2023-01-26 11:12:44 -08:00
|
|
|
@Test
|
|
|
|
@MediumTest
|
|
|
|
fun toggle_analytics() = runTest {
|
|
|
|
val testSetup = TestSetup(composeTestRule)
|
|
|
|
|
|
|
|
assertEquals(0, testSetup.getBackupCount())
|
|
|
|
|
|
|
|
composeTestRule.onNodeWithText(getStringResource(R.string.settings_enable_analytics)).also {
|
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, testSetup.getAnalyticsToggleCount())
|
|
|
|
}
|
|
|
|
|
2022-01-26 13:33:02 -08:00
|
|
|
@Test
|
|
|
|
@MediumTest
|
2022-06-13 09:47:22 -07:00
|
|
|
@Ignore("Wipe has been disabled in Settings and is now a debug-only option")
|
2022-01-26 13:33:02 -08:00
|
|
|
fun wipe() = runTest {
|
|
|
|
val testSetup = TestSetup(composeTestRule)
|
|
|
|
|
|
|
|
assertEquals(0, testSetup.getBackupCount())
|
|
|
|
|
|
|
|
composeTestRule.onNodeWithText(getStringResource(R.string.settings_wipe)).also {
|
|
|
|
it.performClick()
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, testSetup.getWipeCount())
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestSetup(private val composeTestRule: ComposeContentTestRule) {
|
|
|
|
|
2022-02-17 05:08:06 -08:00
|
|
|
private val onBackCount = AtomicInteger(0)
|
|
|
|
private val onBackupCount = AtomicInteger(0)
|
|
|
|
private val onRescanCount = AtomicInteger(0)
|
|
|
|
private val onWipeCount = AtomicInteger(0)
|
2023-01-26 11:12:44 -08:00
|
|
|
private val onAnalyticsChangedCount = AtomicInteger(0)
|
2022-01-26 13:33:02 -08:00
|
|
|
|
|
|
|
fun getOnBackCount(): Int {
|
|
|
|
composeTestRule.waitForIdle()
|
|
|
|
return onBackCount.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getBackupCount(): Int {
|
|
|
|
composeTestRule.waitForIdle()
|
|
|
|
return onBackupCount.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getRescanCount(): Int {
|
|
|
|
composeTestRule.waitForIdle()
|
|
|
|
return onRescanCount.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getWipeCount(): Int {
|
|
|
|
composeTestRule.waitForIdle()
|
|
|
|
return onWipeCount.get()
|
|
|
|
}
|
|
|
|
|
2023-01-26 11:12:44 -08:00
|
|
|
fun getAnalyticsToggleCount(): Int {
|
|
|
|
composeTestRule.waitForIdle()
|
|
|
|
return onAnalyticsChangedCount.get()
|
|
|
|
}
|
|
|
|
|
2022-01-26 13:33:02 -08:00
|
|
|
init {
|
|
|
|
composeTestRule.setContent {
|
|
|
|
ZcashTheme {
|
|
|
|
Settings(
|
2023-01-26 11:12:44 -08:00
|
|
|
isAnalyticsEnabled = true,
|
2022-01-26 13:33:02 -08:00
|
|
|
onBack = {
|
|
|
|
onBackCount.incrementAndGet()
|
|
|
|
},
|
|
|
|
onBackupWallet = {
|
|
|
|
onBackupCount.incrementAndGet()
|
|
|
|
},
|
|
|
|
onRescanWallet = {
|
|
|
|
onRescanCount.incrementAndGet()
|
|
|
|
},
|
|
|
|
onWipeWallet = {
|
|
|
|
onWipeCount.incrementAndGet()
|
2023-01-26 11:12:44 -08:00
|
|
|
},
|
|
|
|
onAnalyticsSettingsChanged = {
|
|
|
|
onAnalyticsChangedCount.incrementAndGet()
|
2022-01-26 13:33:02 -08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|