Updated on 2026-08-14
This commit is contained in:
parent
d174ada664
commit
6c4b0a31ec
7 changed files with 111 additions and 46 deletions
|
|
@ -3,7 +3,6 @@ package com.tangem.common
|
|||
import android.Manifest
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import com.kaspersky.components.composesupport.config.withComposeSupport
|
||||
|
|
|
|||
48
app/src/androidTest/kotlin/com/tangem/tests/ScanErrorTest.kt
Normal file
48
app/src/androidTest/kotlin/com/tangem/tests/ScanErrorTest.kt
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package com.tangem.tests
|
||||
|
||||
import com.tangem.common.BaseTestCase
|
||||
import com.tangem.screens.DisclaimerScreen
|
||||
import com.tangem.screens.StoriesScreen
|
||||
import com.tangem.screens.WalletScreen
|
||||
import com.tangem.tap.domain.sdk.mocks.MockProvider
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import io.github.kakaocup.compose.node.element.ComposeScreen
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class ScanErrorTest : BaseTestCase() {
|
||||
|
||||
@Test
|
||||
fun goToMain() =
|
||||
setupHooks().run {
|
||||
ComposeScreen.onComposeScreen<StoriesScreen>(composeTestRule) {
|
||||
step("Click on \"Scan\" button emulating scan error") {
|
||||
MockProvider.setEmulateError()
|
||||
scanButton {
|
||||
assertIsDisplayed()
|
||||
performClick()
|
||||
}
|
||||
}
|
||||
step("Click on \"Scan\" button again without emulating error") {
|
||||
MockProvider.resetEmulateError()
|
||||
scanButton {
|
||||
assertIsDisplayed()
|
||||
performClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
DisclaimerScreen {
|
||||
step("Click on \"Accept\" button") {
|
||||
acceptButton {
|
||||
isVisible()
|
||||
click()
|
||||
}
|
||||
}
|
||||
}
|
||||
ComposeScreen.onComposeScreen<WalletScreen>(composeTestRule) {
|
||||
step("Make sure wallet screen is visible") {
|
||||
assertIsDisplayed()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package com.tangem.tap.domain.sdk.mocks
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.models.scan.ProductType
|
||||
|
||||
data class MockConfig(
|
||||
val content: Either<ProductType, Mocks>,
|
||||
)
|
||||
|
|
@ -8,7 +8,7 @@ import com.tangem.operations.derivation.DerivationTaskResponse
|
|||
import com.tangem.operations.wallet.CreateWalletResponse
|
||||
import com.tangem.tap.domain.tasks.product.CreateProductWalletTaskResponse
|
||||
|
||||
interface Mocks {
|
||||
interface MockContent {
|
||||
|
||||
val successResponse: SuccessResponse
|
||||
|
||||
|
|
@ -22,11 +22,15 @@ interface Mocks {
|
|||
|
||||
val createProductWalletTaskResponse: CreateProductWalletTaskResponse
|
||||
|
||||
// Wallet2-specific
|
||||
val importWalletResponse: CreateProductWalletTaskResponse
|
||||
|
||||
// Twin-specific
|
||||
val finalizeTwinResponse: ScanResponse
|
||||
|
||||
// Twin-specific
|
||||
val createFirstTwinResponse: CreateWalletResponse
|
||||
|
||||
// Twin-specific
|
||||
val createSecondTwinResponse: CreateWalletResponse
|
||||
}
|
||||
|
|
@ -1,59 +1,81 @@
|
|||
package com.tangem.tap.domain.sdk.mocks
|
||||
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.common.core.TangemError
|
||||
import com.tangem.common.core.TangemSdkError
|
||||
import com.tangem.domain.models.scan.ProductType
|
||||
import com.tangem.tap.domain.sdk.mocks.wallet.WalletMocks
|
||||
import com.tangem.tap.domain.sdk.mocks.wallet2.Wallet2Mocks
|
||||
import com.tangem.tap.domain.sdk.mocks.content.WalletMockContent
|
||||
import com.tangem.tap.domain.sdk.mocks.content.Wallet2MockContent
|
||||
import com.tangem.tap.domain.tasks.product.CreateProductWalletTaskResponse
|
||||
|
||||
object MockProvider {
|
||||
|
||||
private var mocks: Mocks = getMocks(ProductType.Wallet)
|
||||
private var content: MockContent = getMockContent(ProductType.Wallet)
|
||||
|
||||
fun setMockConfig(mockConfig: MockConfig) {
|
||||
mockConfig.content.fold(
|
||||
ifLeft = {
|
||||
mocks = getMocks(it)
|
||||
},
|
||||
ifRight = {
|
||||
mocks = it
|
||||
},
|
||||
)
|
||||
private var emulateError: Boolean = false
|
||||
|
||||
private var emulatedError: TangemError = TangemSdkError.TagLost()
|
||||
|
||||
fun setEmulateError(error: TangemError? = null) {
|
||||
emulateError = true
|
||||
error?.let {
|
||||
emulatedError = it
|
||||
}
|
||||
}
|
||||
|
||||
fun getSuccessResponse() = CompletionResult.Success(mocks.successResponse)
|
||||
fun resetEmulateError() {
|
||||
emulateError = false
|
||||
}
|
||||
|
||||
fun getScanResponse() = CompletionResult.Success(mocks.scanResponse)
|
||||
fun setMocks(productType: ProductType) {
|
||||
content = getMockContent(productType)
|
||||
}
|
||||
|
||||
fun getDerivationTaskResponse() = CompletionResult.Success(mocks.derivationTaskResponse)
|
||||
fun setMocks(mockContent: MockContent) {
|
||||
content = mockContent
|
||||
}
|
||||
|
||||
fun getCardDto() = CompletionResult.Success(mocks.cardDto)
|
||||
fun getSuccessResponse() = CompletionResult.Success(content.successResponse).orFailure()
|
||||
|
||||
fun getExtendedPublicKey() = CompletionResult.Success(mocks.extendedPublicKey)
|
||||
fun getScanResponse() = CompletionResult.Success(content.scanResponse).orFailure()
|
||||
|
||||
fun getDerivationTaskResponse() = CompletionResult.Success(content.derivationTaskResponse).orFailure()
|
||||
|
||||
fun getCardDto() = CompletionResult.Success(content.cardDto).orFailure()
|
||||
|
||||
fun getExtendedPublicKey() = CompletionResult.Success(content.extendedPublicKey).orFailure()
|
||||
|
||||
fun getCreateProductWalletResponse(): CompletionResult<CreateProductWalletTaskResponse> {
|
||||
return CompletionResult.Success(mocks.createProductWalletTaskResponse)
|
||||
return CompletionResult.Success(content.createProductWalletTaskResponse).orFailure()
|
||||
}
|
||||
|
||||
fun getImportWalletResponse(): CompletionResult<CreateProductWalletTaskResponse> {
|
||||
return CompletionResult.Success(mocks.importWalletResponse)
|
||||
}
|
||||
|
||||
private fun getMocks(productType: ProductType): Mocks {
|
||||
return when (productType) {
|
||||
ProductType.Wallet -> WalletMocks
|
||||
ProductType.Wallet2 -> Wallet2Mocks
|
||||
else -> TODO()
|
||||
}
|
||||
return CompletionResult.Success(content.importWalletResponse).orFailure()
|
||||
}
|
||||
|
||||
// region Twin-specific
|
||||
|
||||
fun finalizeTwin() = CompletionResult.Success(mocks.finalizeTwinResponse)
|
||||
fun finalizeTwin() = CompletionResult.Success(content.finalizeTwinResponse).orFailure()
|
||||
|
||||
fun createFirstTwinWallet() = CompletionResult.Success(mocks.createFirstTwinResponse)
|
||||
fun createFirstTwinWallet() = CompletionResult.Success(content.createFirstTwinResponse).orFailure()
|
||||
|
||||
fun createSecondTwinWallet() = CompletionResult.Success(mocks.createSecondTwinResponse)
|
||||
fun createSecondTwinWallet() = CompletionResult.Success(content.createSecondTwinResponse).orFailure()
|
||||
|
||||
// endregion
|
||||
|
||||
private fun getMockContent(productType: ProductType): MockContent {
|
||||
return when (productType) {
|
||||
ProductType.Wallet -> WalletMockContent
|
||||
ProductType.Wallet2 -> Wallet2MockContent
|
||||
else -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> CompletionResult.Success<T>.orFailure(): CompletionResult<T> {
|
||||
return if (emulateError) {
|
||||
CompletionResult.Failure(emulatedError)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.tap.domain.sdk.mocks.wallet2
|
||||
package com.tangem.tap.domain.sdk.mocks.content
|
||||
|
||||
import com.tangem.common.SuccessResponse
|
||||
import com.tangem.crypto.hdWallet.bip32.ExtendedPublicKey
|
||||
|
|
@ -6,10 +6,10 @@ import com.tangem.domain.models.scan.CardDTO
|
|||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.operations.derivation.DerivationTaskResponse
|
||||
import com.tangem.operations.wallet.CreateWalletResponse
|
||||
import com.tangem.tap.domain.sdk.mocks.Mocks
|
||||
import com.tangem.tap.domain.sdk.mocks.MockContent
|
||||
import com.tangem.tap.domain.tasks.product.CreateProductWalletTaskResponse
|
||||
|
||||
object Wallet2Mocks : Mocks {
|
||||
object Wallet2MockContent : MockContent {
|
||||
|
||||
override val scanResponse: ScanResponse
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.tap.domain.sdk.mocks.wallet
|
||||
package com.tangem.tap.domain.sdk.mocks.content
|
||||
|
||||
import com.tangem.common.SuccessResponse
|
||||
import com.tangem.common.card.*
|
||||
|
|
@ -13,11 +13,11 @@ import com.tangem.operations.backup.PrimaryCard
|
|||
import com.tangem.operations.derivation.DerivationTaskResponse
|
||||
import com.tangem.operations.derivation.ExtendedPublicKeysMap
|
||||
import com.tangem.operations.wallet.CreateWalletResponse
|
||||
import com.tangem.tap.domain.sdk.mocks.Mocks
|
||||
import com.tangem.tap.domain.sdk.mocks.MockContent
|
||||
import com.tangem.tap.domain.tasks.product.CreateProductWalletTaskResponse
|
||||
import java.util.Date
|
||||
|
||||
object WalletMocks : Mocks {
|
||||
object WalletMockContent : MockContent {
|
||||
|
||||
private val primaryCard = PrimaryCard(
|
||||
cardId = "AC05000000086747",
|
||||
Loading…
Add table
Add a link
Reference in a new issue